irix3 3.1.1 → 3.3.2
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/Gemfile +4 -0
- data/Gemfile.lock +225 -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 +14 -0
- metadata +27 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 575dd9c7feb2770230a550cc6bee6032e6f740dd2715970a24aa8d21111a72af
|
4
|
+
data.tar.gz: 0af4c69d470ff8de17dd32151a62c65a034895c70b4e747dece11929db60e2c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c8a162b3e86c34f4f6165f6073d5452f84da5967c1943ced013f3e90d758265768e78108c814eff559c3a4196ff997f91804e1a68291eacc617e2cb515d4ab6
|
7
|
+
data.tar.gz: e544c5b83e6ba827786e424a10343afa0a1453e3a0778275d7af22f7a2a9df9ab684953943d21997510d7b9cae1dec403717e064af82380715e736b3e9462170
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
irix3 (3.3)
|
5
|
+
em-synchrony (~> 1.0)
|
6
|
+
em-websocket
|
7
|
+
eventmachine
|
8
|
+
peatio-dao (>= 3.1.3)
|
9
|
+
websocket-client-simple (~> 0.9.0)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
activemodel (8.0.2)
|
15
|
+
activesupport (= 8.0.2)
|
16
|
+
activesupport (8.0.2)
|
17
|
+
base64
|
18
|
+
benchmark (>= 0.3)
|
19
|
+
bigdecimal
|
20
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
21
|
+
connection_pool (>= 2.2.5)
|
22
|
+
drb
|
23
|
+
i18n (>= 1.6, < 2)
|
24
|
+
logger (>= 1.4.2)
|
25
|
+
minitest (>= 5.1)
|
26
|
+
securerandom (>= 0.3)
|
27
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
28
|
+
uri (>= 0.13.1)
|
29
|
+
amq-protocol (2.3.3)
|
30
|
+
amqp (1.8.0)
|
31
|
+
amq-protocol (>= 2.2.0)
|
32
|
+
eventmachine
|
33
|
+
ast (2.4.3)
|
34
|
+
base64 (0.2.0)
|
35
|
+
benchmark (0.4.0)
|
36
|
+
bigdecimal (3.1.9)
|
37
|
+
bunny (2.24.0)
|
38
|
+
amq-protocol (~> 2.3)
|
39
|
+
sorted_set (~> 1, >= 1.0.2)
|
40
|
+
byebug (12.0.0)
|
41
|
+
clamp (1.3.2)
|
42
|
+
coderay (1.1.3)
|
43
|
+
concurrent-ruby (1.3.5)
|
44
|
+
connection_pool (2.5.1)
|
45
|
+
daemons (1.4.1)
|
46
|
+
diff-lcs (1.6.1)
|
47
|
+
docile (1.4.1)
|
48
|
+
drb (2.2.1)
|
49
|
+
em-spec (0.2.7)
|
50
|
+
eventmachine
|
51
|
+
em-synchrony (1.0.6)
|
52
|
+
eventmachine (>= 1.0.0.beta.1)
|
53
|
+
em-websocket (0.5.3)
|
54
|
+
eventmachine (>= 0.12.9)
|
55
|
+
http_parser.rb (~> 0)
|
56
|
+
em-websocket-client (0.1.2)
|
57
|
+
eventmachine
|
58
|
+
websocket
|
59
|
+
event_emitter (0.2.6)
|
60
|
+
eventmachine (1.2.7)
|
61
|
+
faraday (1.10.4)
|
62
|
+
faraday-em_http (~> 1.0)
|
63
|
+
faraday-em_synchrony (~> 1.0)
|
64
|
+
faraday-excon (~> 1.1)
|
65
|
+
faraday-httpclient (~> 1.0)
|
66
|
+
faraday-multipart (~> 1.0)
|
67
|
+
faraday-net_http (~> 1.0)
|
68
|
+
faraday-net_http_persistent (~> 1.0)
|
69
|
+
faraday-patron (~> 1.0)
|
70
|
+
faraday-rack (~> 1.0)
|
71
|
+
faraday-retry (~> 1.0)
|
72
|
+
ruby2_keywords (>= 0.0.4)
|
73
|
+
faraday-em_http (1.0.0)
|
74
|
+
faraday-em_synchrony (1.0.0)
|
75
|
+
faraday-excon (1.1.0)
|
76
|
+
faraday-httpclient (1.0.1)
|
77
|
+
faraday-multipart (1.1.0)
|
78
|
+
multipart-post (~> 2.0)
|
79
|
+
faraday-net_http (1.0.2)
|
80
|
+
faraday-net_http_persistent (1.2.0)
|
81
|
+
faraday-patron (1.0.0)
|
82
|
+
faraday-rack (1.0.0)
|
83
|
+
faraday-retry (1.0.3)
|
84
|
+
http_parser.rb (0.8.0)
|
85
|
+
i18n (1.14.7)
|
86
|
+
concurrent-ruby (~> 1.0)
|
87
|
+
json (2.10.2)
|
88
|
+
jwt (2.10.1)
|
89
|
+
base64
|
90
|
+
language_server-protocol (3.17.0.4)
|
91
|
+
lint_roller (1.1.0)
|
92
|
+
logger (1.7.0)
|
93
|
+
method_source (1.1.0)
|
94
|
+
minitest (5.25.5)
|
95
|
+
multipart-post (2.4.1)
|
96
|
+
mutex_m (0.3.0)
|
97
|
+
mysql2 (0.5.6)
|
98
|
+
parallel (1.27.0)
|
99
|
+
parser (3.3.8.0)
|
100
|
+
ast (~> 2.4.1)
|
101
|
+
racc
|
102
|
+
peatio-dao (3.1.3)
|
103
|
+
activemodel (> 5.2)
|
104
|
+
amqp
|
105
|
+
bunny
|
106
|
+
clamp
|
107
|
+
em-synchrony (~> 1.0)
|
108
|
+
em-websocket
|
109
|
+
eventmachine
|
110
|
+
faraday (~> 1.10)
|
111
|
+
jwt
|
112
|
+
mysql2
|
113
|
+
prometheus-client
|
114
|
+
thin
|
115
|
+
websocket-client-simple (~> 0.9.0)
|
116
|
+
prism (1.4.0)
|
117
|
+
prometheus-client (4.2.4)
|
118
|
+
base64
|
119
|
+
pry (0.15.2)
|
120
|
+
coderay (~> 1.1)
|
121
|
+
method_source (~> 1.0)
|
122
|
+
pry-byebug (3.11.0)
|
123
|
+
byebug (~> 12.0)
|
124
|
+
pry (>= 0.13, < 0.16)
|
125
|
+
racc (1.8.1)
|
126
|
+
rack (2.2.13)
|
127
|
+
rainbow (3.1.1)
|
128
|
+
rake (13.2.1)
|
129
|
+
rbtree (0.4.6)
|
130
|
+
regexp_parser (2.10.0)
|
131
|
+
rspec (3.13.0)
|
132
|
+
rspec-core (~> 3.13.0)
|
133
|
+
rspec-expectations (~> 3.13.0)
|
134
|
+
rspec-mocks (~> 3.13.0)
|
135
|
+
rspec-core (3.13.3)
|
136
|
+
rspec-support (~> 3.13.0)
|
137
|
+
rspec-expectations (3.13.3)
|
138
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
139
|
+
rspec-support (~> 3.13.0)
|
140
|
+
rspec-mocks (3.13.2)
|
141
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
142
|
+
rspec-support (~> 3.13.0)
|
143
|
+
rspec-support (3.13.2)
|
144
|
+
rspec_junit_formatter (0.6.0)
|
145
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
146
|
+
rubocop (1.75.2)
|
147
|
+
json (~> 2.3)
|
148
|
+
language_server-protocol (~> 3.17.0.2)
|
149
|
+
lint_roller (~> 1.1.0)
|
150
|
+
parallel (~> 1.10)
|
151
|
+
parser (>= 3.3.0.2)
|
152
|
+
rainbow (>= 2.2.2, < 4.0)
|
153
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
154
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
155
|
+
ruby-progressbar (~> 1.7)
|
156
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
157
|
+
rubocop-ast (1.44.1)
|
158
|
+
parser (>= 3.3.7.2)
|
159
|
+
prism (~> 1.4)
|
160
|
+
rubocop-github (0.23.0)
|
161
|
+
rubocop (>= 1.72)
|
162
|
+
rubocop-performance (>= 1.24)
|
163
|
+
rubocop-rails (>= 2.23)
|
164
|
+
rubocop-performance (1.25.0)
|
165
|
+
lint_roller (~> 1.1)
|
166
|
+
rubocop (>= 1.75.0, < 2.0)
|
167
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
168
|
+
rubocop-rails (2.31.0)
|
169
|
+
activesupport (>= 4.2.0)
|
170
|
+
lint_roller (~> 1.1)
|
171
|
+
rack (>= 1.1)
|
172
|
+
rubocop (>= 1.75.0, < 2.0)
|
173
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
174
|
+
ruby-progressbar (1.13.0)
|
175
|
+
ruby2_keywords (0.0.5)
|
176
|
+
securerandom (0.4.1)
|
177
|
+
set (1.1.1)
|
178
|
+
simplecov (0.22.0)
|
179
|
+
docile (~> 1.1)
|
180
|
+
simplecov-html (~> 0.11)
|
181
|
+
simplecov_json_formatter (~> 0.1)
|
182
|
+
simplecov-html (0.13.1)
|
183
|
+
simplecov-json (0.2.3)
|
184
|
+
json
|
185
|
+
simplecov
|
186
|
+
simplecov_json_formatter (0.1.4)
|
187
|
+
sorted_set (1.0.3)
|
188
|
+
rbtree
|
189
|
+
set (~> 1.0)
|
190
|
+
thin (1.8.2)
|
191
|
+
daemons (~> 1.0, >= 1.0.9)
|
192
|
+
eventmachine (~> 1.0, >= 1.0.4)
|
193
|
+
rack (>= 1, < 3)
|
194
|
+
tzinfo (2.0.6)
|
195
|
+
concurrent-ruby (~> 1.0)
|
196
|
+
unicode-display_width (3.1.4)
|
197
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
198
|
+
unicode-emoji (4.0.4)
|
199
|
+
uri (1.0.3)
|
200
|
+
websocket (1.2.11)
|
201
|
+
websocket-client-simple (0.9.0)
|
202
|
+
base64
|
203
|
+
event_emitter
|
204
|
+
mutex_m
|
205
|
+
websocket
|
206
|
+
|
207
|
+
PLATFORMS
|
208
|
+
ruby
|
209
|
+
x86_64-linux
|
210
|
+
|
211
|
+
DEPENDENCIES
|
212
|
+
bundler (~> 2.4)
|
213
|
+
em-spec
|
214
|
+
em-websocket-client
|
215
|
+
irix3!
|
216
|
+
pry-byebug
|
217
|
+
rake (~> 13.0)
|
218
|
+
rspec (~> 3.0)
|
219
|
+
rspec_junit_formatter
|
220
|
+
rubocop-github
|
221
|
+
simplecov
|
222
|
+
simplecov-json
|
223
|
+
|
224
|
+
BUNDLED WITH
|
225
|
+
2.6.6
|
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,14 @@
|
|
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
|
+
|
9
|
+
module Irix
|
10
|
+
require "irix/bitfinex"
|
11
|
+
require "irix/huobi"
|
12
|
+
require "irix/hooks"
|
13
|
+
require "irix/version"
|
14
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: irix3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naichuk M.
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-04-20 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: em-synchrony
|
@@ -53,61 +52,47 @@ dependencies:
|
|
53
52
|
- !ruby/object:Gem::Version
|
54
53
|
version: '0'
|
55
54
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
55
|
+
name: websocket-client-simple
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
58
57
|
requirements:
|
59
58
|
- - "~>"
|
60
59
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
60
|
+
version: 0.9.0
|
62
61
|
type: :runtime
|
63
62
|
prerelease: false
|
64
63
|
version_requirements: !ruby/object:Gem::Requirement
|
65
64
|
requirements:
|
66
65
|
- - "~>"
|
67
66
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
67
|
+
version: 0.9.0
|
69
68
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '1.2'
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '1.2'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: peatio
|
69
|
+
name: peatio-dao
|
85
70
|
requirement: !ruby/object:Gem::Requirement
|
86
71
|
requirements:
|
87
72
|
- - ">="
|
88
73
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
74
|
+
version: 3.1.3
|
90
75
|
type: :runtime
|
91
76
|
prerelease: false
|
92
77
|
version_requirements: !ruby/object:Gem::Requirement
|
93
78
|
requirements:
|
94
79
|
- - ">="
|
95
80
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
81
|
+
version: 3.1.3
|
97
82
|
- !ruby/object:Gem::Dependency
|
98
83
|
name: bundler
|
99
84
|
requirement: !ruby/object:Gem::Requirement
|
100
85
|
requirements:
|
101
86
|
- - "~>"
|
102
87
|
- !ruby/object:Gem::Version
|
103
|
-
version: '2.
|
88
|
+
version: '2.4'
|
104
89
|
type: :development
|
105
90
|
prerelease: false
|
106
91
|
version_requirements: !ruby/object:Gem::Requirement
|
107
92
|
requirements:
|
108
93
|
- - "~>"
|
109
94
|
- !ruby/object:Gem::Version
|
110
|
-
version: '2.
|
95
|
+
version: '2.4'
|
111
96
|
- !ruby/object:Gem::Dependency
|
112
97
|
name: em-spec
|
113
98
|
requirement: !ruby/object:Gem::Requirement
|
@@ -237,14 +222,27 @@ dependencies:
|
|
237
222
|
description: Irix is implementing several crypto-exchange for Arke and Peatio.
|
238
223
|
email:
|
239
224
|
- mnaichuk@heliostech.fr
|
240
|
-
executables:
|
225
|
+
executables:
|
226
|
+
- console
|
227
|
+
- setup
|
241
228
|
extensions: []
|
242
229
|
extra_rdoc_files: []
|
243
|
-
files:
|
230
|
+
files:
|
231
|
+
- Gemfile
|
232
|
+
- Gemfile.lock
|
233
|
+
- README.md
|
234
|
+
- Rakefile
|
235
|
+
- bin/console
|
236
|
+
- bin/setup
|
237
|
+
- lib/irix.rb
|
238
|
+
- lib/irix/bitfinex.rb
|
239
|
+
- lib/irix/hooks.rb
|
240
|
+
- lib/irix/huobi.rb
|
241
|
+
- lib/irix/railtie.rb
|
242
|
+
- lib/irix/version.rb
|
244
243
|
homepage: https://www.openware.com
|
245
244
|
licenses: []
|
246
245
|
metadata: {}
|
247
|
-
post_install_message:
|
248
246
|
rdoc_options: []
|
249
247
|
require_paths:
|
250
248
|
- lib
|
@@ -259,8 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
259
257
|
- !ruby/object:Gem::Version
|
260
258
|
version: '0'
|
261
259
|
requirements: []
|
262
|
-
rubygems_version: 3.
|
263
|
-
signing_key:
|
260
|
+
rubygems_version: 3.6.6
|
264
261
|
specification_version: 4
|
265
262
|
summary: Irix is implementing several crypto-exchange for Arke and Peatio.
|
266
263
|
test_files: []
|