Class: Okcoin::Rest
- Inherits:
-
Object
- Object
- Okcoin::Rest
- Defined in:
- lib/okcoin/rest.rb
Constant Summary collapse
- BASE_URI =
"https://www.okcoin.com/api"
- TIMEOUT =
0.5
Instance Method Summary collapse
- #exchange_rate ⇒ Object
- #futures_cancel(pair:, contract_type:, order_id:) ⇒ Object
- #futures_estimated_price(pair: "btc_usd") ⇒ Object
- #futures_explosive(pair:, contract_type:, status:, current_page:, page_length:) ⇒ Object
- #futures_hold_amount(pair: "btc_usd", contract_type: "this_week") ⇒ Object
- #futures_index(pair: "btc_usd") ⇒ Object
- #futures_kandlestick(pair: "btc_usd", type: "30min", contract_type: "this_week", size: 50, since: nil) ⇒ Object
- #futures_order_info(order_id:, symbol:, contract_type:, status: nil, current_page: nil, page_length: nil) ⇒ Object
- #futures_orderbook(pair: "btc_usd", contract_type: "this_week", items_no: 50, merge: 0) ⇒ Object
- #futures_position(pair:, contract_type:) ⇒ Object
-
#futures_ticker(pair: "btc_usd", contract_type: "this_week") ⇒ Object
Futures Price API.
- #futures_trade(pair:, amount:, type:, contract_type:, match_price:, price: nil, lever_rate: 10) ⇒ Object
- #futures_trades(pair: "btc_usd", contract_type: "this_week") ⇒ Object
- #futures_trades_history(pair: "btc_usd", date:, since:) ⇒ Object
-
#futures_userinfo ⇒ Object
Futures Trading API.
-
#initialize(api_key: nil, secret_key: nil) ⇒ Rest
constructor
A new instance of Rest.
-
#spot_account_records(pair: 'btc_usd', type: 1, current_page: 1, page_length: 50) ⇒ Object
type 0:deposits 1 :withdraw.
- #spot_batch_trade(pair:, type:, orders_data:) ⇒ Object
- #spot_cancel(pair:, order_id:) ⇒ Object
- #spot_cancel_withdraw(pair: 'btc_usd', withdraw_id:) ⇒ Object
- #spot_kandlestick(pair: "btc_usd", type: "30min", size: 50, since: nil) ⇒ Object
- #spot_order_info(pair:, order_id:) ⇒ Object
- #spot_orderbook(pair: "btc_usd", items_no: 50, merge: 0) ⇒ Object
- #spot_orders_info(pair:, type:, order_id:) ⇒ Object
- #spot_swaps_orderbook(pair: "btc_usd") ⇒ Object
-
#spot_ticker(pair: "btc_usd") ⇒ Object
Spot Price API.
- #spot_trade(pair:, type:, price:, amount:) ⇒ Object
- #spot_trades(pair: "btc_usd", since: nil) ⇒ Object
-
#spot_userinfo ⇒ Object
Spot Trading API.
- #spot_withdraw(pair: 'btc_usd', trade_pwd:, withdraw_address:, withdraw_amount:, chargefee: 0.0001) ⇒ Object
- #spot_withdraw_info(pair: 'btc_usd', withdraw_id:) ⇒ Object
Constructor Details
#initialize(api_key: nil, secret_key: nil) ⇒ Rest
Returns a new instance of Rest.
6 7 8 9 |
# File 'lib/okcoin/rest.rb', line 6 def initialize(api_key: nil, secret_key: nil) @api_key = api_key @secret_key = secret_key end |
Instance Method Details
#exchange_rate ⇒ Object
157 158 159 |
# File 'lib/okcoin/rest.rb', line 157 def exchange_rate get_request(url: "/v1/exchange_rate.do") end |
#futures_cancel(pair:, contract_type:, order_id:) ⇒ Object
203 204 205 206 207 208 209 210 211 |
# File 'lib/okcoin/rest.rb', line 203 def futures_cancel(pair:, contract_type:, order_id:) post_data = initial_post_data post_data["symbol"] = pair post_data["contract_type"] = contract_type post_data["order_id"] = order_id post_request post_data: post_data, action: "/v1/future_cancel.do" end |
#futures_estimated_price(pair: "btc_usd") ⇒ Object
161 162 163 164 |
# File 'lib/okcoin/rest.rb', line 161 def futures_estimated_price(pair: "btc_usd") query = { "symbol" => pair } get_request(url: "/v1/future_estimated_price.do", query: query) end |
#futures_explosive(pair:, contract_type:, status:, current_page:, page_length:) ⇒ Object
232 233 234 235 236 237 238 239 240 241 |
# File 'lib/okcoin/rest.rb', line 232 def futures_explosive(pair:, contract_type:, status:, current_page:, page_length:) post_data = initial_post_data post_data["symbol"] = pair post_data["contract_type"] = contract_type post_data["status"] = status post_data["current_page"] = current_page post_data["page_length"] = page_length post_request post_data: post_data, action: "/v1/future_explosive.do" end |
#futures_hold_amount(pair: "btc_usd", contract_type: "this_week") ⇒ Object
176 177 178 179 |
# File 'lib/okcoin/rest.rb', line 176 def futures_hold_amount(pair: "btc_usd", contract_type: "this_week") query = { "symbol" => pair, "contract_type" => contract_type } get_request(url: "/v1/future_hold_amount.do", query: query) end |
#futures_index(pair: "btc_usd") ⇒ Object
152 153 154 155 |
# File 'lib/okcoin/rest.rb', line 152 def futures_index(pair: "btc_usd") query = { "symbol" => pair } get_request(url: "/v1/future_index.do", query: query) end |
#futures_kandlestick(pair: "btc_usd", type: "30min", contract_type: "this_week", size: 50, since: nil) ⇒ Object
171 172 173 174 |
# File 'lib/okcoin/rest.rb', line 171 def futures_kandlestick(pair: "btc_usd", type: "30min", contract_type: "this_week", size: 50, since: nil) query = { "symbol" => pair, "type" => type, "contract_type" => contract_type, "size" => size, "since" => since } get_request(url: "/v1/future_kline.do", query: query) end |
#futures_order_info(order_id:, symbol:, contract_type:, status: nil, current_page: nil, page_length: nil) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/okcoin/rest.rb', line 213 def futures_order_info(order_id:, symbol:, contract_type:, status: nil, current_page: nil, page_length: nil) post_data = initial_post_data post_data["symbol"] = symbol post_data["contract_type"] = contract_type post_data["order_id"] = order_id post_data["status"] = status post_data["current_page"] = current_page post_data["page_length"] = page_length post_request post_data: post_data, action: "/v1/future_order_info.do" end |
#futures_orderbook(pair: "btc_usd", contract_type: "this_week", items_no: 50, merge: 0) ⇒ Object
142 143 144 145 |
# File 'lib/okcoin/rest.rb', line 142 def futures_orderbook(pair: "btc_usd", contract_type: "this_week", items_no: 50, merge: 0) query = { "symbol" => pair, "contract_type" => contract_type, "size" => items_no, "merge" => merge } get_request(url: "/future_depth.do", query: query) end |
#futures_position(pair:, contract_type:) ⇒ Object
225 226 227 228 229 230 |
# File 'lib/okcoin/rest.rb', line 225 def futures_position(pair:, contract_type:) post_data = initial_post_data post_data["symbol"] = pair post_data["contract_type"] = contract_type post_request post_data: post_data, action: "/v1/future_position.do" end |
#futures_ticker(pair: "btc_usd", contract_type: "this_week") ⇒ Object
Futures Price API
137 138 139 140 |
# File 'lib/okcoin/rest.rb', line 137 def futures_ticker(pair: "btc_usd", contract_type: "this_week") query = { "symbol" => pair, "contract_type" => contract_type } get_request(url: "/v1/future_ticker.do", query: query) end |
#futures_trade(pair:, amount:, type:, contract_type:, match_price:, price: nil, lever_rate: 10) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/okcoin/rest.rb', line 188 def futures_trade(pair:, amount:, type:, contract_type:, match_price:, price: nil, lever_rate: 10) post_data = initial_post_data post_data["symbol"] = pair post_data["contract_type"] = contract_type post_data["amount"] = amount post_data["type"] = type post_data["match_price"] = match_price post_data["lever_rate"] = lever_rate post_data["price"] = price if price post_request post_data: post_data, action: "/v1/future_trade.do" end |
#futures_trades(pair: "btc_usd", contract_type: "this_week") ⇒ Object
147 148 149 150 |
# File 'lib/okcoin/rest.rb', line 147 def futures_trades(pair: "btc_usd", contract_type: "this_week") query = { "symbol" => pair, "contract_type" => since } get_request(url: "/v1/trades.do", query: query) end |
#futures_trades_history(pair: "btc_usd", date:, since:) ⇒ Object
166 167 168 169 |
# File 'lib/okcoin/rest.rb', line 166 def futures_trades_history(pair: "btc_usd", date:, since:) query = { "symbol" => pair, "date" => date, "since" => since } get_request(url: "/v1/future_trades_history.do", query: query) end |
#futures_userinfo ⇒ Object
Futures Trading API
183 184 185 186 |
# File 'lib/okcoin/rest.rb', line 183 def futures_userinfo post_data = initial_post_data post_request post_data: post_data, action: "/v1/future_userinfo.do" end |
#spot_account_records(pair: 'btc_usd', type: 1, current_page: 1, page_length: 50) ⇒ Object
type 0:deposits 1 :withdraw
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/okcoin/rest.rb', line 124 def spot_account_records(pair: 'btc_usd', type: 1, current_page: 1, page_length: 50) post_data = initial_post_data post_data['symbol'] = pair post_data['type'] = type post_data['current_page'] = current_page post_data['page_length'] = page_length post_request post_data: post_data, action: "/v1/account_records.do" end |
#spot_batch_trade(pair:, type:, orders_data:) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/okcoin/rest.rb', line 58 def spot_batch_trade(pair:, type:, orders_data:) post_data = initial_post_data post_data["symbol"] = pair post_data["type"] = type post_data["orders_data"] = orders_data post_request post_data: post_data, action: "/v1/batch_trade.do" end |
#spot_cancel(pair:, order_id:) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/okcoin/rest.rb', line 68 def spot_cancel(pair:, order_id:) post_data = initial_post_data post_data["symbol"] = pair post_data["order_id"] = order_id post_request post_data: post_data, action: "/v1/cancel_order.do" end |
#spot_cancel_withdraw(pair: 'btc_usd', withdraw_id:) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/okcoin/rest.rb', line 107 def spot_cancel_withdraw(pair: 'btc_usd', withdraw_id:) post_data = initial_post_data post_data['symbol'] = pair post_data['withdraw_id'] = withdraw_id post_request post_data: post_data, action: "/v1/cancel_withdraw.do" end |
#spot_kandlestick(pair: "btc_usd", type: "30min", size: 50, since: nil) ⇒ Object
30 31 32 33 |
# File 'lib/okcoin/rest.rb', line 30 def spot_kandlestick(pair: "btc_usd", type: "30min", size: 50, since: nil) query = { "symbol" => pair, "type" => type, "size" => size, "since" => since } get_request(url: "/v1/kline.do", query: query) end |
#spot_order_info(pair:, order_id:) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/okcoin/rest.rb', line 77 def spot_order_info(pair:, order_id:) post_data = initial_post_data post_data["symbol"] = pair post_data["order_id"] = order_id post_request post_data: post_data, action: "/v1/order_info.do" end |
#spot_orderbook(pair: "btc_usd", items_no: 50, merge: 0) ⇒ Object
20 21 22 23 |
# File 'lib/okcoin/rest.rb', line 20 def spot_orderbook(pair: "btc_usd", items_no: 50, merge: 0) query = { "symbol" => pair, "size" => items_no, "merge" => merge } get_request(url: "/v1/depth.do", query: query) end |
#spot_orders_info(pair:, type:, order_id:) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/okcoin/rest.rb', line 86 def spot_orders_info(pair:, type:, order_id:) post_data = initial_post_data post_data["symbol"] = pair post_data["order_id"] = order_id post_data["type"] = type post_request post_data: post_data, action: "/v1/orders_info.do" end |
#spot_swaps_orderbook(pair: "btc_usd") ⇒ Object
35 36 37 38 |
# File 'lib/okcoin/rest.rb', line 35 def spot_swaps_orderbook(pair: "btc_usd") query = { "symbol" => pair } get_request(url: "/v1/lend_depth.do", query: query) end |
#spot_ticker(pair: "btc_usd") ⇒ Object
Spot Price API
15 16 17 18 |
# File 'lib/okcoin/rest.rb', line 15 def spot_ticker(pair: "btc_usd") query = { "symbol" => pair } get_request(url: "/v1/ticker.do", query: query) end |
#spot_trade(pair:, type:, price:, amount:) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/okcoin/rest.rb', line 47 def spot_trade(pair:, type:, price:, amount:) post_data = initial_post_data post_data["symbol"] = pair post_data["type"] = type post_data["amount"] = amount post_data["price"] = price post_request post_data: post_data, action: "/v1/trade.do" end |
#spot_trades(pair: "btc_usd", since: nil) ⇒ Object
25 26 27 28 |
# File 'lib/okcoin/rest.rb', line 25 def spot_trades(pair: "btc_usd", since: nil) query = { "symbol" => pair, "since" => since } get_request(url: "/v1/trades.do", query: query) end |
#spot_userinfo ⇒ Object
Spot Trading API
42 43 44 45 |
# File 'lib/okcoin/rest.rb', line 42 def spot_userinfo post_data = initial_post_data post_request post_data: post_data, action: "/v1/userinfo.do" end |
#spot_withdraw(pair: 'btc_usd', trade_pwd:, withdraw_address:, withdraw_amount:, chargefee: 0.0001) ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/okcoin/rest.rb', line 96 def spot_withdraw(pair: 'btc_usd', trade_pwd:, withdraw_address:, withdraw_amount:, chargefee: 0.0001) post_data = initial_post_data post_data['symbol'] = pair post_data['chargefee'] = chargefee post_data['trade_pwd'] = trade_pwd post_data['withdraw_address'] = withdraw_address post_data['withdraw_amount'] = withdraw_amount post_request post_data: post_data, action: "/v1/withdraw.do" end |
#spot_withdraw_info(pair: 'btc_usd', withdraw_id:) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/okcoin/rest.rb', line 115 def spot_withdraw_info(pair: 'btc_usd', withdraw_id:) post_data = initial_post_data post_data['symbol'] = pair post_data['withdraw_id'] = withdraw_id post_request post_data: post_data, action: "/v1/withdraw_info.do" end |