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
- #futures_cancel(pair:, contract_type:, order_id:) ⇒ Object
- #futures_order_info(order_id:, symbol:, contract_type:, status: nil, current_page: nil, page_length: nil) ⇒ Object
-
#futures_orderbook(pair:, contract:, items_no: 50) ⇒ Object
Futures Price API.
- #futures_position(pair:, contract_type:) ⇒ Object
- #futures_trade(pair:, amount:, type:, contract_type:, match_price:, price: nil, lever_rate: 10) ⇒ Object
-
#futures_userinfo ⇒ Object
Futures Trading API.
-
#initialize(api_key: nil, secret_key: nil) ⇒ Rest
constructor
A new instance of Rest.
- #spot_kandlestick(pair: "btc_usd", type: "30min", size: 50, since: nil) ⇒ Object
- #spot_orderbook(pair: "btc_usd", items_no: 50, merge: 0) ⇒ 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.
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
#futures_cancel(pair:, contract_type:, order_id:) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/okcoin/rest.rb', line 83 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_order_info(order_id:, symbol:, contract_type:, status: nil, current_page: nil, page_length: nil) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/okcoin/rest.rb', line 93 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:, contract:, items_no: 50) ⇒ Object
Futures Price API
57 58 59 60 |
# File 'lib/okcoin/rest.rb', line 57 def futures_orderbook(pair:, contract:, items_no: 50) query = { "symbol" => pair, "contractType" => contract, "size" => items_no } get_request(url: "/future_depth.do", query: query) end |
#futures_position(pair:, contract_type:) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/okcoin/rest.rb', line 105 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_trade(pair:, amount:, type:, contract_type:, match_price:, price: nil, lever_rate: 10) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/okcoin/rest.rb', line 68 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_userinfo ⇒ Object
Futures Trading API
63 64 65 66 |
# File 'lib/okcoin/rest.rb', line 63 def futures_userinfo post_data = initial_post_data post_request post_data: post_data, action: "/v1/future_userinfo.do" end |
#spot_kandlestick(pair: "btc_usd", type: "30min", size: 50, since: nil) ⇒ Object
28 29 30 31 |
# File 'lib/okcoin/rest.rb', line 28 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_orderbook(pair: "btc_usd", items_no: 50, merge: 0) ⇒ Object
18 19 20 21 |
# File 'lib/okcoin/rest.rb', line 18 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_swaps_orderbook(pair: "btc_usd") ⇒ Object
33 34 35 36 |
# File 'lib/okcoin/rest.rb', line 33 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
13 14 15 16 |
# File 'lib/okcoin/rest.rb', line 13 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
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/okcoin/rest.rb', line 45 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
23 24 25 26 |
# File 'lib/okcoin/rest.rb', line 23 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
40 41 42 43 |
# File 'lib/okcoin/rest.rb', line 40 def spot_userinfo post_data = initial_post_data post_request post_data: post_data, action: "/v1/userinfo.do" end |