okcoin-ruby 0.0.5 → 0.0.6

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
  SHA1:
3
- metadata.gz: 830387957a835f4427a3c83b5b9a51b540147328
4
- data.tar.gz: 7716a827c6d2fa7d61ac8ad47cd9a9a1028d6cb4
3
+ metadata.gz: b23eec84532c011d040c6fa7728ab5efa39b8c18
4
+ data.tar.gz: f8783b2a32993bc2233aceffff7dfd3c127d65e9
5
5
  SHA512:
6
- metadata.gz: 07fbdae8dfb02cea01f431ce8f115cda92e5a445abb847eaa166ef5790f8fdf139d80cac712f5691d7fccd7ed9927580950171db6b41ce4d9d3f4c9b84982f5f
7
- data.tar.gz: cccbd09133e4ccc261f76bb6abf459db736062540b5aa0050574b57414606c61cf48df42fcd869bee316aebb54d70d2eeb97579296f61a98b6d5a147e3bbf6fb
6
+ metadata.gz: 27a39fe575d4fb49380fb79df027636dfef5c15d89bd56ddf681fa2fb195ed0094fd7e206102710ca63d7beaf18a0995c8342f64e681e9e5e533716bd3eefff5
7
+ data.tar.gz: 346ca36c63f846445c6dfba035ca206ce469900a0674a018904a4bfaa900504dbb84123078916c0d1d94e430f919893e124e1308f4ed5da290f1d98964d3f0e5
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ *.gem
data/README.md CHANGED
@@ -12,7 +12,7 @@ BTC 15y2a3FKLW89qoDniDMRwsdhrZeHJA1Det
12
12
  Add these gems into your Gemfile:
13
13
 
14
14
  ```ruby
15
- gem 'okcoin-ruby'
15
+ gem 'okcoin-ruby', '~> 0.0.6'
16
16
  gem 'celluloid-websocket-client', :github => 'ilyacherevkov/celluloid-websocket-client'
17
17
  ```
18
18
 
@@ -30,6 +30,8 @@ okcoin = Okcoin::Rest.new api_key: ENV['OKCOIN_APIKEY'], secret_key: ENV['OKCOIN
30
30
 
31
31
  Make requests
32
32
 
33
+ [See OKCoin REST API reference](https://www.okcoin.com/about/rest_api.do)
34
+
33
35
  Spot Price
34
36
  ```ruby
35
37
  okcoin.spot_ticker(pair: "btc_usd")
@@ -43,11 +45,26 @@ Spot Trade
43
45
  ```ruby
44
46
  okcoin.spot_userinfo
45
47
  okcoin.spot_trade(pair: "btc_usd", type: "buy", price:240, amount:1)
48
+ # max 5 orders in spot_batch_trade per request
49
+ okcoin.batch_spot_trade(pair: "btc_usd", type: "buy", orders_data: [{price:3,amount:5,type:'sell'},{price:3,amount:3,type:'buy'},{price:3,amount:3}])
50
+ # max 3 order_ids in spot_cancel per request
51
+ okcoin.spot_cancel(pair: "btc_usd", order_id: "1234, 2345, 3456")
52
+ # -1 returns all unfilled orders, otherwise return the order specified
53
+ okcoin.spot_order_info(pair: "btc_usd", order_id: -1)
54
+ # max 50 orders per request
55
+ spot_orders_info(pair: "btc_usd", type: 0, order_id: "12345, 2345, 3456")
46
56
  ```
47
57
 
48
58
  Futures Price
49
59
  ```ruby
50
- okcoin.futures_orderbook(pair: "btc_usd", contract: "this_week", items_no: 50)
60
+ okcoin.futures_orderbook(pair: "btc_usd", contract_type: "this_week", items_no: 50, merge: 0)
61
+ okcoin.futures_trades(pair: "btc_usd", contract_type: "this_week")
62
+ okcoin.futures_index(pair: "btc_usd")
63
+ okcoin.exchange_rate
64
+ okcoin.futures_estimated_price(pair: "btc_usd")
65
+ okcoin.futures_trades_history(pair: "btc_usd", date: nil, since: nil)
66
+ okcoin.futures_kandlestick(pair: "btc_usd", type: "30min", contract_type: "this_week", size: 50, since: nil)
67
+ okcoin.futures_hold_amount(pair: "btc_usd", contract_type: "this_week")
51
68
  ```
52
69
 
53
70
  Futures Trade
@@ -57,10 +74,12 @@ okcoin.futures_trade(pair: "btc_usd", amount: 1, type: 1, contract_type: "this_w
57
74
  okcoin.futures_cancel(pair: "btc_usd", contract_type: "this_week", order_id: 12345)
58
75
  okcoin.futures_order_info(order_id: 12345, symbol: "btc_usd", contract_type: "this_week", status: nil, current_page: nil, page_length: nil)
59
76
  okcoin.futures_position(pair: "btc_usd", contract_type: "this_week")
77
+ okcoin.futures_explosive(pair: "btc_usd", contract_type: "this_week", status: 0, current_page: 1, page_length: 50)
78
+ # status - 0: open liquidation orders of last 7 days; 1: filled liquidation orders of last 7 days
60
79
  ```
61
80
 
62
81
  ### 2. WebSocket Example
63
-
82
+ [See OKCoin WebSocket API reference](https://www.okcoin.com/about/ws_api.do)
64
83
  ```ruby
65
84
  okcoin = Okcoin::WS.new api_key: ENV['OKCOIN_APIKEY'], secret_key: ENV['OKCOIN_SECRET']
66
85
  okcoin.userinfo
@@ -1,3 +1,4 @@
1
+ require 'json'
1
2
  require 'curb'
2
3
  require 'celluloid/websocket/client'
3
4
  require 'okcoin/rest'
@@ -9,7 +9,9 @@ class Okcoin
9
9
  end
10
10
 
11
11
  public
12
+
12
13
  # Spot Price API
14
+
13
15
  def spot_ticker(pair: "btc_usd")
14
16
  query = { "symbol" => pair }
15
17
  get_request(url: "/v1/ticker.do", query: query)
@@ -44,7 +46,7 @@ class Okcoin
44
46
 
45
47
  def spot_trade(pair:, type:, price:, amount:)
46
48
  post_data = initial_post_data
47
-
49
+
48
50
  post_data["symbol"] = pair
49
51
  post_data["type"] = type
50
52
  post_data["amount"] = amount
@@ -53,13 +55,131 @@ class Okcoin
53
55
  post_request post_data: post_data, action: "/v1/trade.do"
54
56
  end
55
57
 
58
+ def spot_batch_trade(pair:, type:, orders_data:)
59
+ post_data = initial_post_data
60
+
61
+ post_data["symbol"] = pair
62
+ post_data["type"] = type
63
+ post_data["orders_data"] = orders_data
64
+
65
+ post_request post_data: post_data, action: "/v1/batch_trade.do"
66
+ end
67
+
68
+ def spot_cancel(pair:, order_id:)
69
+ post_data = initial_post_data
70
+
71
+ post_data["symbol"] = pair
72
+ post_data["order_id"] = order_id
73
+
74
+ post_request post_data: post_data, action: "/v1/cancel_order.do"
75
+ end
76
+
77
+ def spot_order_info(pair:, order_id:)
78
+ post_data = initial_post_data
79
+
80
+ post_data["symbol"] = pair
81
+ post_data["order_id"] = order_id
82
+
83
+ post_request post_data: post_data, action: "/v1/order_info.do"
84
+ end
85
+
86
+ def spot_orders_info(pair:, type:, order_id:)
87
+ post_data = initial_post_data
88
+
89
+ post_data["symbol"] = pair
90
+ post_data["order_id"] = order_id
91
+ post_data["type"] = type
92
+
93
+ post_request post_data: post_data, action: "/v1/orders_info.do"
94
+ end
95
+
96
+ def spot_withdraw(pair: 'btc_usd', trade_pwd:, withdraw_address:, withdraw_amount:, chargefee: 0.0001)
97
+ post_data = initial_post_data
98
+
99
+ post_data['symbol'] = pair
100
+ post_data['chargefee'] = chargefee
101
+ post_data['trade_pwd'] = trade_pwd
102
+ post_data['withdraw_address'] = withdraw_address
103
+ post_data['withdraw_amount'] = withdraw_amount
104
+ post_request post_data: post_data, action: "/v1/withdraw.do"
105
+ end
106
+
107
+ def spot_cancel_withdraw(pair: 'btc_usd', withdraw_id:)
108
+ post_data = initial_post_data
109
+
110
+ post_data['symbol'] = pair
111
+ post_data['withdraw_id'] = withdraw_id
112
+ post_request post_data: post_data, action: "/v1/cancel_withdraw.do"
113
+ end
114
+
115
+ def spot_withdraw_info(pair: 'btc_usd', withdraw_id:)
116
+ post_data = initial_post_data
117
+
118
+ post_data['symbol'] = pair
119
+ post_data['withdraw_id'] = withdraw_id
120
+ post_request post_data: post_data, action: "/v1/withdraw_info.do"
121
+ end
122
+
123
+ # type 0:deposits 1 :withdraw
124
+ def spot_account_records(pair: 'btc_usd', type: 1, current_page: 1, page_length: 50)
125
+ post_data = initial_post_data
126
+
127
+ post_data['symbol'] = pair
128
+ post_data['type'] = type
129
+ post_data['current_page'] = current_page
130
+ post_data['page_length'] = page_length
131
+
132
+ post_request post_data: post_data, action: "/v1/account_records.do"
133
+ end
134
+
56
135
  # Futures Price API
57
- def futures_orderbook(pair:, contract:, items_no: 50)
58
- query = { "symbol" => pair, "contractType" => contract, "size" => items_no }
136
+
137
+ def futures_ticker(pair: "btc_usd", contract_type: "this_week")
138
+ query = { "symbol" => pair, "contract_type" => contract_type }
139
+ get_request(url: "/v1/future_ticker.do", query: query)
140
+ end
141
+
142
+ def futures_orderbook(pair: "btc_usd", contract_type: "this_week", items_no: 50, merge: 0)
143
+ query = { "symbol" => pair, "contract_type" => contract_type, "size" => items_no, "merge" => merge }
59
144
  get_request(url: "/future_depth.do", query: query)
60
145
  end
61
146
 
147
+ def futures_trades(pair: "btc_usd", contract_type: "this_week")
148
+ query = { "symbol" => pair, "contract_type" => since }
149
+ get_request(url: "/v1/trades.do", query: query)
150
+ end
151
+
152
+ def futures_index(pair: "btc_usd")
153
+ query = { "symbol" => pair }
154
+ get_request(url: "/v1/future_index.do", query: query)
155
+ end
156
+
157
+ def exchange_rate
158
+ get_request(url: "/v1/exchange_rate.do")
159
+ end
160
+
161
+ def futures_estimated_price(pair: "btc_usd")
162
+ query = { "symbol" => pair }
163
+ get_request(url: "/v1/future_estimated_price.do", query: query)
164
+ end
165
+
166
+ def futures_trades_history(pair: "btc_usd", date:, since:)
167
+ query = { "symbol" => pair, "date" => date, "since" => since }
168
+ get_request(url: "/v1/future_trades_history.do", query: query)
169
+ end
170
+
171
+ def futures_kandlestick(pair: "btc_usd", type: "30min", contract_type: "this_week", size: 50, since: nil)
172
+ query = { "symbol" => pair, "type" => type, "contract_type" => contract_type, "size" => size, "since" => since }
173
+ get_request(url: "/v1/future_kline.do", query: query)
174
+ end
175
+
176
+ def futures_hold_amount(pair: "btc_usd", contract_type: "this_week")
177
+ query = { "symbol" => pair, "contract_type" => contract_type }
178
+ get_request(url: "/v1/future_hold_amount.do", query: query)
179
+ end
180
+
62
181
  # Futures Trading API
182
+
63
183
  def futures_userinfo
64
184
  post_data = initial_post_data
65
185
  post_request post_data: post_data, action: "/v1/future_userinfo.do"
@@ -109,13 +229,28 @@ class Okcoin
109
229
  post_request post_data: post_data, action: "/v1/future_position.do"
110
230
  end
111
231
 
232
+ def futures_explosive(pair:, contract_type:, status:, current_page:, page_length:)
233
+ post_data = initial_post_data
234
+ post_data["symbol"] = pair
235
+ post_data["contract_type"] = contract_type
236
+ post_data["status"] = status
237
+ post_data["current_page"] = current_page
238
+ post_data["page_length"] = page_length
239
+
240
+ post_request post_data: post_data, action: "/v1/future_explosive.do"
241
+ end
242
+
112
243
  private
113
244
 
245
+ def logger
246
+ @logger ||= Object.const_defined?(:Rails) ? Rails.logger : Logger.new(STDOUT)
247
+ end
248
+
114
249
  def handle_timeouts
115
250
  begin
116
251
  yield
117
252
  rescue => ex
118
- Rails.logger.info "Okcoin: An error of type #{ex.class} happened, message is #{ex.message}. Retrying..."
253
+ logger.info("Okcoin: An error of type #{ex.class} happened, message is #{ex.message}. Retrying...")
119
254
  sleep TIMEOUT
120
255
  retry
121
256
  end
@@ -1,3 +1,3 @@
1
1
  class Okcoin
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: okcoin-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Cherevkov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-24 00:00:00.000000000 Z
11
+ date: 2016-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 2.2.2
106
+ rubygems_version: 2.4.8
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: A ruby library for okcoin.com