irix 2.4.3 → 2.4.4

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: 66522df660b1ad84d6085e2c85ad9560b6caeca36964d302270bfdcbaba01a16
4
- data.tar.gz: f1f81a8dd46e33d1fc118ad77df41afec7ba40bdc5f7fb9e79a35128b2adf5b2
3
+ metadata.gz: caf68e868b63a60fc53b7570e0621737269f5e66283ca78fc1f732c003656afb
4
+ data.tar.gz: d30d96951ae9c217e8a91ede2026f670d9a48ca26edd84ec161c22d24175167e
5
5
  SHA512:
6
- metadata.gz: 379e9c8f811ba1cf5ce927553551c3f52228217b2c064b475c3e772a2fe8d80b6d6bdc004a121660275094f0cc2fcd2f87d49eed1d9eb1e7b3149cab58d9ce6a
7
- data.tar.gz: 6bdb2cda4714b4f14f813edd915bf921954b0c6379921a4ed943e82a9ce3f3e70abecd7121f1d05fef032ba26cad849bc4085864a5e3ea18421e969e24075b8a
6
+ metadata.gz: 5c26e9e5fe8d3734e6cf5336f86178d52c4404e092d523094418af187cccb34c84b4610994818d5e6ffd882fedef8cf1738c2ab7342664e72f8f9e0e6919262f
7
+ data.tar.gz: 4263f3d2204ee46bce976d3e5d271baba30390d4131cb060ef6a7f0e4e5c9b36169b8536f32f78d21c2efef6a7ed65b814eddd9bac5b59c0e7350ea4cd094653
data/.drone.yml CHANGED
@@ -9,6 +9,21 @@ steps:
9
9
  - gem install bundler:2.0.2
10
10
  - bundle install --jobs=$(nproc) --retry=3 --path vendor/bundle
11
11
  - bundle exec rspec
12
+
13
+ - name: Release gem
14
+ image: ruby:2.6
15
+ environment:
16
+ GEM_CREDENTIALS:
17
+ from_secret: gem_credentials
18
+ commands:
19
+ - mkdir -p ~/.gem
20
+ - echo $GEM_CREDENTIALS | base64 -d > ~/.gem/credentials
21
+ - chmod 0600 ~/.gem/credentials
22
+ - gem build irix.gemspec
23
+ - gem push irix-*.gem
24
+ when:
25
+ branch:
26
+ - master
12
27
 
13
28
  trigger:
14
29
  event:
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- irix (2.4.3)
4
+ irix (2.4.4)
5
5
  em-synchrony (~> 1.0)
6
6
  em-websocket
7
7
  eventmachine
@@ -22,13 +22,13 @@ GEM
22
22
  zeitwerk (~> 2.1, >= 2.1.8)
23
23
  addressable (2.7.0)
24
24
  public_suffix (>= 2.0.2, < 5.0)
25
- amq-protocol (2.3.0)
25
+ amq-protocol (2.3.1)
26
26
  amqp (1.8.0)
27
27
  amq-protocol (>= 2.2.0)
28
28
  eventmachine
29
29
  ast (2.4.0)
30
- bunny (2.14.4)
31
- amq-protocol (~> 2.3, >= 2.3.0)
30
+ bunny (2.15.0)
31
+ amq-protocol (~> 2.3, >= 2.3.1)
32
32
  byebug (11.1.1)
33
33
  clamp (1.3.1)
34
34
  coderay (1.1.2)
@@ -60,7 +60,7 @@ GEM
60
60
  multipart-post (>= 1.2, < 3)
61
61
  faraday_middleware (0.13.1)
62
62
  faraday (>= 0.7.4, < 1.0)
63
- faye (1.2.4)
63
+ faye (1.2.5)
64
64
  cookiejar (>= 0.3.0)
65
65
  em-http-request (>= 0.3.0)
66
66
  eventmachine (>= 0.12.0)
@@ -85,7 +85,7 @@ GEM
85
85
  parallel (1.19.0)
86
86
  parser (2.6.5.0)
87
87
  ast (~> 2.4.0)
88
- peatio (2.4.3)
88
+ peatio (2.4.4)
89
89
  activemodel (> 5.2, <= 6.0.0)
90
90
  amqp
91
91
  bunny
@@ -106,7 +106,7 @@ GEM
106
106
  pry-byebug (3.8.0)
107
107
  byebug (~> 11.0)
108
108
  pry (~> 0.10)
109
- public_suffix (4.0.3)
109
+ public_suffix (4.0.5)
110
110
  rack (2.2.2)
111
111
  rainbow (3.0.0)
112
112
  rake (13.0.1)
@@ -151,7 +151,7 @@ GEM
151
151
  eventmachine (~> 1.0, >= 1.0.4)
152
152
  rack (>= 1, < 3)
153
153
  thread_safe (0.3.6)
154
- tzinfo (1.2.6)
154
+ tzinfo (1.2.7)
155
155
  thread_safe (~> 0.1)
156
156
  unicode-display_width (1.6.0)
157
157
  websocket (1.2.8)
@@ -177,4 +177,4 @@ DEPENDENCIES
177
177
  simplecov-json
178
178
 
179
179
  BUNDLED WITH
180
- 2.0.2
180
+ 2.1.4
data/lib/irix/huobi.rb CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  module Irix
4
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
5
13
  # WS huobi global
6
14
  # websocket: "wss://api.huobi.pro/ws/"
7
15
  # WS for krw markets
@@ -37,11 +45,76 @@ module Irix
37
45
  end
38
46
 
39
47
  case msg['ch']
40
- when /market\.([^.]+)\.trade\.detail/
48
+ when /market\.#{@target}\.trade\.detail/
41
49
  detect_trade(msg.dig('tick', 'data'))
50
+ when /market\.#{@target}\.mbp\.150/
51
+ detect_order(msg.dig('tick'))
52
+ end
53
+ pp @bids
54
+ pp @asks
55
+ pp @snap
56
+ end
57
+
58
+ def detect_order(msg)
59
+ if @increment_count < MIN_INCREMENT_COUNT_TO_SNAPSHOT && @snapshot_time <= Time.now - MAX_PERIOD_TO_SNAPSHOT
60
+ publish_snapshot
61
+ @increment_count = 0
62
+ elsif @increment_count >= MIN_INCREMENT_COUNT_TO_SNAPSHOT && @snapshot_time < Time.now - MIN_PERIOD_TO_SNAPSHOT
63
+ publish_snapshot
64
+ @increment_count = 0
65
+ end
66
+ fill_increment(msg)
67
+ end
68
+
69
+ def fill_increment(inc)
70
+ binding.pry
71
+ fill_side(inc, "bids")
72
+ fill_side(inc, "asks")
73
+ @increment_count += 1
74
+ end
75
+
76
+ def fill_side(inc, side)
77
+ inc[side].each do |price_point|
78
+ price = price_point[0]
79
+ amount = price_point[1]
80
+ if amount.zero?
81
+ @snap[side].delete_if { |point| point[0] == price.to_s }
82
+ else
83
+ @snap[side].delete_if { |point| point[0] == price.to_s }
84
+ @snap[side] << [price.to_s, amount.to_s]
85
+ end
86
+ if side == "bids"
87
+ @bids.delete_if { |point| point[0] == price }
88
+ @bids << [price.to_s, amount.to_s]
89
+ elsif side == "asks"
90
+ @asks.delete_if { |point| point[0] == price }
91
+ @asks << [price.to_s, amount.to_s]
92
+ end
42
93
  end
43
94
  end
44
95
 
96
+ def publish_increment
97
+ inc = {}
98
+ inc['bids'] = @bids.sort.reverse if @bids.present?
99
+ inc['asks'] = @asks.sort if @asks.present?
100
+ if inc.present?
101
+ @sequence_number += 1
102
+ @peatio_mq.enqueue_event('public', @market, 'ob-inc',
103
+ 'bids' => inc['bids'], 'asks' => inc['asks'],
104
+ 'sequence' => @sequence_number)
105
+ end
106
+ @bids = []
107
+ @asks = []
108
+ end
109
+
110
+ def publish_snapshot
111
+ @snapshot_time = Time.now
112
+ @peatio_mq.enqueue_event('public', @market, 'ob-snap',
113
+ 'bids' => @snap['bids'].sort.reverse,
114
+ 'asks' => @snap['asks'].sort,
115
+ 'sequence' => @sequence_number)
116
+ end
117
+
45
118
  def detect_trade(msg)
46
119
  msg.map do |t|
47
120
  trade =
@@ -69,6 +142,8 @@ module Irix
69
142
  end
70
143
 
71
144
  def subscribe_trades(market, ws)
145
+ return unless @config['trade_proxy']
146
+
72
147
  sub = {
73
148
  'sub' => "market.#{market}.trade.detail"
74
149
  }
@@ -78,5 +153,29 @@ module Irix
78
153
  ws.send(JSON.generate(sub))
79
154
  end
80
155
  end
156
+
157
+ def subscribe_orderbook(market, ws)
158
+ return unless @config['orderbook_proxy']
159
+
160
+ @sequence_number = 0
161
+ @increment_count = 0
162
+ @snapshot_time = Time.now
163
+ @bids = []
164
+ @asks = []
165
+ @snap = { 'asks' => [], 'bids' => [] }
166
+ sub = {
167
+ 'sub' => "market.#{market}.mbp.150"
168
+ }
169
+
170
+ Rails.logger.info 'Open event' + sub.to_s
171
+ EM.next_tick do
172
+ ws.send(JSON.generate(sub))
173
+ end
174
+ Fiber.new do
175
+ EM::Synchrony.add_periodic_timer(0.2) do
176
+ publish_increment
177
+ end
178
+ end.resume
179
+ end
81
180
  end
82
181
  end
data/lib/irix/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Irix
2
- VERSION = "2.4.3"
2
+ VERSION = "2.4.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irix
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.3
4
+ version: 2.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naichuk M.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-20 00:00:00.000000000 Z
11
+ date: 2020-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-synchrony