bitmex-api 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +7 -6
- data/Rakefile +3 -2
- data/TODOs.org +4 -0
- data/bin/console +7 -3
- data/bin/triangular.rb +46 -0
- data/lib/bitmex/version.rb +1 -1
- data/lib/bitmex/websocket.rb +9 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 448191dd7c9613d1201fd02d19c14e089e4c58a4b8f0976043d6940b958fdd49
|
4
|
+
data.tar.gz: 5dbaa19973f3ecf4265124adb2e19f2df3e446c826241916bbbc7d971ab1bbcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7226c9c0656f4e13af581708a4493ad89a4f5d272a9f8de290cdb35423b7847d3af506cd2a51f4b02428bcb0bdfb39ce69782e5f9a5fc90cd7fc1c57d151e602
|
7
|
+
data.tar.gz: 940894dc0f2af98dc25dbf8a893fddbc14877519e449e11a141a69355833d395206397651ae301b05ff078f10b2f6e2ded2c10be87b3c52f0c5bf7568b90ebc4
|
data/CHANGELOG.md
CHANGED
@@ -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
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bitmex-api (0.1.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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
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>
|
data/bin/console
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
|
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
|
17
|
+
require 'irb'
|
14
18
|
IRB.start(__FILE__)
|
data/bin/triangular.rb
ADDED
@@ -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
|
+
#
|
data/lib/bitmex/version.rb
CHANGED
data/lib/bitmex/websocket.rb
CHANGED
@@ -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
|
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
|
-
# @
|
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
|
-
|
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.
|
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-
|
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
|