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
- #equity ⇒ Object
- #future_cancel(pair:, contract_type:, order_id:) ⇒ Object
- #futures_orderbook(pair:, contract:, items_no: 50) ⇒ Object
- #futures_orders_info(order_id:, symbol:, contract_type:) ⇒ Object
- #futures_position(pair:, contract_type:) ⇒ Object
- #futures_user_info ⇒ Object
-
#initialize(api_key: nil, secret_key: nil) ⇒ Rest
constructor
A new instance of Rest.
- #orderbook(pair:, items_no: 50) ⇒ Object
- #trade_futures(pair:, amount:, type:, contract_type:, match_price:, price: nil, lever_rate: 10) ⇒ Object
- #user_info ⇒ 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
#equity ⇒ Object
23 24 25 26 |
# File 'lib/okcoin/rest.rb', line 23 def equity post_data = initial_post_data post_request(post_data: post_data, action: "/v1/future_userinfo.do")["info"]["btc"]["account_rights"] end |
#future_cancel(pair:, contract_type:, order_id:) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/okcoin/rest.rb', line 48 def future_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_orderbook(pair:, contract:, items_no: 50) ⇒ Object
28 29 30 31 |
# File 'lib/okcoin/rest.rb', line 28 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_orders_info(order_id:, symbol:, contract_type:) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/okcoin/rest.rb', line 58 def futures_orders_info(order_id:, symbol:, contract_type:) post_data = initial_post_data post_data["symbol"] = symbol post_data["contract_type"] = contract_type post_data["order_id"] = order_id post_request post_data: post_data, action: "/v1/future_orders_info.do" end |
#futures_position(pair:, contract_type:) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/okcoin/rest.rb', line 67 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_user_info ⇒ Object
18 19 20 21 |
# File 'lib/okcoin/rest.rb', line 18 def futures_user_info post_data = initial_post_data post_request post_data: post_data, action: "/v1/future_userinfo.do" end |
#orderbook(pair:, items_no: 50) ⇒ Object
13 14 15 16 |
# File 'lib/okcoin/rest.rb', line 13 def orderbook(pair:, items_no: 50) query = { "ok" => 1, "symbol" => pair, "size" => items_no } get_request(url: "/depth.do", query: query) end |
#trade_futures(pair:, amount:, type:, contract_type:, match_price:, price: nil, lever_rate: 10) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/okcoin/rest.rb', line 33 def trade_futures(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 |
#user_info ⇒ Object
75 76 77 78 |
# File 'lib/okcoin/rest.rb', line 75 def user_info post_data = initial_post_data post_request post_data: post_data, action: "/v1/userinfo.do" end |