bibox 0.1.2 → 0.1.3

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: 85887e7aed5ce9bacd8c655939c6f291b843831909caf13521163e00d9258b0d
4
- data.tar.gz: 1fce3879a1b05c631eb4410340f72ff295a84e80c1ab34c567e036884db077e5
3
+ metadata.gz: 8986db1d579aa17da50d2dee9f419d81f9e3fb26f63de03fd830241c357be27c
4
+ data.tar.gz: b4e51c4e0990379d2906ca5970240e57e9c66439fadd7d4d9883cbab5746c0f7
5
5
  SHA512:
6
- metadata.gz: 703cc058445847ba99d19f572677672488dea9c798ecfc5118a674af89795b4fda159d475cad060414a27f9d6678046d36e4dcc089381c43b5664187cd5fdc2a
7
- data.tar.gz: ccdabef258bd42cfb8768d1c8e1c2261a988dbef04c6b850a40ae413d193633d5873819659efad3f1cf20d2fd6d82b0b4af4c4aaec648028d405158a9f72b402
6
+ metadata.gz: 011ab93a271422c1725c07427720fe177a7d5ed56c02133b63eec2c26664f081bc8aea9977cbffa839bcac6281083af9f64734384c50223db00fbd7b9f7979b9
7
+ data.tar.gz: 99cf68663a13a8090b204211c4dcce82bb08df89b7cc5ca597d8103606e1e566da346453f4625804653ca039ed257ad94c6c74dfdbe7e6ec034e097e6600dd75
@@ -2,48 +2,48 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  bibox (0.1.2)
5
- eventmachine (>= 1.2.5)
6
- faraday (>= 0.13)
7
- faraday_middleware (>= 0.12.2)
5
+ eventmachine (>= 1.2.7)
6
+ faraday (>= 0.15.4)
7
+ faraday_middleware (>= 0.13.1)
8
8
  faye-websocket (>= 0.10.7)
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- addressable (2.5.2)
13
+ addressable (2.6.0)
14
14
  public_suffix (>= 2.0.2, < 4.0)
15
15
  crack (0.4.3)
16
16
  safe_yaml (~> 1.0.0)
17
17
  diff-lcs (1.3)
18
- eventmachine (1.2.5)
19
- faraday (0.14.0)
18
+ eventmachine (1.2.7)
19
+ faraday (0.15.4)
20
20
  multipart-post (>= 1.2, < 3)
21
- faraday_middleware (0.12.2)
21
+ faraday_middleware (0.13.1)
22
22
  faraday (>= 0.7.4, < 1.0)
23
23
  faye-websocket (0.10.7)
24
24
  eventmachine (>= 0.12.0)
25
25
  websocket-driver (>= 0.5.1)
26
- hashdiff (0.3.7)
26
+ hashdiff (0.3.8)
27
27
  multipart-post (2.0.0)
28
- public_suffix (3.0.1)
28
+ public_suffix (3.0.3)
29
29
  rake (10.5.0)
30
- rdoc (6.0.1)
31
- rspec (3.7.0)
32
- rspec-core (~> 3.7.0)
33
- rspec-expectations (~> 3.7.0)
34
- rspec-mocks (~> 3.7.0)
35
- rspec-core (3.7.1)
36
- rspec-support (~> 3.7.0)
37
- rspec-expectations (3.7.0)
30
+ rdoc (6.1.1)
31
+ rspec (3.8.0)
32
+ rspec-core (~> 3.8.0)
33
+ rspec-expectations (~> 3.8.0)
34
+ rspec-mocks (~> 3.8.0)
35
+ rspec-core (3.8.0)
36
+ rspec-support (~> 3.8.0)
37
+ rspec-expectations (3.8.2)
38
38
  diff-lcs (>= 1.2.0, < 2.0)
39
- rspec-support (~> 3.7.0)
40
- rspec-mocks (3.7.0)
39
+ rspec-support (~> 3.8.0)
40
+ rspec-mocks (3.8.0)
41
41
  diff-lcs (>= 1.2.0, < 2.0)
42
- rspec-support (~> 3.7.0)
43
- rspec-support (3.7.1)
44
- safe_yaml (1.0.4)
42
+ rspec-support (~> 3.8.0)
43
+ rspec-support (3.8.0)
44
+ safe_yaml (1.0.5)
45
45
  vcr (4.0.0)
46
- webmock (3.3.0)
46
+ webmock (3.5.1)
47
47
  addressable (>= 2.3.6)
48
48
  crack (>= 0.3.2)
49
49
  hashdiff
@@ -64,4 +64,4 @@ DEPENDENCIES
64
64
  webmock (~> 3.1)
65
65
 
66
66
  BUNDLED WITH
67
- 1.16.1
67
+ 1.17.2
@@ -21,11 +21,11 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_dependency "faraday", ">= 0.13"
25
- spec.add_dependency "faraday_middleware", ">= 0.12.2"
24
+ spec.add_dependency "faraday", ">= 0.15.4"
25
+ spec.add_dependency "faraday_middleware", ">= 0.13.1"
26
26
 
27
27
  spec.add_dependency "faye-websocket", ">= 0.10.7"
28
- spec.add_dependency "eventmachine", ">= 1.2.5"
28
+ spec.add_dependency "eventmachine", ">= 1.2.7"
29
29
 
30
30
  spec.add_development_dependency "bundler", "~> 1.16"
31
31
  spec.add_development_dependency "rake", "~> 10.0"
@@ -33,8 +33,8 @@ class WebsocketWrapper
33
33
  self.client.callbacks[:klines] = -> (data) { klines(data) }
34
34
  end
35
35
 
36
- def subscribe!(pairs: ["BIX_ETH", "BIX_BTC"])
37
- self.client.subscribe_to_trading_pairs!
36
+ def subscribe!(pairs: ["4ETH_USDT"])
37
+ #self.client.subscribe_to_trading_pairs!
38
38
  self.client.subscribe_to_order_book!(pairs: pairs)
39
39
  self.client.subscribe_to_trades!(pairs: pairs)
40
40
  self.client.subscribe_to_ticker!(pairs: pairs)
@@ -7,6 +7,11 @@ require "openssl"
7
7
  require "faye/websocket"
8
8
  require "eventmachine"
9
9
 
10
+ # Parsing / Decoding
11
+ require "zlib"
12
+ require "stringio"
13
+ require "base64"
14
+
10
15
  # Shared
11
16
  require "json"
12
17
  require "date"
@@ -1,3 +1,3 @@
1
1
  module Bibox
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  module Bibox
2
2
  module Websocket
3
- # Websocket client for Coinbase Exchange
3
+ # Websocket client for Bibox
4
4
  class Client
5
5
  attr_accessor :url, :prefix, :keepalive, :socket, :reactor_owner, :matchers, :callbacks
6
6
 
@@ -10,11 +10,11 @@ module Bibox
10
10
  self.keepalive = options.fetch(:keepalive, false)
11
11
 
12
12
  self.matchers = {
13
- trading_pairs: /[A-Z]{3}_[A-Z]{3}_market/,
14
- order_book: /[A-Z]{3}_[A-Z]{3}_depth$/,
15
- trades: /[A-Z]{3}_[A-Z]{3}_deals$/,
16
- ticker: /[A-Z]{3}_[A-Z]{3}_ticker$/,
17
- klines: /[A-Z]{3}_[A-Z]{3}_kline_(?<period>.*)$/
13
+ trading_pairs: /\d?[A-Z]+_[A-Z]+_market/,
14
+ order_book: /\d?[A-Z]+_[A-Z]+_depth$/,
15
+ trades: /\d?[A-Z]+_[A-Z]+_deals$/,
16
+ ticker: /\d?[A-Z]+_[A-Z]+_ticker$/,
17
+ klines: /\d?[A-Z]+_[A-Z]+_kline_(?<period>.*)$/
18
18
  }
19
19
 
20
20
  self.callbacks = {
@@ -55,14 +55,6 @@ module Bibox
55
55
  self.socket.onclose = method(:on_close)
56
56
  self.socket.onerror = method(:on_error)
57
57
  end
58
-
59
- def subscribe!
60
- subscribe_to_trading_pairs!
61
- subscribe_to_order_book!(pairs: ["BIX_BTC", "BIX_ETH"])
62
- subscribe_to_trades!(pair: ["BIX_BTC", "BIX_ETH"])
63
- subscribe_to_ticker!(pair: ["BIX_BTC", "BIX_ETH"])
64
- subscribe_to_klines!(pair: ["BIX_BTC", "BIX_ETH"], periods: ["5min"])
65
- end
66
58
 
67
59
  def subscribe_to_trading_pairs!
68
60
  subscribe_to! channel_name("ALL_ALL_market")
@@ -123,13 +115,37 @@ module Bibox
123
115
  rescue => err
124
116
  return data
125
117
  end
118
+
119
+ def decode_and_inflate(data)
120
+ Zlib::GzipReader.new(StringIO.new(Base64.decode64(data))).read
121
+ end
122
+
123
+ def send_pong(timestamp)
124
+ self.socket.send({pong: timestamp}.to_json)
125
+ end
126
126
 
127
127
  def on_open(_event)
128
128
  self.callbacks[:subscribe].call
129
129
  end
130
130
 
131
131
  def on_message(event)
132
- self.callbacks[:message].call(parse(event.data)&.first)
132
+ parsed = parse(event.data)
133
+
134
+ if parsed
135
+ if parsed.is_a?(Hash)
136
+ send_pong(parsed["ping"]) unless parsed.fetch("ping", nil).to_s.empty?
137
+ elsif parsed.is_a?(Array)
138
+ parsed = parsed.first
139
+ end
140
+
141
+ is_binary = parsed.fetch("binary", nil)&.eql?("1")
142
+
143
+ if is_binary && !parsed.fetch("data", nil).to_s.empty?
144
+ parsed["data"] = parse(decode_and_inflate(parsed["data"]))
145
+ end
146
+
147
+ self.callbacks[:message].call(parsed)
148
+ end
133
149
  end
134
150
 
135
151
  def on_close(_event)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bibox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Johnsson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-08 00:00:00.000000000 Z
11
+ date: 2019-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0.13'
19
+ version: 0.15.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0.13'
26
+ version: 0.15.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: faraday_middleware
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.12.2
33
+ version: 0.13.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.12.2
40
+ version: 0.13.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: faye-websocket
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 1.2.5
61
+ version: 1.2.7
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: 1.2.5
68
+ version: 1.2.7
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -224,8 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
224
  - !ruby/object:Gem::Version
225
225
  version: '0'
226
226
  requirements: []
227
- rubyforge_project:
228
- rubygems_version: 2.7.4
227
+ rubygems_version: 3.0.1
229
228
  signing_key:
230
229
  specification_version: 4
231
230
  summary: Ruby REST + Websocket clients for Bibox's API'