irix3 3.1.1 → 3.3.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.

Potentially problematic release.


This version of irix3 might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e6b21303c4fb330f43ee1d2b9a8554a69808084d49a7cab22466abdc589444c
4
- data.tar.gz: 2c444fcfffac5fa0dd48708d5065b2ae24615e4437a6ed4e10152f1f1d3602fb
3
+ metadata.gz: 72f0349ff517766bfd480c9a1696cb036faba32fc1ab939941dd9c0b5485ee57
4
+ data.tar.gz: 697e452e592592e1bd7c02f4f786fdcc9ce58698e973f88f6151b5771161fe2a
5
5
  SHA512:
6
- metadata.gz: 103e95215bddebe2dcde753bc4715e710b201db151fb4ce33e9fd164a075e7bd3cecf9794311c365407993c971eafa27e4ce88c963702d8db6d1bf1a7cd49cb7
7
- data.tar.gz: 17d82733ea7615a419e801bb92f65103d4627bbbc4f23527287229ce313779c6b1d2c0807c04ea4d8c4fe667fd0217af4abc2772ea96d9ccdd9bd12fc2219cbd
6
+ metadata.gz: 5a53bbc388b2e31c0963564e6abdbf38cea7217e610abe9feff41d441731c2b4962341f5a6f0022a1dba0ef12d7b3ee9ccd05d9e71368dd0ce3455871461befd
7
+ data.tar.gz: 6ca82a154a439a9a274ce683a88f640e4527b09c6c8b55a14970e611d2d3587a699844a770f073d522ef191caac8bcf4f869759aaee4490fc986d45b35bb238b
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in irix.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,242 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ irix3 (3.3.1)
5
+ em-synchrony (~> 1.0)
6
+ em-websocket
7
+ eventmachine
8
+ faraday_middleware (~> 1.2)
9
+ faye (~> 1.2)
10
+ peatio-dao (>= 3.1.2)
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
+ event_emitter (0.2.6)
68
+ eventmachine (1.2.7)
69
+ faraday (1.10.3)
70
+ faraday-em_http (~> 1.0)
71
+ faraday-em_synchrony (~> 1.0)
72
+ faraday-excon (~> 1.1)
73
+ faraday-httpclient (~> 1.0)
74
+ faraday-multipart (~> 1.0)
75
+ faraday-net_http (~> 1.0)
76
+ faraday-net_http_persistent (~> 1.0)
77
+ faraday-patron (~> 1.0)
78
+ faraday-rack (~> 1.0)
79
+ faraday-retry (~> 1.0)
80
+ ruby2_keywords (>= 0.0.4)
81
+ faraday-em_http (1.0.0)
82
+ faraday-em_synchrony (1.0.0)
83
+ faraday-excon (1.1.0)
84
+ faraday-httpclient (1.0.1)
85
+ faraday-multipart (1.0.4)
86
+ multipart-post (~> 2)
87
+ faraday-net_http (1.0.1)
88
+ faraday-net_http_persistent (1.2.0)
89
+ faraday-patron (1.0.0)
90
+ faraday-rack (1.0.0)
91
+ faraday-retry (1.0.3)
92
+ faraday_middleware (1.2.0)
93
+ faraday (~> 1.0)
94
+ faye (1.4.0)
95
+ cookiejar (>= 0.3.0)
96
+ em-http-request (>= 1.1.6)
97
+ eventmachine (>= 0.12.0)
98
+ faye-websocket (>= 0.11.0)
99
+ multi_json (>= 1.0.0)
100
+ rack (>= 1.0.0)
101
+ websocket-driver (>= 0.5.1)
102
+ faye-websocket (0.11.3)
103
+ eventmachine (>= 0.12.0)
104
+ websocket-driver (>= 0.5.1)
105
+ http_parser.rb (0.8.0)
106
+ i18n (1.14.5)
107
+ concurrent-ruby (~> 1.0)
108
+ json (2.7.2)
109
+ jwt (2.8.2)
110
+ base64
111
+ language_server-protocol (3.17.0.3)
112
+ method_source (1.1.0)
113
+ minitest (5.24.0)
114
+ multi_json (1.15.0)
115
+ multipart-post (2.4.1)
116
+ mutex_m (0.2.0)
117
+ mysql2 (0.5.6)
118
+ parallel (1.25.1)
119
+ parser (3.3.3.0)
120
+ ast (~> 2.4.1)
121
+ racc
122
+ peatio-dao (3.1.2)
123
+ activemodel (> 5.2)
124
+ amqp
125
+ bunny
126
+ clamp
127
+ em-synchrony (~> 1.0)
128
+ em-websocket
129
+ eventmachine
130
+ faraday (>= 1.10)
131
+ jwt
132
+ mysql2
133
+ prometheus-client
134
+ thin
135
+ websocket-client-simple (~> 0.9.0)
136
+ prometheus-client (4.2.2)
137
+ pry (0.14.2)
138
+ coderay (~> 1.1)
139
+ method_source (~> 1.0)
140
+ pry-byebug (3.10.1)
141
+ byebug (~> 11.0)
142
+ pry (>= 0.13, < 0.15)
143
+ public_suffix (5.1.1)
144
+ racc (1.8.0)
145
+ rack (2.2.9)
146
+ rainbow (3.1.1)
147
+ rake (13.2.1)
148
+ rbtree (0.4.6)
149
+ regexp_parser (2.9.2)
150
+ rexml (3.3.1)
151
+ strscan
152
+ rspec (3.13.0)
153
+ rspec-core (~> 3.13.0)
154
+ rspec-expectations (~> 3.13.0)
155
+ rspec-mocks (~> 3.13.0)
156
+ rspec-core (3.13.0)
157
+ rspec-support (~> 3.13.0)
158
+ rspec-expectations (3.13.1)
159
+ diff-lcs (>= 1.2.0, < 2.0)
160
+ rspec-support (~> 3.13.0)
161
+ rspec-mocks (3.13.1)
162
+ diff-lcs (>= 1.2.0, < 2.0)
163
+ rspec-support (~> 3.13.0)
164
+ rspec-support (3.13.1)
165
+ rspec_junit_formatter (0.6.0)
166
+ rspec-core (>= 2, < 4, != 2.12.0)
167
+ rubocop (1.64.1)
168
+ json (~> 2.3)
169
+ language_server-protocol (>= 3.17.0)
170
+ parallel (~> 1.10)
171
+ parser (>= 3.3.0.2)
172
+ rainbow (>= 2.2.2, < 4.0)
173
+ regexp_parser (>= 1.8, < 3.0)
174
+ rexml (>= 3.2.5, < 4.0)
175
+ rubocop-ast (>= 1.31.1, < 2.0)
176
+ ruby-progressbar (~> 1.7)
177
+ unicode-display_width (>= 2.4.0, < 3.0)
178
+ rubocop-ast (1.31.3)
179
+ parser (>= 3.3.1.0)
180
+ rubocop-github (0.20.0)
181
+ rubocop (>= 1.37)
182
+ rubocop-performance (>= 1.15)
183
+ rubocop-rails (>= 2.17)
184
+ rubocop-performance (1.21.1)
185
+ rubocop (>= 1.48.1, < 2.0)
186
+ rubocop-ast (>= 1.31.1, < 2.0)
187
+ rubocop-rails (2.25.0)
188
+ activesupport (>= 4.2.0)
189
+ rack (>= 1.1)
190
+ rubocop (>= 1.33.0, < 2.0)
191
+ rubocop-ast (>= 1.31.1, < 2.0)
192
+ ruby-progressbar (1.13.0)
193
+ ruby2_keywords (0.0.5)
194
+ set (1.0.4)
195
+ simplecov (0.22.0)
196
+ docile (~> 1.1)
197
+ simplecov-html (~> 0.11)
198
+ simplecov_json_formatter (~> 0.1)
199
+ simplecov-html (0.12.3)
200
+ simplecov-json (0.2.3)
201
+ json
202
+ simplecov
203
+ simplecov_json_formatter (0.1.4)
204
+ sorted_set (1.0.3)
205
+ rbtree
206
+ set (~> 1.0)
207
+ strscan (3.1.0)
208
+ thin (1.8.2)
209
+ daemons (~> 1.0, >= 1.0.9)
210
+ eventmachine (~> 1.0, >= 1.0.4)
211
+ rack (>= 1, < 3)
212
+ tzinfo (2.0.6)
213
+ concurrent-ruby (~> 1.0)
214
+ unicode-display_width (2.5.0)
215
+ websocket (1.2.10)
216
+ websocket-client-simple (0.9.0)
217
+ base64
218
+ event_emitter
219
+ mutex_m
220
+ websocket
221
+ websocket-driver (0.7.6)
222
+ websocket-extensions (>= 0.1.0)
223
+ websocket-extensions (0.1.5)
224
+
225
+ PLATFORMS
226
+ x86_64-linux
227
+
228
+ DEPENDENCIES
229
+ bundler (~> 2.4)
230
+ em-spec
231
+ em-websocket-client
232
+ irix3!
233
+ pry-byebug
234
+ rake (~> 13.0)
235
+ rspec (~> 3.0)
236
+ rspec_junit_formatter
237
+ rubocop-github
238
+ simplecov
239
+ simplecov-json
240
+
241
+ BUNDLED WITH
242
+ 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
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Irix
4
+ class Railtie < Rails::Railtie
5
+ config.after_initialize do
6
+ Hooks.register
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Irix
2
+ VERSION = "3.3.1"
3
+ end
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,13 @@
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.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naichuk M.
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-06-15 00:00:00.000000000 Z
10
+ date: 2025-04-17 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: em-synchrony
@@ -53,61 +52,61 @@ dependencies:
53
52
  - !ruby/object:Gem::Version
54
53
  version: '0'
55
54
  - !ruby/object:Gem::Dependency
56
- name: faraday_middleware
55
+ name: faye
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - "~>"
60
59
  - !ruby/object:Gem::Version
61
- version: 0.13.1
60
+ version: '1.2'
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.13.1
67
+ version: '1.2'
69
68
  - !ruby/object:Gem::Dependency
70
- name: faye
69
+ name: peatio-dao
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
- - - "~>"
72
+ - - ">="
74
73
  - !ruby/object:Gem::Version
75
- version: '1.2'
74
+ version: 3.1.2
76
75
  type: :runtime
77
76
  prerelease: false
78
77
  version_requirements: !ruby/object:Gem::Requirement
79
78
  requirements:
80
- - - "~>"
79
+ - - ">="
81
80
  - !ruby/object:Gem::Version
82
- version: '1.2'
81
+ version: 3.1.2
83
82
  - !ruby/object:Gem::Dependency
84
- name: peatio
83
+ name: faraday_middleware
85
84
  requirement: !ruby/object:Gem::Requirement
86
85
  requirements:
87
- - - ">="
86
+ - - "~>"
88
87
  - !ruby/object:Gem::Version
89
- version: 2.4.2
88
+ version: '1.2'
90
89
  type: :runtime
91
90
  prerelease: false
92
91
  version_requirements: !ruby/object:Gem::Requirement
93
92
  requirements:
94
- - - ">="
93
+ - - "~>"
95
94
  - !ruby/object:Gem::Version
96
- version: 2.4.2
95
+ version: '1.2'
97
96
  - !ruby/object:Gem::Dependency
98
97
  name: bundler
99
98
  requirement: !ruby/object:Gem::Requirement
100
99
  requirements:
101
100
  - - "~>"
102
101
  - !ruby/object:Gem::Version
103
- version: '2.0'
102
+ version: '2.4'
104
103
  type: :development
105
104
  prerelease: false
106
105
  version_requirements: !ruby/object:Gem::Requirement
107
106
  requirements:
108
107
  - - "~>"
109
108
  - !ruby/object:Gem::Version
110
- version: '2.0'
109
+ version: '2.4'
111
110
  - !ruby/object:Gem::Dependency
112
111
  name: em-spec
113
112
  requirement: !ruby/object:Gem::Requirement
@@ -237,14 +236,27 @@ dependencies:
237
236
  description: Irix is implementing several crypto-exchange for Arke and Peatio.
238
237
  email:
239
238
  - mnaichuk@heliostech.fr
240
- executables: []
239
+ executables:
240
+ - console
241
+ - setup
241
242
  extensions: []
242
243
  extra_rdoc_files: []
243
- files: []
244
+ files:
245
+ - Gemfile
246
+ - Gemfile.lock
247
+ - README.md
248
+ - Rakefile
249
+ - bin/console
250
+ - bin/setup
251
+ - lib/irix.rb
252
+ - lib/irix/bitfinex.rb
253
+ - lib/irix/hooks.rb
254
+ - lib/irix/huobi.rb
255
+ - lib/irix/railtie.rb
256
+ - lib/irix/version.rb
244
257
  homepage: https://www.openware.com
245
258
  licenses: []
246
259
  metadata: {}
247
- post_install_message:
248
260
  rdoc_options: []
249
261
  require_paths:
250
262
  - lib
@@ -259,8 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
259
271
  - !ruby/object:Gem::Version
260
272
  version: '0'
261
273
  requirements: []
262
- rubygems_version: 3.0.8
263
- signing_key:
274
+ rubygems_version: 3.6.6
264
275
  specification_version: 4
265
276
  summary: Irix is implementing several crypto-exchange for Arke and Peatio.
266
277
  test_files: []