irix 2.4.1 → 2.4.2

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: caedc8fae1848a9d4aae0465cf99219c179dddb3a94854e46692246448149b65
4
- data.tar.gz: c7889d940a00aea620b57c168e1ec87ae4807924a1f0cd6083a7e9d9ddc40b56
3
+ metadata.gz: c95445e49c906a31bbc9e16f2b4b78ca8d023fca73f5d29128d9531ab0112c18
4
+ data.tar.gz: 79e6e7f4d815726d6624e4d79c0a0d8db2ebed9bda2534645c29b40bbffbf7d4
5
5
  SHA512:
6
- metadata.gz: 3421bc3612236d3a933ec9bb84e34fb6796d910f94cc71fca8e075b318ad0b39d6b533a4c625b73c28240b7f07fb7a70c87bbde5b2920fa7f4e6d97c7f6b10b9
7
- data.tar.gz: fcde730a14bf33dacc5df16302bc8c768043da35b32b2e769dd4eefedacf9d77d242f9f4fa49ab94365bf48ca81bf8dbd18ba34d648824e622bcc96d09c6ef54
6
+ metadata.gz: '0509583f671a0de4396eaec6ae5cc524e0bf4924afb4186c7efa6487dfff53fcc657eccfdf53158a1e81deb3e24b7937a066a4c0e65669b209fda92c1c507133'
7
+ data.tar.gz: d77b1f4410a5ff9d7ce1268aa30ea7e16556534f5684b3b14ddb241c6d9774e4c19518d92484d34cb8525818b53c3af72954f48eaf7782c1467bf6d3eef2b8d5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- irix (2.4.1)
4
+ irix (2.4.2)
5
5
  em-synchrony (~> 1.0)
6
6
  em-websocket
7
7
  eventmachine
data/lib/irix.rb CHANGED
@@ -8,6 +8,7 @@ require "faye"
8
8
 
9
9
  module Irix
10
10
  require "irix/bitfinex"
11
+ require "irix/huobi"
11
12
  require "irix/hooks"
12
13
  require "irix/version"
13
14
  end
data/lib/irix/bitfinex.rb CHANGED
@@ -14,7 +14,7 @@ module Irix
14
14
  end
15
15
  @ping_set = false
16
16
  @rest = (config['rest']).to_s
17
- @ws_url = "#{config['websocket']}/public"
17
+ @ws_url = "#{config['websocket']}"
18
18
  end
19
19
 
20
20
  def ws_connect
data/lib/irix/hooks.rb CHANGED
@@ -5,6 +5,7 @@ module Irix
5
5
  class << self
6
6
  def register
7
7
  Peatio::Upstream.registry[:bitfinex] = Irix::Bitfinex
8
+ Peatio::Upstream.registry[:huobi] = Irix::Huobi
8
9
  end
9
10
  end
10
11
 
data/lib/irix/huobi.rb ADDED
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Irix
4
+ class Huobi < Peatio::Upstream::Base
5
+ # WS huobi global
6
+ # websocket: "wss://api.huobi.pro/ws/"
7
+ # WS for krw markets
8
+ # websocket: "wss://api-cloud.huobi.co.kr/ws/"
9
+
10
+ def initialize(config)
11
+ super
12
+ @connection = Faraday.new(url: (config['rest']).to_s) do |builder|
13
+ builder.response :json
14
+ builder.response :logger if config['debug']
15
+ builder.adapter(@adapter)
16
+ unless config['verify_ssl'].nil?
17
+ builder.ssl[:verify] = config['verify_ssl']
18
+ end
19
+ end
20
+ @ping_set = false
21
+ @rest = (config['rest']).to_s
22
+ @ws_url = (config['websocket']).to_s
23
+ end
24
+
25
+ def ws_read_message(msg)
26
+ data = Zlib::GzipReader.new(StringIO.new(msg.data.map(&:chr).join)).read
27
+ Rails.logger.debug { "received websocket message: #{data}" }
28
+
29
+ object = JSON.parse(data)
30
+ ws_read_public_message(object)
31
+ end
32
+
33
+ def ws_read_public_message(msg)
34
+ if msg['ping'].present?
35
+ @ws.send(JSON.dump('pong': msg['ping']))
36
+ return
37
+ end
38
+
39
+ case msg['ch']
40
+ when /market\.([^.]+)\.trade\.detail/
41
+ detect_trade(msg.dig('tick', 'data'))
42
+ end
43
+ end
44
+
45
+ def detect_trade(msg)
46
+ msg.map do |t|
47
+ trade =
48
+ {
49
+ 'tid' => t['tradeId'],
50
+ 'amount' => t['amount'].to_d,
51
+ 'price' => t['price'].to_d,
52
+ 'date' => t['ts'] / 1000,
53
+ 'taker_type' => t['direction']
54
+ }
55
+ notify_public_trade(trade)
56
+ end
57
+ end
58
+
59
+ def ws_connect
60
+ super
61
+ return if @ping_set
62
+
63
+ Fiber.new do
64
+ EM::Synchrony.add_periodic_timer(80) do
65
+ @ws.send(JSON.dump('ping' => Time.now.to_i))
66
+ end
67
+ end.resume
68
+ @ping_set = true
69
+ end
70
+
71
+ def subscribe_trades(market, ws)
72
+ sub = {
73
+ 'sub' => "market.#{market}.trade.detail"
74
+ }
75
+
76
+ Rails.logger.info 'Open event' + sub.to_s
77
+ EM.next_tick do
78
+ ws.send(JSON.generate(sub))
79
+ end
80
+ end
81
+ end
82
+ end
data/lib/irix/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Irix
2
- VERSION = "2.4.1"
2
+ VERSION = "2.4.2"
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.1
4
+ version: 2.4.2
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-03-11 00:00:00.000000000 Z
11
+ date: 2020-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-synchrony
@@ -256,6 +256,7 @@ files:
256
256
  - lib/irix.rb
257
257
  - lib/irix/bitfinex.rb
258
258
  - lib/irix/hooks.rb
259
+ - lib/irix/huobi.rb
259
260
  - lib/irix/railtie.rb
260
261
  - lib/irix/version.rb
261
262
  homepage: https://www.openware.com