irix3 3.1.1 → 3.2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/Gemfile.lock +236 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/irix/bitfinex.rb +205 -0
- data/lib/irix/hooks.rb +18 -0
- data/lib/irix/huobi.rb +177 -0
- data/lib/irix/railtie.rb +9 -0
- data/lib/irix/version.rb +3 -0
- data/lib/irix.rb +15 -0
- metadata +32 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b319260e54f2382a090fea635487b8e1e156720301d9adeb97850e24260827b
|
4
|
+
data.tar.gz: d2b8a29ccb7248f28a55b6ccafce77261347abcb71eb3878e572b63df24d5007
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffbf0f981dc678801a37e147741234030a182568608cebb1621e5e0603ba899503551e2352b8057c94da8398375b25028a72b21b78fcd9af02ff0e4661d94226
|
7
|
+
data.tar.gz: 4ba5b2acec514146f20ecfc1c3bef4f74bf69aaad951209f6e01d6122ab52c0dd32800eb450c7b508737082cdca07d1b0364f10f266919dc1f6b032103f041ba
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,236 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
irix (3.2.1)
|
5
|
+
em-synchrony (~> 1.0)
|
6
|
+
em-websocket
|
7
|
+
eventmachine
|
8
|
+
faraday_middleware (~> 1.2)
|
9
|
+
faye (~> 1.2)
|
10
|
+
peatio (~> 3.1)
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: https://rubygems.org/
|
14
|
+
specs:
|
15
|
+
activemodel (7.1.3.4)
|
16
|
+
activesupport (= 7.1.3.4)
|
17
|
+
activesupport (7.1.3.4)
|
18
|
+
base64
|
19
|
+
bigdecimal
|
20
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
21
|
+
connection_pool (>= 2.2.5)
|
22
|
+
drb
|
23
|
+
i18n (>= 1.6, < 2)
|
24
|
+
minitest (>= 5.1)
|
25
|
+
mutex_m
|
26
|
+
tzinfo (~> 2.0)
|
27
|
+
addressable (2.8.7)
|
28
|
+
public_suffix (>= 2.0.2, < 7.0)
|
29
|
+
amq-protocol (2.3.2)
|
30
|
+
amqp (1.8.0)
|
31
|
+
amq-protocol (>= 2.2.0)
|
32
|
+
eventmachine
|
33
|
+
ast (2.4.2)
|
34
|
+
base64 (0.2.0)
|
35
|
+
bigdecimal (3.1.8)
|
36
|
+
bunny (2.22.0)
|
37
|
+
amq-protocol (~> 2.3, >= 2.3.1)
|
38
|
+
sorted_set (~> 1, >= 1.0.2)
|
39
|
+
byebug (11.1.3)
|
40
|
+
clamp (1.3.2)
|
41
|
+
coderay (1.1.3)
|
42
|
+
concurrent-ruby (1.3.3)
|
43
|
+
connection_pool (2.4.1)
|
44
|
+
cookiejar (0.3.4)
|
45
|
+
daemons (1.4.1)
|
46
|
+
diff-lcs (1.5.1)
|
47
|
+
docile (1.4.0)
|
48
|
+
drb (2.2.1)
|
49
|
+
em-http-request (1.1.7)
|
50
|
+
addressable (>= 2.3.4)
|
51
|
+
cookiejar (!= 0.3.1)
|
52
|
+
em-socksify (>= 0.3)
|
53
|
+
eventmachine (>= 1.0.3)
|
54
|
+
http_parser.rb (>= 0.6.0)
|
55
|
+
em-socksify (0.3.2)
|
56
|
+
eventmachine (>= 1.0.0.beta.4)
|
57
|
+
em-spec (0.2.7)
|
58
|
+
eventmachine
|
59
|
+
em-synchrony (1.0.6)
|
60
|
+
eventmachine (>= 1.0.0.beta.1)
|
61
|
+
em-websocket (0.5.3)
|
62
|
+
eventmachine (>= 0.12.9)
|
63
|
+
http_parser.rb (~> 0)
|
64
|
+
em-websocket-client (0.1.2)
|
65
|
+
eventmachine
|
66
|
+
websocket
|
67
|
+
eventmachine (1.2.7)
|
68
|
+
faraday (1.10.3)
|
69
|
+
faraday-em_http (~> 1.0)
|
70
|
+
faraday-em_synchrony (~> 1.0)
|
71
|
+
faraday-excon (~> 1.1)
|
72
|
+
faraday-httpclient (~> 1.0)
|
73
|
+
faraday-multipart (~> 1.0)
|
74
|
+
faraday-net_http (~> 1.0)
|
75
|
+
faraday-net_http_persistent (~> 1.0)
|
76
|
+
faraday-patron (~> 1.0)
|
77
|
+
faraday-rack (~> 1.0)
|
78
|
+
faraday-retry (~> 1.0)
|
79
|
+
ruby2_keywords (>= 0.0.4)
|
80
|
+
faraday-em_http (1.0.0)
|
81
|
+
faraday-em_synchrony (1.0.0)
|
82
|
+
faraday-excon (1.1.0)
|
83
|
+
faraday-httpclient (1.0.1)
|
84
|
+
faraday-multipart (1.0.4)
|
85
|
+
multipart-post (~> 2)
|
86
|
+
faraday-net_http (1.0.1)
|
87
|
+
faraday-net_http_persistent (1.2.0)
|
88
|
+
faraday-patron (1.0.0)
|
89
|
+
faraday-rack (1.0.0)
|
90
|
+
faraday-retry (1.0.3)
|
91
|
+
faraday_middleware (1.2.0)
|
92
|
+
faraday (~> 1.0)
|
93
|
+
faye (1.4.0)
|
94
|
+
cookiejar (>= 0.3.0)
|
95
|
+
em-http-request (>= 1.1.6)
|
96
|
+
eventmachine (>= 0.12.0)
|
97
|
+
faye-websocket (>= 0.11.0)
|
98
|
+
multi_json (>= 1.0.0)
|
99
|
+
rack (>= 1.0.0)
|
100
|
+
websocket-driver (>= 0.5.1)
|
101
|
+
faye-websocket (0.11.3)
|
102
|
+
eventmachine (>= 0.12.0)
|
103
|
+
websocket-driver (>= 0.5.1)
|
104
|
+
http_parser.rb (0.8.0)
|
105
|
+
i18n (1.14.5)
|
106
|
+
concurrent-ruby (~> 1.0)
|
107
|
+
json (2.7.2)
|
108
|
+
jwt (2.8.2)
|
109
|
+
base64
|
110
|
+
language_server-protocol (3.17.0.3)
|
111
|
+
method_source (1.1.0)
|
112
|
+
minitest (5.24.0)
|
113
|
+
multi_json (1.15.0)
|
114
|
+
multipart-post (2.4.1)
|
115
|
+
mutex_m (0.2.0)
|
116
|
+
mysql2 (0.5.6)
|
117
|
+
parallel (1.25.1)
|
118
|
+
parser (3.3.3.0)
|
119
|
+
ast (~> 2.4.1)
|
120
|
+
racc
|
121
|
+
peatio (3.1.1)
|
122
|
+
activemodel (> 5.2)
|
123
|
+
amqp
|
124
|
+
bunny
|
125
|
+
clamp
|
126
|
+
em-synchrony (~> 1.0)
|
127
|
+
em-websocket
|
128
|
+
eventmachine
|
129
|
+
faraday (~> 1.10)
|
130
|
+
faye (~> 1.2)
|
131
|
+
jwt
|
132
|
+
mysql2
|
133
|
+
prometheus-client
|
134
|
+
thin
|
135
|
+
prometheus-client (4.2.2)
|
136
|
+
pry (0.14.2)
|
137
|
+
coderay (~> 1.1)
|
138
|
+
method_source (~> 1.0)
|
139
|
+
pry-byebug (3.10.1)
|
140
|
+
byebug (~> 11.0)
|
141
|
+
pry (>= 0.13, < 0.15)
|
142
|
+
public_suffix (5.1.1)
|
143
|
+
racc (1.8.0)
|
144
|
+
rack (2.2.9)
|
145
|
+
rainbow (3.1.1)
|
146
|
+
rake (13.2.1)
|
147
|
+
rbtree (0.4.6)
|
148
|
+
regexp_parser (2.9.2)
|
149
|
+
rexml (3.3.0)
|
150
|
+
strscan
|
151
|
+
rspec (3.13.0)
|
152
|
+
rspec-core (~> 3.13.0)
|
153
|
+
rspec-expectations (~> 3.13.0)
|
154
|
+
rspec-mocks (~> 3.13.0)
|
155
|
+
rspec-core (3.13.0)
|
156
|
+
rspec-support (~> 3.13.0)
|
157
|
+
rspec-expectations (3.13.1)
|
158
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
159
|
+
rspec-support (~> 3.13.0)
|
160
|
+
rspec-mocks (3.13.1)
|
161
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
162
|
+
rspec-support (~> 3.13.0)
|
163
|
+
rspec-support (3.13.1)
|
164
|
+
rspec_junit_formatter (0.6.0)
|
165
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
166
|
+
rubocop (1.64.1)
|
167
|
+
json (~> 2.3)
|
168
|
+
language_server-protocol (>= 3.17.0)
|
169
|
+
parallel (~> 1.10)
|
170
|
+
parser (>= 3.3.0.2)
|
171
|
+
rainbow (>= 2.2.2, < 4.0)
|
172
|
+
regexp_parser (>= 1.8, < 3.0)
|
173
|
+
rexml (>= 3.2.5, < 4.0)
|
174
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
175
|
+
ruby-progressbar (~> 1.7)
|
176
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
177
|
+
rubocop-ast (1.31.3)
|
178
|
+
parser (>= 3.3.1.0)
|
179
|
+
rubocop-github (0.20.0)
|
180
|
+
rubocop (>= 1.37)
|
181
|
+
rubocop-performance (>= 1.15)
|
182
|
+
rubocop-rails (>= 2.17)
|
183
|
+
rubocop-performance (1.21.1)
|
184
|
+
rubocop (>= 1.48.1, < 2.0)
|
185
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
186
|
+
rubocop-rails (2.25.0)
|
187
|
+
activesupport (>= 4.2.0)
|
188
|
+
rack (>= 1.1)
|
189
|
+
rubocop (>= 1.33.0, < 2.0)
|
190
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
191
|
+
ruby-progressbar (1.13.0)
|
192
|
+
ruby2_keywords (0.0.5)
|
193
|
+
set (1.0.4)
|
194
|
+
simplecov (0.22.0)
|
195
|
+
docile (~> 1.1)
|
196
|
+
simplecov-html (~> 0.11)
|
197
|
+
simplecov_json_formatter (~> 0.1)
|
198
|
+
simplecov-html (0.12.3)
|
199
|
+
simplecov-json (0.2.3)
|
200
|
+
json
|
201
|
+
simplecov
|
202
|
+
simplecov_json_formatter (0.1.4)
|
203
|
+
sorted_set (1.0.3)
|
204
|
+
rbtree
|
205
|
+
set (~> 1.0)
|
206
|
+
strscan (3.1.0)
|
207
|
+
thin (1.8.2)
|
208
|
+
daemons (~> 1.0, >= 1.0.9)
|
209
|
+
eventmachine (~> 1.0, >= 1.0.4)
|
210
|
+
rack (>= 1, < 3)
|
211
|
+
tzinfo (2.0.6)
|
212
|
+
concurrent-ruby (~> 1.0)
|
213
|
+
unicode-display_width (2.5.0)
|
214
|
+
websocket (1.2.10)
|
215
|
+
websocket-driver (0.7.6)
|
216
|
+
websocket-extensions (>= 0.1.0)
|
217
|
+
websocket-extensions (0.1.5)
|
218
|
+
|
219
|
+
PLATFORMS
|
220
|
+
x86_64-linux
|
221
|
+
|
222
|
+
DEPENDENCIES
|
223
|
+
bundler (~> 2.4)
|
224
|
+
em-spec
|
225
|
+
em-websocket-client
|
226
|
+
irix!
|
227
|
+
pry-byebug
|
228
|
+
rake (~> 13.0)
|
229
|
+
rspec (~> 3.0)
|
230
|
+
rspec_junit_formatter
|
231
|
+
rubocop-github
|
232
|
+
simplecov
|
233
|
+
simplecov-json
|
234
|
+
|
235
|
+
BUNDLED WITH
|
236
|
+
2.4.0
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Irix
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/irix`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'irix'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install irix
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/irix.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "irix"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,205 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Irix
|
4
|
+
class Bitfinex < Peatio::Upstream::Base
|
5
|
+
require 'time'
|
6
|
+
|
7
|
+
MIN_INCREMENT_COUNT_TO_SNAPSHOT = 100
|
8
|
+
MIN_PERIOD_TO_SNAPSHOT = 5
|
9
|
+
MAX_PERIOD_TO_SNAPSHOT = 60
|
10
|
+
|
11
|
+
attr_accessor :snap, :snapshot_time, :increment_count, :sequence_number,
|
12
|
+
:open_channels, :asks, :bids
|
13
|
+
|
14
|
+
def initialize(config)
|
15
|
+
super
|
16
|
+
@connection = Faraday.new(url: (config['rest']).to_s) do |builder|
|
17
|
+
builder.response :json
|
18
|
+
builder.response :logger if config['debug']
|
19
|
+
builder.adapter(@adapter)
|
20
|
+
unless config['verify_ssl'].nil?
|
21
|
+
builder.ssl[:verify] = config['verify_ssl']
|
22
|
+
end
|
23
|
+
end
|
24
|
+
@open_channels = {}
|
25
|
+
@ping_set = false
|
26
|
+
@rest = (config['rest']).to_s
|
27
|
+
@ws_url = (config['websocket']).to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
def ws_connect
|
31
|
+
super
|
32
|
+
return if @ping_set
|
33
|
+
|
34
|
+
@ws.on(:open) do |_e|
|
35
|
+
subscribe_trades(@target, @ws)
|
36
|
+
subscribe_orderbook(@target, @ws)
|
37
|
+
logger.info { 'Websocket connected' }
|
38
|
+
end
|
39
|
+
|
40
|
+
Fiber.new do
|
41
|
+
EM::Synchrony.add_periodic_timer(80) do
|
42
|
+
@ws.send('{"event":"ping"}')
|
43
|
+
end
|
44
|
+
end.resume
|
45
|
+
@ping_set = true
|
46
|
+
end
|
47
|
+
|
48
|
+
def subscribe_trades(market, ws)
|
49
|
+
return unless @config['trade_proxy']
|
50
|
+
|
51
|
+
sub = {
|
52
|
+
event: 'subscribe',
|
53
|
+
channel: 'trades',
|
54
|
+
symbol: market.upcase
|
55
|
+
}
|
56
|
+
|
57
|
+
Rails.logger.info 'Open event' + sub.to_s
|
58
|
+
EM.next_tick do
|
59
|
+
ws.send(JSON.generate(sub))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def subscribe_orderbook(market, ws)
|
64
|
+
return unless @config['orderbook_proxy']
|
65
|
+
|
66
|
+
@sequence_number = 0
|
67
|
+
@increment_count = 0
|
68
|
+
@bids = []
|
69
|
+
@asks = []
|
70
|
+
@snap = { 'asks' => [], 'bids' => [] }
|
71
|
+
sub = {
|
72
|
+
event: 'subscribe',
|
73
|
+
channel: 'book',
|
74
|
+
symbol: market.upcase,
|
75
|
+
len: 25
|
76
|
+
}
|
77
|
+
Rails.logger.info 'Open event' + sub.to_s
|
78
|
+
EM.next_tick do
|
79
|
+
ws.send(JSON.generate(sub))
|
80
|
+
end
|
81
|
+
Fiber.new do
|
82
|
+
EM::Synchrony.add_periodic_timer(0.2) do
|
83
|
+
publish_increment
|
84
|
+
end
|
85
|
+
end.resume
|
86
|
+
end
|
87
|
+
|
88
|
+
def ws_read_public_message(msg)
|
89
|
+
if msg.is_a?(Array)
|
90
|
+
if msg[1] == 'hb'
|
91
|
+
@ws.send('{"event":"ping"}')
|
92
|
+
elsif @open_channels[msg[0]] == 'trades'
|
93
|
+
detect_trade(msg)
|
94
|
+
elsif @open_channels[msg[0]] == 'book'
|
95
|
+
detect_order(msg)
|
96
|
+
end
|
97
|
+
elsif msg.is_a?(Hash)
|
98
|
+
message_event(msg)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def detect_trade(msg)
|
103
|
+
if msg[1] == 'tu'
|
104
|
+
data = msg[2]
|
105
|
+
trade =
|
106
|
+
{
|
107
|
+
'tid' => data[0],
|
108
|
+
'amount' => data[2].to_d.abs,
|
109
|
+
'price' => data[3],
|
110
|
+
'date' => data[1] / 1000,
|
111
|
+
'taker_type' => data[2].to_d.positive? ? 'buy' : 'sell'
|
112
|
+
}
|
113
|
+
notify_public_trade(trade)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# [
|
118
|
+
# CHANNEL_ID,
|
119
|
+
# [
|
120
|
+
# PRICE,
|
121
|
+
# COUNT,
|
122
|
+
# AMOUNT
|
123
|
+
# ]
|
124
|
+
# ]
|
125
|
+
def detect_order(msg)
|
126
|
+
if msg[1][0].is_a?(Array)
|
127
|
+
msg[1].each do |point|
|
128
|
+
if point[2] > 0
|
129
|
+
@snap['bids'] << [point[0].to_s, point[2].to_s]
|
130
|
+
else
|
131
|
+
@snap['asks'] << [point[0].to_s, point[2].abs.to_s]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
publish_snapshot
|
135
|
+
else
|
136
|
+
if @increment_count < MIN_INCREMENT_COUNT_TO_SNAPSHOT && @snapshot_time <= Time.now - MAX_PERIOD_TO_SNAPSHOT
|
137
|
+
publish_snapshot
|
138
|
+
@increment_count = 0
|
139
|
+
elsif @increment_count >= MIN_INCREMENT_COUNT_TO_SNAPSHOT && @snapshot_time < Time.now - MIN_PERIOD_TO_SNAPSHOT
|
140
|
+
publish_snapshot
|
141
|
+
@increment_count = 0
|
142
|
+
end
|
143
|
+
|
144
|
+
fill_increment(msg[1])
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def fill_increment(order)
|
149
|
+
side = order[2].positive? ? 'bid' : 'ask'
|
150
|
+
price = order[0].to_s
|
151
|
+
if order[1].zero?
|
152
|
+
amount = 0
|
153
|
+
@snap["#{side}s"].delete_if { |point| point[0] == price }
|
154
|
+
else
|
155
|
+
amount = order[2].abs.to_s
|
156
|
+
@snap["#{side}s"].delete_if { |point| point[0] == price }
|
157
|
+
@snap["#{side}s"] << [price.to_s, amount.to_s]
|
158
|
+
end
|
159
|
+
if side == 'bid'
|
160
|
+
@bids.delete_if { |point| point[0] == price }
|
161
|
+
@bids << [price.to_s, amount.to_s]
|
162
|
+
elsif side == 'ask'
|
163
|
+
@asks.delete_if { |point| point[0] == price }
|
164
|
+
@asks << [price.to_s, amount.to_s]
|
165
|
+
end
|
166
|
+
@increment_count += 1
|
167
|
+
end
|
168
|
+
|
169
|
+
def publish_increment
|
170
|
+
inc = {}
|
171
|
+
inc['bids'] = @bids.sort.reverse if @bids.present?
|
172
|
+
inc['asks'] = @asks.sort if @asks.present?
|
173
|
+
if inc.present?
|
174
|
+
@sequence_number += 1
|
175
|
+
@peatio_mq.enqueue_event('public', @market, 'ob-inc',
|
176
|
+
'bids' => inc['bids'], 'asks' => inc['asks'],
|
177
|
+
'sequence' => @sequence_number)
|
178
|
+
end
|
179
|
+
@bids = []
|
180
|
+
@asks = []
|
181
|
+
end
|
182
|
+
|
183
|
+
def publish_snapshot
|
184
|
+
@snapshot_time = Time.now
|
185
|
+
@peatio_mq.enqueue_event('public', @market, 'ob-snap',
|
186
|
+
'bids' => @snap['bids'].sort.reverse,
|
187
|
+
'asks' => @snap['asks'].sort,
|
188
|
+
'sequence' => @sequence_number)
|
189
|
+
end
|
190
|
+
|
191
|
+
def message_event(msg)
|
192
|
+
case msg['event']
|
193
|
+
when 'subscribed'
|
194
|
+
Rails.logger.info "Event: #{msg}"
|
195
|
+
@open_channels[msg['chanId']] = msg['channel']
|
196
|
+
when 'error'
|
197
|
+
Rails.logger.info "Event: #{msg} ignored"
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def info(msg)
|
202
|
+
Rails.logger.info "Bitfinex: #{msg}"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
data/lib/irix/hooks.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Irix
|
4
|
+
module Hooks
|
5
|
+
class << self
|
6
|
+
def register
|
7
|
+
Peatio::Upstream.registry[:bitfinex] = Irix::Bitfinex
|
8
|
+
Peatio::Upstream.registry[:huobi] = Irix::Huobi
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
if defined?(Rails::Railtie)
|
13
|
+
require 'irix/railtie'
|
14
|
+
else
|
15
|
+
register
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/irix/huobi.rb
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Irix
|
4
|
+
class Huobi < Peatio::Upstream::Base
|
5
|
+
require 'time'
|
6
|
+
|
7
|
+
MIN_INCREMENT_COUNT_TO_SNAPSHOT = 100
|
8
|
+
MIN_PERIOD_TO_SNAPSHOT = 5
|
9
|
+
MAX_PERIOD_TO_SNAPSHOT = 60
|
10
|
+
|
11
|
+
attr_accessor :snap, :snapshot_time, :increment_count, :sequence_number,
|
12
|
+
:asks, :bids
|
13
|
+
# WS huobi global
|
14
|
+
# websocket: "wss://api.huobi.pro/ws/"
|
15
|
+
# WS for krw markets
|
16
|
+
# websocket: "wss://api-cloud.huobi.co.kr/ws/"
|
17
|
+
|
18
|
+
def initialize(config)
|
19
|
+
super
|
20
|
+
@connection = Faraday.new(url: (config['rest']).to_s) do |builder|
|
21
|
+
builder.response :json
|
22
|
+
builder.response :logger if config['debug']
|
23
|
+
builder.adapter(@adapter)
|
24
|
+
unless config['verify_ssl'].nil?
|
25
|
+
builder.ssl[:verify] = config['verify_ssl']
|
26
|
+
end
|
27
|
+
end
|
28
|
+
@ping_set = false
|
29
|
+
@rest = (config['rest']).to_s
|
30
|
+
@ws_url = (config['websocket']).to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
def ws_read_message(msg)
|
34
|
+
data = Zlib::GzipReader.new(StringIO.new(msg.data.map(&:chr).join)).read
|
35
|
+
Rails.logger.debug { "received websocket message: #{data}" }
|
36
|
+
|
37
|
+
object = JSON.parse(data)
|
38
|
+
ws_read_public_message(object)
|
39
|
+
end
|
40
|
+
|
41
|
+
def ws_read_public_message(msg)
|
42
|
+
if msg['ping'].present?
|
43
|
+
@ws.send(JSON.dump('pong': msg['ping']))
|
44
|
+
return
|
45
|
+
end
|
46
|
+
|
47
|
+
case msg['ch']
|
48
|
+
when /market\.#{@target}\.trade\.detail/
|
49
|
+
detect_trade(msg.dig('tick', 'data'))
|
50
|
+
when /market\.#{@target}\.mbp\.150/
|
51
|
+
detect_order(msg.dig('tick'))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def detect_order(msg)
|
56
|
+
if @increment_count < MIN_INCREMENT_COUNT_TO_SNAPSHOT && @snapshot_time <= Time.now - MAX_PERIOD_TO_SNAPSHOT
|
57
|
+
publish_snapshot
|
58
|
+
@increment_count = 0
|
59
|
+
elsif @increment_count >= MIN_INCREMENT_COUNT_TO_SNAPSHOT && @snapshot_time < Time.now - MIN_PERIOD_TO_SNAPSHOT
|
60
|
+
publish_snapshot
|
61
|
+
@increment_count = 0
|
62
|
+
end
|
63
|
+
fill_increment(msg)
|
64
|
+
end
|
65
|
+
|
66
|
+
def fill_increment(inc)
|
67
|
+
fill_side(inc, "bids")
|
68
|
+
fill_side(inc, "asks")
|
69
|
+
@increment_count += 1
|
70
|
+
end
|
71
|
+
|
72
|
+
def fill_side(inc, side)
|
73
|
+
inc[side].each do |price_point|
|
74
|
+
price = price_point[0]
|
75
|
+
amount = price_point[1]
|
76
|
+
if amount.zero?
|
77
|
+
@snap[side].delete_if { |point| point[0] == price.to_s }
|
78
|
+
else
|
79
|
+
@snap[side].delete_if { |point| point[0] == price.to_s }
|
80
|
+
@snap[side] << [price.to_s, amount.to_s]
|
81
|
+
end
|
82
|
+
if side == "bids"
|
83
|
+
@bids.delete_if { |point| point[0] == price }
|
84
|
+
@bids << [price.to_s, amount.to_s]
|
85
|
+
elsif side == "asks"
|
86
|
+
@asks.delete_if { |point| point[0] == price }
|
87
|
+
@asks << [price.to_s, amount.to_s]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def publish_increment
|
93
|
+
inc = {}
|
94
|
+
inc['bids'] = @bids.sort.reverse if @bids.present?
|
95
|
+
inc['asks'] = @asks.sort if @asks.present?
|
96
|
+
if inc.present?
|
97
|
+
@sequence_number += 1
|
98
|
+
@peatio_mq.enqueue_event('public', @market, 'ob-inc',
|
99
|
+
'bids' => inc['bids'], 'asks' => inc['asks'],
|
100
|
+
'sequence' => @sequence_number)
|
101
|
+
end
|
102
|
+
@bids = []
|
103
|
+
@asks = []
|
104
|
+
end
|
105
|
+
|
106
|
+
def publish_snapshot
|
107
|
+
@snapshot_time = Time.now
|
108
|
+
@peatio_mq.enqueue_event('public', @market, 'ob-snap',
|
109
|
+
'bids' => @snap['bids'].sort.reverse,
|
110
|
+
'asks' => @snap['asks'].sort,
|
111
|
+
'sequence' => @sequence_number)
|
112
|
+
end
|
113
|
+
|
114
|
+
def detect_trade(msg)
|
115
|
+
msg.map do |t|
|
116
|
+
trade =
|
117
|
+
{
|
118
|
+
'tid' => t['tradeId'],
|
119
|
+
'amount' => t['amount'].to_d,
|
120
|
+
'price' => t['price'].to_d,
|
121
|
+
'date' => t['ts'] / 1000,
|
122
|
+
'taker_type' => t['direction']
|
123
|
+
}
|
124
|
+
notify_public_trade(trade)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def ws_connect
|
129
|
+
super
|
130
|
+
return if @ping_set
|
131
|
+
|
132
|
+
Fiber.new do
|
133
|
+
EM::Synchrony.add_periodic_timer(80) do
|
134
|
+
@ws.send(JSON.dump('ping' => Time.now.to_i))
|
135
|
+
end
|
136
|
+
end.resume
|
137
|
+
@ping_set = true
|
138
|
+
end
|
139
|
+
|
140
|
+
def subscribe_trades(market, ws)
|
141
|
+
return unless @config['trade_proxy']
|
142
|
+
|
143
|
+
sub = {
|
144
|
+
'sub' => "market.#{market}.trade.detail"
|
145
|
+
}
|
146
|
+
|
147
|
+
Rails.logger.info 'Open event' + sub.to_s
|
148
|
+
EM.next_tick do
|
149
|
+
ws.send(JSON.generate(sub))
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def subscribe_orderbook(market, ws)
|
154
|
+
return unless @config['orderbook_proxy']
|
155
|
+
|
156
|
+
@sequence_number = 0
|
157
|
+
@increment_count = 0
|
158
|
+
@snapshot_time = Time.now
|
159
|
+
@bids = []
|
160
|
+
@asks = []
|
161
|
+
@snap = { 'asks' => [], 'bids' => [] }
|
162
|
+
sub = {
|
163
|
+
'sub' => "market.#{market}.mbp.150"
|
164
|
+
}
|
165
|
+
|
166
|
+
Rails.logger.info 'Open event' + sub.to_s
|
167
|
+
EM.next_tick do
|
168
|
+
ws.send(JSON.generate(sub))
|
169
|
+
end
|
170
|
+
Fiber.new do
|
171
|
+
EM::Synchrony.add_periodic_timer(0.2) do
|
172
|
+
publish_increment
|
173
|
+
end
|
174
|
+
end.resume
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
data/lib/irix/railtie.rb
ADDED
data/lib/irix/version.rb
ADDED
data/lib/irix.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "peatio"
|
2
|
+
#require "faraday_middleware"
|
3
|
+
require "faraday"
|
4
|
+
require "em-synchrony"
|
5
|
+
require "em-websocket"
|
6
|
+
require "eventmachine"
|
7
|
+
#require "faraday_middleware"
|
8
|
+
require "faye"
|
9
|
+
|
10
|
+
module Irix
|
11
|
+
require "irix/bitfinex"
|
12
|
+
require "irix/huobi"
|
13
|
+
require "irix/hooks"
|
14
|
+
require "irix/version"
|
15
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: irix3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.1
|
4
|
+
version: 3.2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naichuk M.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-synchrony
|
@@ -53,61 +53,61 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: faye
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '1.2'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '1.2'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: peatio
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '1
|
75
|
+
version: '3.1'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '1
|
82
|
+
version: '3.1'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: faraday_middleware
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: '1.2'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: '1.2'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: bundler
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '2.
|
103
|
+
version: '2.4'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '2.
|
110
|
+
version: '2.4'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: em-spec
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -237,10 +237,24 @@ dependencies:
|
|
237
237
|
description: Irix is implementing several crypto-exchange for Arke and Peatio.
|
238
238
|
email:
|
239
239
|
- mnaichuk@heliostech.fr
|
240
|
-
executables:
|
240
|
+
executables:
|
241
|
+
- console
|
242
|
+
- setup
|
241
243
|
extensions: []
|
242
244
|
extra_rdoc_files: []
|
243
|
-
files:
|
245
|
+
files:
|
246
|
+
- Gemfile
|
247
|
+
- Gemfile.lock
|
248
|
+
- README.md
|
249
|
+
- Rakefile
|
250
|
+
- bin/console
|
251
|
+
- bin/setup
|
252
|
+
- lib/irix.rb
|
253
|
+
- lib/irix/bitfinex.rb
|
254
|
+
- lib/irix/hooks.rb
|
255
|
+
- lib/irix/huobi.rb
|
256
|
+
- lib/irix/railtie.rb
|
257
|
+
- lib/irix/version.rb
|
244
258
|
homepage: https://www.openware.com
|
245
259
|
licenses: []
|
246
260
|
metadata: {}
|
@@ -259,7 +273,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
259
273
|
- !ruby/object:Gem::Version
|
260
274
|
version: '0'
|
261
275
|
requirements: []
|
262
|
-
rubygems_version: 3.
|
276
|
+
rubygems_version: 3.5.3
|
263
277
|
signing_key:
|
264
278
|
specification_version: 4
|
265
279
|
summary: Irix is implementing several crypto-exchange for Arke and Peatio.
|