bibox 0.1.3 → 0.1.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: 8986db1d579aa17da50d2dee9f419d81f9e3fb26f63de03fd830241c357be27c
4
- data.tar.gz: b4e51c4e0990379d2906ca5970240e57e9c66439fadd7d4d9883cbab5746c0f7
3
+ metadata.gz: 5e8cf4b3e892dc5fc64f8807f486cb890b5c46d6b3abe2110f604ebb9b0ee796
4
+ data.tar.gz: 22c23c9ef4ae49f24ef93ef9918bd278aaedb85ad617590038f188782e71c08d
5
5
  SHA512:
6
- metadata.gz: 011ab93a271422c1725c07427720fe177a7d5ed56c02133b63eec2c26664f081bc8aea9977cbffa839bcac6281083af9f64734384c50223db00fbd7b9f7979b9
7
- data.tar.gz: 99cf68663a13a8090b204211c4dcce82bb08df89b7cc5ca597d8103606e1e566da346453f4625804653ca039ed257ad94c6c74dfdbe7e6ec034e097e6600dd75
6
+ metadata.gz: 9b38220351d35b3dde46f77daf13b8d030fe922e1f58b0a1353f525755c63413ca8f761201c7741216432913e7d94bdfefcdd2e6b58e73be35d20fd6a523ff03
7
+ data.tar.gz: 742ffce82b24e37ab872cbd9fd8fee74105efc8a039b619cdf5f1856fff0faa99d98928552df8430ccef07dd8541057c63aecd87d1c5fe3783eebc111a518329
data/.gitignore CHANGED
@@ -10,6 +10,9 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
 
13
+ # pry
14
+ .pry_history
15
+
13
16
  credentials.yml
14
17
  .ruby-version
15
- .ruby-gemset
18
+ .ruby-gemset
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bibox (0.1.2)
4
+ bibox (0.1.3)
5
5
  eventmachine (>= 1.2.7)
6
6
  faraday (>= 0.15.4)
7
7
  faraday_middleware (>= 0.13.1)
@@ -12,6 +12,7 @@ GEM
12
12
  specs:
13
13
  addressable (2.6.0)
14
14
  public_suffix (>= 2.0.2, < 4.0)
15
+ coderay (1.1.2)
15
16
  crack (0.4.3)
16
17
  safe_yaml (~> 1.0.0)
17
18
  diff-lcs (1.3)
@@ -24,7 +25,11 @@ GEM
24
25
  eventmachine (>= 0.12.0)
25
26
  websocket-driver (>= 0.5.1)
26
27
  hashdiff (0.3.8)
28
+ method_source (0.9.2)
27
29
  multipart-post (2.0.0)
30
+ pry (0.12.2)
31
+ coderay (~> 1.1.0)
32
+ method_source (~> 0.9.0)
28
33
  public_suffix (3.0.3)
29
34
  rake (10.5.0)
30
35
  rdoc (6.1.1)
@@ -57,6 +62,7 @@ PLATFORMS
57
62
  DEPENDENCIES
58
63
  bibox!
59
64
  bundler (~> 1.16)
65
+ pry (~> 0.12.2)
60
66
  rake (~> 10.0)
61
67
  rdoc (~> 6.0)
62
68
  rspec (~> 3.0)
data/README.md CHANGED
@@ -56,7 +56,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
56
56
 
57
57
  ## Contributing
58
58
 
59
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bibox. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/SebastianJ/bibox. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
60
60
 
61
61
  ## License
62
62
 
@@ -64,4 +64,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
64
64
 
65
65
  ## Code of Conduct
66
66
 
67
- Everyone interacting in the Bibox project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/bibox/blob/master/CODE_OF_CONDUCT.md).
67
+ Everyone interacting in the Bibox project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/SebastianJ/bibox/blob/master/CODE_OF_CONDUCT.md).
@@ -33,4 +33,6 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency "rdoc", "~> 6.0"
34
34
  spec.add_development_dependency "vcr", "~> 4.0"
35
35
  spec.add_development_dependency "webmock", "~> 3.1"
36
+
37
+ spec.add_development_dependency "pry", "~> 0.12.2"
36
38
  end
@@ -23,9 +23,9 @@ end
23
23
  # You can add fixtures and/or initialization code here to make experimenting
24
24
  # with your gem easier. You can also use a different console, if you like.
25
25
 
26
- # (If you use this, don't forget to add pry to your Gemfile!)
27
- # require "pry"
28
- # Pry.start
26
+ require "pry"
27
+ Pry.config.history.file = File.join(__FILE__, "../.pry_history")
28
+ Pry.start
29
29
 
30
- require "irb"
31
- IRB.start(__FILE__)
30
+ #require "irb"
31
+ #IRB.start(__FILE__)
@@ -23,18 +23,25 @@ class WebsocketWrapper
23
23
 
24
24
  def set_callbacks
25
25
  # Subscription callback
26
- self.client.callbacks[:subscribe] = -> { subscribe! }
26
+ self.client.callbacks[:subscribe] = -> { subscribe! }
27
27
 
28
28
  # Received messages callbacks
29
- self.client.callbacks[:trading_pairs] = -> (data) { trading_pairs(data) }
30
- self.client.callbacks[:order_book] = -> (data) { order_book(data) }
31
- self.client.callbacks[:trades] = -> (data) { trades(data) }
32
- self.client.callbacks[:ticker] = -> (data) { ticker(data) }
33
- self.client.callbacks[:klines] = -> (data) { klines(data) }
29
+ self.client.callbacks[:trading_pairs] = -> (data) { trading_pairs(data) }
30
+ self.client.callbacks[:order_book] = -> (data) { order_book(data) }
31
+ self.client.callbacks[:trades] = -> (data) { trades(data) }
32
+ self.client.callbacks[:ticker] = -> (data) { ticker(data) }
33
+ self.client.callbacks[:klines] = -> (data) { klines(data) }
34
+
35
+ self.client.callbacks[:index_markets] = -> (data) { index_markets(data) }
36
+ self.client.callbacks[:contract_price_limits] = -> (data) { contract_price_limits(data) }
34
37
  end
35
38
 
36
39
  def subscribe!(pairs: ["4ETH_USDT"])
37
- #self.client.subscribe_to_trading_pairs!
40
+ self.client.login!
41
+ self.client.subscribe_to_trading_pairs!
42
+ #self.client.subscribe_to_index_markets!
43
+ #self.client.subscribe_to_contract_price_limits!
44
+
38
45
  self.client.subscribe_to_order_book!(pairs: pairs)
39
46
  self.client.subscribe_to_trades!(pairs: pairs)
40
47
  self.client.subscribe_to_ticker!(pairs: pairs)
@@ -66,6 +73,16 @@ class WebsocketWrapper
66
73
  pp data
67
74
  end
68
75
 
76
+ def index_markets(data)
77
+ puts "\nReceived index markets message!"
78
+ pp data
79
+ end
80
+
81
+ def contract_price_limits(data)
82
+ puts "\nReceived contract price limits message!"
83
+ pp data
84
+ end
85
+
69
86
  end
70
87
 
71
88
  WebsocketWrapper.new.run!
@@ -36,6 +36,7 @@ require "bibox/models/asset"
36
36
  require "bibox/models/user_assets"
37
37
  require "bibox/models/transfer"
38
38
  require "bibox/models/bill"
39
+ require "bibox/models/contract"
39
40
 
40
41
  require "bibox/rest/public/ticker"
41
42
  require "bibox/rest/public/pairs"
@@ -49,6 +50,10 @@ require "bibox/rest/private/assets"
49
50
  require "bibox/rest/private/transfers"
50
51
  require "bibox/rest/private/bills"
51
52
 
53
+ require "bibox/rest/private/contracts/general"
54
+ require "bibox/rest/private/contracts/assets"
55
+ require "bibox/rest/private/contracts/orders"
56
+
52
57
  require "bibox/rest/errors"
53
58
  require "bibox/rest/client"
54
59
 
@@ -0,0 +1,20 @@
1
+ module Bibox
2
+ module Models
3
+ class Contract < Base
4
+ MAPPING = {
5
+ id: :integer,
6
+ pair: :string,
7
+ value: :float,
8
+ coin_symbol: :string,
9
+
10
+ offset_normal: :float,
11
+ offset_short: :float,
12
+ offset_long: :float,
13
+ normal_dx: :float,
14
+
15
+ created_at: :datetime,
16
+ updated_at: :datetime
17
+ }
18
+ end
19
+ end
20
+ end
@@ -8,8 +8,8 @@ module Bibox
8
8
  coin_symbol: :string,
9
9
  confirm_count: :string,
10
10
  amount: :float,
11
- updated_at: :datetime,
12
- created_at: :datetime,
11
+ updated_at: :time,
12
+ created_at: :time,
13
13
  url: :string,
14
14
  icon_url: :string,
15
15
  status: {enum: {1 => :pending, 2 => :success, 3 => :failed}},
@@ -21,6 +21,10 @@ module Bibox
21
21
  include ::Bibox::Rest::Private::Assets
22
22
  include ::Bibox::Rest::Private::Transfers
23
23
  include ::Bibox::Rest::Private::Bills
24
+
25
+ include ::Bibox::Rest::Private::Contracts::General
26
+ include ::Bibox::Rest::Private::Contracts::Assets
27
+ include ::Bibox::Rest::Private::Contracts::Orders
24
28
 
25
29
  def configured?
26
30
  !self.configuration.key.to_s.empty? && !self.configuration.secret.to_s.empty?
@@ -0,0 +1,24 @@
1
+ module Bibox
2
+ module Rest
3
+ module Private
4
+ module Contracts
5
+ module Assets
6
+
7
+ def contract_assets(coin_symbol: "USDT", options: {})
8
+ payload = [
9
+ {
10
+ cmd: "query/assets",
11
+ body: {
12
+ coin_symbol: coin_symbol
13
+ }
14
+ }
15
+ ]
16
+
17
+ response = parse(post("/cquery", data: payload, options: options))&.fetch("result", [])&.first&.fetch("result", [])
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ module Bibox
2
+ module Rest
3
+ module Private
4
+ module Contracts
5
+ module General
6
+ def contract_values(options: {})
7
+ payload = [
8
+ {
9
+ cmd: "query/contractValue",
10
+ body: {}
11
+ }
12
+ ]
13
+
14
+ response = post("/cquery", data: payload, options: options)#&.fetch("result", [])&.first&.fetch("result", [])
15
+
16
+ raise response.inspect
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ module Bibox
2
+ module Rest
3
+ module Private
4
+ module Contracts
5
+ module Orders
6
+
7
+ def contract_orders(pair:, options: {})
8
+ payload = [
9
+ {
10
+ cmd: "query/order",
11
+ body: {
12
+ pair: pair
13
+ }
14
+ }
15
+ ]
16
+
17
+ response = parse(post("/cquery", data: payload, options: options))&.fetch("result", [])&.first&.fetch("result", [])
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,7 +1,12 @@
1
1
  module Bibox
2
2
  class Utilities
3
3
 
4
- class << self
4
+ class << self
5
+
6
+ def decode_and_inflate(data)
7
+ Zlib::GzipReader.new(StringIO.new(Base64.decode64(data))).read
8
+ end
9
+
5
10
  def convert_value(value, type, use_ms_for_time: true)
6
11
  if type.is_a?(Symbol)
7
12
  return case type
@@ -1,3 +1,3 @@
1
1
  module Bibox
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -10,21 +10,27 @@ module Bibox
10
10
  self.keepalive = options.fetch(:keepalive, false)
11
11
 
12
12
  self.matchers = {
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>.*)$/
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
+
19
+ index_markets: /\d?[A-Z]+_[A-Z]+_indexMarket/,
20
+ contract_price_limits: /\d?[A-Z]+_[A-Z]+_contractPriceLimit$/,
18
21
  }
19
22
 
20
23
  self.callbacks = {
21
- subscribe: -> { subscribe! },
22
- message: -> (data) { message(data) },
23
- trading_pairs: -> (data) { nil },
24
- order_book: -> (data) { nil },
25
- trades: -> (data) { nil },
26
- ticker: -> (data) { nil },
27
- klines: -> (data) { nil },
24
+ subscribe: -> { subscribe! },
25
+ message: -> (data) { message(data) },
26
+ trading_pairs: -> (data) { nil },
27
+ order_book: -> (data) { nil },
28
+ trades: -> (data) { nil },
29
+ ticker: -> (data) { nil },
30
+ klines: -> (data) { nil },
31
+
32
+ index_markets: -> (data) { nil },
33
+ contract_price_limits: -> (data) { nil },
28
34
  }
29
35
  end
30
36
 
@@ -56,10 +62,22 @@ module Bibox
56
62
  self.socket.onerror = method(:on_error)
57
63
  end
58
64
 
65
+ def login!
66
+ subscribe_to! channel_name("ALL_ALL_login")
67
+ end
68
+
59
69
  def subscribe_to_trading_pairs!
60
70
  subscribe_to! channel_name("ALL_ALL_market")
61
71
  end
62
72
 
73
+ def subscribe_to_index_markets!
74
+ subscribe_to! channel_name("ALL_ALL_indexMarket")
75
+ end
76
+
77
+ def subscribe_to_contract_price_limits!
78
+ subscribe_to! channel_name("ALL_ALL_contractPriceLimit")
79
+ end
80
+
63
81
  def subscribe_to_order_book!(pairs: [])
64
82
  pairs&.each { |pair| subscribe_to! channel_name("#{pair}_depth") }
65
83
  end
@@ -105,6 +123,10 @@ module Bibox
105
123
  period = channel.match(self.matchers[:klines])&.[](:period)
106
124
  data.merge!("period" => period) if !period.to_s.empty?
107
125
  self.callbacks[:klines].call(data)
126
+ when self.matchers[:index_markets]
127
+ self.callbacks[:index_markets].call(data)
128
+ when self.matchers[:contract_price_limits]
129
+ self.callbacks[:contract_price_limits].call(data)
108
130
  end
109
131
  end
110
132
 
@@ -116,10 +138,6 @@ module Bibox
116
138
  return data
117
139
  end
118
140
 
119
- def decode_and_inflate(data)
120
- Zlib::GzipReader.new(StringIO.new(Base64.decode64(data))).read
121
- end
122
-
123
141
  def send_pong(timestamp)
124
142
  self.socket.send({pong: timestamp}.to_json)
125
143
  end
@@ -130,7 +148,7 @@ module Bibox
130
148
 
131
149
  def on_message(event)
132
150
  parsed = parse(event.data)
133
-
151
+
134
152
  if parsed
135
153
  if parsed.is_a?(Hash)
136
154
  send_pong(parsed["ping"]) unless parsed.fetch("ping", nil).to_s.empty?
@@ -141,7 +159,7 @@ module Bibox
141
159
  is_binary = parsed.fetch("binary", nil)&.eql?("1")
142
160
 
143
161
  if is_binary && !parsed.fetch("data", nil).to_s.empty?
144
- parsed["data"] = parse(decode_and_inflate(parsed["data"]))
162
+ parsed["data"] = parse(Bibox::Utilities.decode_and_inflate(parsed["data"]))
145
163
  end
146
164
 
147
165
  self.callbacks[:message].call(parsed)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bibox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Johnsson
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '3.1'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 0.12.2
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 0.12.2
153
167
  description: Ruby REST + Websocket clients for crypto currency exchange Bibox's API
154
168
  email:
155
169
  - sebastian.johnsson@gmail.com
@@ -182,6 +196,7 @@ files:
182
196
  - lib/bibox/models/asset.rb
183
197
  - lib/bibox/models/base.rb
184
198
  - lib/bibox/models/bill.rb
199
+ - lib/bibox/models/contract.rb
185
200
  - lib/bibox/models/ohlcv.rb
186
201
  - lib/bibox/models/order.rb
187
202
  - lib/bibox/models/order_book.rb
@@ -194,6 +209,9 @@ files:
194
209
  - lib/bibox/rest/errors.rb
195
210
  - lib/bibox/rest/private/assets.rb
196
211
  - lib/bibox/rest/private/bills.rb
212
+ - lib/bibox/rest/private/contracts/assets.rb
213
+ - lib/bibox/rest/private/contracts/general.rb
214
+ - lib/bibox/rest/private/contracts/orders.rb
197
215
  - lib/bibox/rest/private/order_book.rb
198
216
  - lib/bibox/rest/private/orders.rb
199
217
  - lib/bibox/rest/private/transfers.rb