Class: Deribit::API
- Inherits:
-
Object
- Object
- Deribit::API
- Defined in:
- lib/deribit/api.rb
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #account(full: false) ⇒ Object
-
#buy(instrument, quantity, price, type: "limit", stopPx: nil, execInst: "index_price", post_only: nil, reduce_only: nil, label: nil, max_show: nil, adv: nil) ⇒ Object
| Name | Type | Decription | |————–|————|———————————————————————————–| | ‘instrument` | `string` | Required, instrument name | | `quantity` | `integer` | Required, quantity, in contracts ($10 per contract for futures, ฿1 — for options) | | `price` | `float` | Required, USD for futures, BTC for options | | `type` | `string` | Required, “limit”, “market” or for futures only: “stop_limit” | | `stopPx` | `string` | Required, needed for stop_limit order, defines stop price | | `post_only` | `boolean` | Optional, if true then the order will be POST ONLY | | `label` | `string` | Optional, user defined maximum 32-char label for the order | | `max_show` | `string` | Optional, optional parameter, if “0” then the order will be hidden | | `adv` | `string` | Optional, can be “implv”, “usd”, or absent (advanced order type) |.
- #cancel(order_id) ⇒ Object
- #cancel_all(type = "all") ⇒ Object
- #currencies ⇒ Object
-
#edit(order_id, quantity, price, post_only: nil, adv: nil, stopPx: nil) ⇒ Object
| Name | Type | Decription | |————–|————|———————————————————————————–| | ‘order_id` | `integer` | Required, ID of the order returned by “sell” or “buy” request | | `quantity` | `integer` | Required, quantity, in contracts ($10 per contract for futures, ฿1 — for options) | | `price` | `float` | Required, USD for futures, BTC for options | | `post_only` | `boolean` | Optional, if true then the order will be POST ONLY | | `adv` | `string` | Optional, can be “implv”, “usd”, or absent (advanced order type) |.
- #index ⇒ Object
-
#initialize(key = nil, secret = nil, test_server: nil) ⇒ API
constructor
A new instance of API.
- #instruments(expired: false, only_active: true) ⇒ Object
- #last_trades(instrument, count: nil, since: nil) ⇒ Object
- #margins(instrument, quantity: 1, price: 0.01) ⇒ Object
- #open_orders(instrument: nil, order_id: nil, type: nil) ⇒ Object
- #order_history(instrument: nil, count: nil, offset: nil) ⇒ Object
- #order_state(order_id) ⇒ Object
- #orderbook(instrument) ⇒ Object
- #positions ⇒ Object
-
#sell(instrument, quantity, price, type: "limit", stopPx: nil, execInst: "index_price", post_only: nil, reduce_only: nil, label: nil, max_show: nil, adv: nil) ⇒ Object
| Name | Type | Decription | |————–|————|———————————————————————————–| | ‘instrument` | `string` | Required, instrument name | | `quantity` | `integer` | Required, quantity, in contracts ($10 per contract for futures, ฿1 — for options) | | `price` | `float` | Required, USD for futures, BTC for options | | `post_only` | `boolean` | Optional, if true then the order will be POST ONLY | | `label` | `string` | Optional, user defined maximum 32-char label for the order | | `max_show` | `string` | Optional, optional parameter, if “0” then the order will be hidden | | `adv` | `string` | Optional, can be “implv”, “usd”, or absent (advanced order type) |.
- #summary(instrument = 'all') ⇒ Object
- #test ⇒ Object
- #trade_history(instrument: nil, count: nil, start_trade_id: nil) ⇒ Object
Constructor Details
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
3 4 5 |
# File 'lib/deribit/api.rb', line 3 def request @request end |
Instance Method Details
#account(full: false) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/deribit/api.rb', line 59 def account(full: false) params = { ext: full } request.send(path: '/api/v1/private/account', params: params) end |
#buy(instrument, quantity, price, type: "limit", stopPx: nil, execInst: "index_price", post_only: nil, reduce_only: nil, label: nil, max_show: nil, adv: nil) ⇒ Object
| Name | Type | Decription |
|--------------|------------|-----------------------------------------------------------------------------------|
| `instrument` | `string` | Required, instrument name |
| `quantity` | `integer` | Required, quantity, in contracts ($10 per contract for futures, ฿1 — for options) |
| `price` | `float` | Required, USD for futures, BTC for options |
| `type` | `string` | Required, "limit", "market" or for futures only: "stop_limit" |
| `stopPx` | `string` | Required, needed for stop_limit order, defines stop price |
| `post_only` | `boolean` | Optional, if true then the order will be POST ONLY |
| `label` | `string` | Optional, user defined maximum 32-char label for the order |
| `max_show` | `string` | Optional, optional parameter, if "0" then the order will be hidden |
| `adv` | `string` | Optional, can be "implv", "usd", or absent (advanced order type) |
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/deribit/api.rb', line 80 def buy(instrument, quantity, price, type: "limit", stopPx: nil, execInst: "index_price", post_only: nil, reduce_only: nil, label: nil, max_show: nil, adv: nil) params = { instrument: instrument, quantity: quantity, price: price } %i(type stopPx post_only reduce_only label max_show adv execInst).each do |var| variable = eval(var.to_s) params[var] = variable if variable end request.send(path: '/api/v1/private/buy', params: params) end |
#cancel(order_id) ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/deribit/api.rb', line 146 def cancel(order_id) params = { "orderId": order_id } request.send(path: '/api/v1/private/cancel', params: params) end |
#cancel_all(type = "all") ⇒ Object
154 155 156 157 158 159 160 |
# File 'lib/deribit/api.rb', line 154 def cancel_all(type = "all") params = { "type": type } request.send(path: '/api/v1/private/cancelall', params: params) end |
#currencies ⇒ Object
30 31 32 |
# File 'lib/deribit/api.rb', line 30 def currencies request.send(path: '/api/v1/public/getcurrencies', params: {}) end |
#edit(order_id, quantity, price, post_only: nil, adv: nil, stopPx: nil) ⇒ Object
| Name | Type | Decription |
|--------------|------------|-----------------------------------------------------------------------------------|
| `order_id` | `integer` | Required, ID of the order returned by "sell" or "buy" request |
| `quantity` | `integer` | Required, quantity, in contracts ($10 per contract for futures, ฿1 — for options) |
| `price` | `float` | Required, USD for futures, BTC for options |
| `post_only` | `boolean` | Optional, if true then the order will be POST ONLY |
| `adv` | `string` | Optional, can be "implv", "usd", or absent (advanced order type) |
131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/deribit/api.rb', line 131 def edit(order_id, quantity, price, post_only: nil, adv: nil, stopPx: nil) params = { orderId: order_id, quantity: quantity, price: price } %i(post_only adv stopPx).each do |var| variable = eval(var.to_s) params[var] = variable if variable end request.send(path: '/api/v1/private/edit', params: params) end |
#index ⇒ Object
22 23 24 |
# File 'lib/deribit/api.rb', line 22 def index request.send(path: '/api/v1/public/index', params: {}) end |
#instruments(expired: false, only_active: true) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/deribit/api.rb', line 13 def instruments(expired: false, only_active: true) response = request.send(path: '/api/v1/public/getinstruments', params: {expired: expired}) if response.is_a?(Array) and only_active response = response.select {|i| i[:isActive] == true} end response end |
#last_trades(instrument, count: nil, since: nil) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/deribit/api.rb', line 34 def last_trades(instrument, count: nil, since: nil) params = {instrument: instrument} params[:count] = count if count params[:since] = since if since request.send(path: '/api/v1/public/getlasttrades', params: params) end |
#margins(instrument, quantity: 1, price: 0.01) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/deribit/api.rb', line 49 def margins(instrument, quantity: 1, price: 0.01) params = { instrument: instrument, quantity: quantity, price: price } request.send(path: '/api/v1/private/getmargins', params: params) end |
#open_orders(instrument: nil, order_id: nil, type: nil) ⇒ Object
162 163 164 165 166 167 168 169 |
# File 'lib/deribit/api.rb', line 162 def open_orders(instrument: nil, order_id: nil, type: nil) params = {} params[:instrument] = instrument if instrument params[:orderId] = order_id if order_id params[:type] = type if type request.send(path: '/api/v1/private/getopenorders', params: params) end |
#order_history(instrument: nil, count: nil, offset: nil) ⇒ Object
183 184 185 186 187 188 189 190 |
# File 'lib/deribit/api.rb', line 183 def order_history(instrument: nil, count: nil, offset: nil) params = {} params[:instrument] = instrument if instrument params[:count] = count if count params[:offset] = offset if offset request.send(path: '/api/v1/private/orderhistory', params: params) end |
#order_state(order_id) ⇒ Object
175 176 177 178 179 180 181 |
# File 'lib/deribit/api.rb', line 175 def order_state(order_id) params = { "orderId": order_id } request.send(path: '/api/v1/private/orderstate', params: params) end |
#orderbook(instrument) ⇒ Object
9 10 11 |
# File 'lib/deribit/api.rb', line 9 def orderbook(instrument) request.send(path: "/api/v1/public/getorderbook", params: {instrument: instrument}) end |
#positions ⇒ Object
171 172 173 |
# File 'lib/deribit/api.rb', line 171 def positions request.send(path: '/api/v1/private/positions', params: {}) end |
#sell(instrument, quantity, price, type: "limit", stopPx: nil, execInst: "index_price", post_only: nil, reduce_only: nil, label: nil, max_show: nil, adv: nil) ⇒ Object
| Name | Type | Decription |
|--------------|------------|-----------------------------------------------------------------------------------|
| `instrument` | `string` | Required, instrument name |
| `quantity` | `integer` | Required, quantity, in contracts ($10 per contract for futures, ฿1 — for options) |
| `price` | `float` | Required, USD for futures, BTC for options |
| `post_only` | `boolean` | Optional, if true then the order will be POST ONLY |
| `label` | `string` | Optional, user defined maximum 32-char label for the order |
| `max_show` | `string` | Optional, optional parameter, if "0" then the order will be hidden |
| `adv` | `string` | Optional, can be "implv", "usd", or absent (advanced order type) |
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/deribit/api.rb', line 107 def sell(instrument, quantity, price, type: "limit", stopPx: nil, execInst: "index_price", post_only: nil, reduce_only: nil, label: nil, max_show: nil, adv: nil) params = { instrument: instrument, quantity: quantity, price: price } %i(type stopPx post_only reduce_only label max_show adv execInst).each do |var| variable = eval(var.to_s) params[var] = variable if variable end request.send(path: '/api/v1/private/sell', params: params) end |
#summary(instrument = 'all') ⇒ Object
42 43 44 45 46 47 |
# File 'lib/deribit/api.rb', line 42 def summary(instrument = 'all') params = {} params[:instrument] = instrument if instrument request.send(path: '/api/v1/public/getsummary', params: params) end |
#test ⇒ Object
26 27 28 |
# File 'lib/deribit/api.rb', line 26 def test request.send(path: '/api/v1/public/test', params: {}) end |
#trade_history(instrument: nil, count: nil, start_trade_id: nil) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/deribit/api.rb', line 192 def trade_history(instrument: nil, count: nil, start_trade_id: nil) params = {} %i(count instrument).each do |var| variable = eval(var.to_s) params[var] = variable if variable end params[:startTradeId] = start_trade_id if start_trade_id request.send(path: '/api/v1/private/tradehistory', params: params) end |