bitmex-api 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ee2c822d6d71a05339a02ea14e4e17f58afafd5e9775ed48f5db89025b914fe
4
- data.tar.gz: 523ee210b7a17955eeaeffafb19bb00ac3dce49a789842545b0f0a7a0faeecd1
3
+ metadata.gz: 448191dd7c9613d1201fd02d19c14e089e4c58a4b8f0976043d6940b958fdd49
4
+ data.tar.gz: 5dbaa19973f3ecf4265124adb2e19f2df3e446c826241916bbbc7d971ab1bbcb
5
5
  SHA512:
6
- metadata.gz: 5fe0a780b415aee7e35c4a4a7b95d4e3236e10533206325f77e4ba719d231e340c5861d60a95a6fb1b5937d7e0be1973db85831143e13fcc8c82231f89884796
7
- data.tar.gz: 7ef74976acb9bbad03b75fde8750b399b0486f475e8714742250bffc2d57bf08331fbb23cfa5ee03001780410ba998b69696881ed0a0d9dead0deba7487d9870
6
+ metadata.gz: 7226c9c0656f4e13af581708a4493ad89a4f5d272a9f8de290cdb35423b7847d3af506cd2a51f4b02428bcb0bdfb39ce69782e5f9a5fc90cd7fc1c57d151e602
7
+ data.tar.gz: 940894dc0f2af98dc25dbf8a893fddbc14877519e449e11a141a69355833d395206397651ae301b05ff078f10b2f6e2ded2c10be87b3c52f0c5bf7568b90ebc4
@@ -5,6 +5,13 @@
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.1.1] - 2019-03-06
9
+ ### Added
10
+ - functional state transfer from one websocket block to the next
11
+ ### Fixed
12
+ - topic with multiple symbols issue
13
+ - loading ENV vars in bin/console
14
+
8
15
  ## [0.1.0] - 2019-02-11
9
16
  ### Added
10
17
  - authentication via websocket
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bitmex-api (0.1.0)
4
+ bitmex-api (0.1.1)
5
5
  eventmachine
6
6
  faye-websocket
7
7
  hashie
@@ -15,7 +15,7 @@ GEM
15
15
  descendants_tracker (~> 0.0.4)
16
16
  ice_nine (~> 0.11.0)
17
17
  thread_safe (~> 0.3, >= 0.3.1)
18
- bump (0.7.0)
18
+ bump (0.8.0)
19
19
  codeclimate-engine-rb (0.4.1)
20
20
  virtus (~> 1.0)
21
21
  coderay (1.1.2)
@@ -25,7 +25,7 @@ GEM
25
25
  thread_safe (~> 0.3, >= 0.3.1)
26
26
  diff-lcs (1.3)
27
27
  docile (1.3.1)
28
- dotenv (2.6.0)
28
+ dotenv (2.7.1)
29
29
  equalizer (0.0.11)
30
30
  eventmachine (1.2.7)
31
31
  faye-websocket (0.10.7)
@@ -37,14 +37,14 @@ GEM
37
37
  multi_xml (>= 0.5.2)
38
38
  ice_nine (0.11.2)
39
39
  jaro_winkler (1.5.2)
40
- json (2.1.0)
40
+ json (2.2.0)
41
41
  kwalify (0.7.2)
42
42
  method_source (0.9.2)
43
43
  mime-types (3.2.2)
44
44
  mime-types-data (~> 3.2015)
45
45
  mime-types-data (3.2018.0812)
46
46
  multi_xml (0.6.0)
47
- parallel (1.13.0)
47
+ parallel (1.14.0)
48
48
  parser (2.6.0.0)
49
49
  ast (~> 2.4.0)
50
50
  powerpack (0.1.2)
@@ -76,11 +76,12 @@ GEM
76
76
  diff-lcs (>= 1.2.0, < 2.0)
77
77
  rspec-support (~> 3.8.0)
78
78
  rspec-support (3.8.0)
79
- rubocop (0.63.1)
79
+ rubocop (0.65.0)
80
80
  jaro_winkler (~> 1.5.1)
81
81
  parallel (~> 1.10)
82
82
  parser (>= 2.5, != 2.5.1.1)
83
83
  powerpack (~> 0.1)
84
+ psych (>= 3.1.0)
84
85
  rainbow (>= 2.2.2, < 4.0)
85
86
  ruby-progressbar (~> 1.7)
86
87
  unicode-display_width (~> 1.4.0)
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'bump/tasks'
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
5
6
 
data/TODOs.org CHANGED
@@ -31,3 +31,7 @@
31
31
  ** refactoring: make user model to extend base class as well
32
32
  ** DONE Release 1.0: API endpoints, examples in README
33
33
  CLOSED: [2019-02-11 Mon] SCHEDULED: <2019-02-11 Mon>
34
+ ** DONE add triangular, functional state transfer, fix multiple symbols issue
35
+ CLOSED: [2019-02-13 Wed] SCHEDULED: <2019-02-13 Wed>
36
+ ** DONE release 0.1.1
37
+ CLOSED: [2019-03-06 Wed] SCHEDULED: <2019-03-06 Wed>
@@ -1,7 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "bitmex"
3
+ require 'dotenv'
4
+ Dotenv.load
5
+ Dotenv.require_keys('API_KEY', 'API_SECRET')
6
+
7
+ require 'bundler/setup'
8
+ require 'bitmex'
5
9
 
6
10
  # You can add fixtures and/or initialization code here to make experimenting
7
11
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +14,5 @@ require "bitmex"
10
14
  # require "pry"
11
15
  # Pry.start
12
16
 
13
- require "irb"
17
+ require 'irb'
14
18
  IRB.start(__FILE__)
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'bitmex'
5
+
6
+ puts 'Triangular arbitrage: XBTUSD-ETHUSD-ETHXBT...'
7
+
8
+ client = Bitmex::Client.new
9
+ client.websocket.listen quote: ['XBTUSD', 'ETHUSD', 'ETHH19'] do |quote, state|
10
+ # initialize
11
+ state = {
12
+ 'max_profit' => -100, 'count' => 0,
13
+ 'XBTUSD' => {}, 'ETHUSD' => {}, 'ETHH19' => {}
14
+ } unless state
15
+
16
+ # update state
17
+ state[quote.symbol] = { 'bid' => quote.bidPrice, 'ask' => quote.askPrice }
18
+ state['count'] += 1
19
+ puts "STATE: #{state}" if state['count']%100 == 0
20
+
21
+ # process
22
+ price1 = state['XBTUSD']['bid']
23
+ price2 = state['ETHUSD']['ask']
24
+ price3 = state['ETHH19']['bid']
25
+ if price1 && price2 && price3
26
+ x1 = price1
27
+ x2 = x1 / price2
28
+ x3 = x2 * price3
29
+ profit = ((x3 - 1) * 10000).to_i
30
+ if profit > state['max_profit']
31
+ state['max_profit'] = profit
32
+ puts "NEW PROFIT: #{profit} points"
33
+ end
34
+ end
35
+
36
+ # return updated state
37
+ state
38
+ end
39
+
40
+ #
41
+ # Capital: 1 XBT
42
+ # Short XBTUSD: 1 XBT x 3600 XBTUSD = 3600 USD
43
+ # Long ETHUSD: 3600 USD / 122 ETHUSD = 22.5 ETH
44
+ # Short ETHXBT: 22.5 ETH * 0.0339 ETHXBT = 0.7627 XBT
45
+ # P&L: XBT
46
+ #
@@ -1,3 +1,3 @@
1
1
  module Bitmex
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -21,7 +21,7 @@ module Bitmex
21
21
 
22
22
  # Subscribe to a specific topic and optionally filter by symbol
23
23
  # @param topic [String] topic to subscribe to e.g. 'trade'
24
- # @param symbol [String] symbol to filter by e.g. 'XBTUSD'
24
+ # @param symbol [String, Array] symbol or symbols to filter
25
25
  # @yield [Array] data payload
26
26
  def subscribe(topic, symbol = nil, auth: false, &callback)
27
27
  raise 'callback block is required' unless block_given?
@@ -44,13 +44,18 @@ module Bitmex
44
44
 
45
45
  # Listen to generic topics
46
46
  # @param topics [Hash] topics to listen to e.g. { trade: "XBTUSD" }
47
- # @yield [data] data pushed via websocket
47
+ # @yieldparam [Hash] data pushed via websocket
48
+ # @yieldparam [any] result state of the previous block execution if any
48
49
  def listen(topics, &ablock)
49
50
  EM.run do
50
51
  connect
51
52
 
52
53
  topics.each do |topic, symbol|
53
- subscribe topic, symbol, &ablock
54
+ symbols = [symbol] if symbol.nil? || symbol.is_a?(String)
55
+ symbols ||= symbol
56
+ symbols.each do |symbol|
57
+ subscribe topic, symbol, &ablock
58
+ end
54
59
  end
55
60
  end
56
61
  end
@@ -83,7 +88,7 @@ module Bitmex
83
88
  callback = @callbacks[topic]
84
89
  if callback
85
90
  data&.each do |payload|
86
- callback.yield Bitmex::Mash.new(payload)
91
+ @result = callback.yield Bitmex::Mash.new(payload), @result
87
92
  end
88
93
  else
89
94
  puts "==> #{event.data}"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitmex-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Iulian Costan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-11 00:00:00.000000000 Z
11
+ date: 2019-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -228,6 +228,7 @@ files:
228
228
  - bin/chat.rb
229
229
  - bin/console
230
230
  - bin/setup
231
+ - bin/triangular.rb
231
232
  - bin/whales-watching.rb
232
233
  - bitmex.gemspec
233
234
  - lib/bitmex-api.rb