class Deribit::API

Attributes

request[R]

Public Class Methods

new(key = nil, secret = nil, test_server: nil) click to toggle source
# File lib/deribit/api.rb, line 5
def initialize(key = nil, secret = nil, test_server: nil)
  @request = Request.new(key, secret, test_server: test_server)
end

Public Instance Methods

account(full: false) click to toggle source
# 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) click to toggle source

| 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) |

# 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) click to toggle source
# 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") click to toggle source
# 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() click to toggle source
# 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) click to toggle source

| 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) |

# 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() click to toggle source
# File lib/deribit/api.rb, line 22
def index
  request.send(path: '/api/v1/public/index', params: {})
end
instruments(expired: false, only_active: true) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/deribit/api.rb, line 9
def orderbook(instrument)
  request.send(path: "/api/v1/public/getorderbook", params: {instrument: instrument})
end
positions() click to toggle source
# 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) click to toggle source

| 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) |

# 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') click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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