Class: Deribit::Client
- Inherits:
-
Object
- Object
- Deribit::Client
- Defined in:
- lib/deribit/client.rb
Overview
Instance Attribute Summary collapse
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#websocket ⇒ Object
readonly
Returns the value of attribute websocket.
Instance Method Summary collapse
-
#account(currency: 'BTC', ext: false) {|Hashie::Mash| ... } ⇒ Hashie::Mash
Retrieves user account summary.
-
#announcements {|Hashie::Mash| ... } ⇒ Array
Retrieves announcements from last 30 days.
-
#book(options = { instrument_name: 'BTC-PERPETUAL' }) {|Hashie::Mash| ... } ⇒ Hashie::Mash
Notifies about changes to the order book for a certain instrument.
-
#buy(instrument_name, amount, options = {}) ⇒ Hashie::Mash
@option options [Float] :stop_price price required for stop limit orders (Only valid for stop orders) @option options [String] :trigger Defines trigger type: index_price mark_price last_price, required for “stop_limit” order type @option options [String] :advanced Advanced option order type, can be “implv”, “usd”.
-
#cancel(order_id) ⇒ Hashie::Mash
Cancels an order, specified by order id.
-
#cancel_all(options = {}) ⇒ Boolean
Cancels all orders, optionally filtered by instrument or instrument type.
-
#close(instrument_name, options = { type: :market }) ⇒ Hashie::Mash
Close a position.
-
#currencies ⇒ Array
Retrieves all cryptocurrencies supported by the API.
-
#edit(order_id, amount, price, options = {}) ⇒ Hashie::Mash
Changes price and/or quantity of the own order.
-
#index(options = { currency: 'BTC' }) ⇒ Hashie::Mash
Retrieves the current index price for the BTC-USD instruments.
-
#initialize(key: nil, secret: nil, testnet: false, debug: false) ⇒ Deribit::Client
constructor
Create new instance.
-
#instruments(options = { currency: 'BTC' }) ⇒ Array
Retrieves available trading instruments.
-
#orders(options = { instrument_name: 'BTC-PERPETUAL' }) {|Hashie::Mash| ... } ⇒ Array
Retrieves open orders.
-
#positions(options = { currency: 'BTC' }) ⇒ Array
Retrieves current positions.
-
#quote(options = { instrument_name: 'BTC-PERPETUAL' }, &blk) ⇒ Object
Best bid/ask price and size.
-
#sell(instrument_name, amount, options = {}) ⇒ Hashie::Mash
Places a sell order for an instrument.
-
#settlements(filters = { instrument_name: 'BTC-PERPETUAL' }) {|Hashie::Mash| ... } ⇒ Hashie::Mash
Retrieves settlement, delivery and bankruptcy events that have occurred.
-
#ticker(options = { instrument_name: 'BTC-PERPETUAL' }, &blk) ⇒ Object
Key information about the instrument.
-
#trades(filters) {|Hashie::Mash| ... } ⇒ Array
Retrieve the latest trades that have occurred for instruments in a specific currency symbol/for a specific instrument and optionally within given time range.
Constructor Details
#initialize(key: nil, secret: nil, testnet: false, debug: false) ⇒ Deribit::Client
Create new instance
17 18 19 20 21 |
# File 'lib/deribit/client.rb', line 17 def initialize(key: nil, secret: nil, testnet: false, debug: false) host = testnet ? TESTNET_HOST : MAINNET_HOST @http = Deribit::Http.new host, key: key, secret: secret, debug: debug @websocket = Deribit::Websocket.new host, key: key, secret: secret end |
Instance Attribute Details
#http ⇒ Object (readonly)
Returns the value of attribute http.
9 10 11 |
# File 'lib/deribit/client.rb', line 9 def http @http end |
#websocket ⇒ Object (readonly)
Returns the value of attribute websocket.
9 10 11 |
# File 'lib/deribit/client.rb', line 9 def websocket @websocket end |
Instance Method Details
#account(currency: 'BTC', ext: false) {|Hashie::Mash| ... } ⇒ Hashie::Mash
Retrieves user account summary.
171 172 173 174 175 176 177 |
# File 'lib/deribit/client.rb', line 171 def account(currency: 'BTC', ext: false) if block_given? raise Deribit::NotImplementedError, 'not implemented' else http.get '/private/get_account_summary', currency: currency end end |
#announcements {|Hashie::Mash| ... } ⇒ Array
Retrieves announcements from last 30 days.
132 133 134 135 136 137 138 |
# File 'lib/deribit/client.rb', line 132 def announcements(&blk) if block_given? websocket.subscribe 'announcements', &blk else http.get '/public/get_announcements' end end |
#book(options = { instrument_name: 'BTC-PERPETUAL' }) {|Hashie::Mash| ... } ⇒ Hashie::Mash
Notifies about changes to the order book for a certain instrument.
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/deribit/client.rb', line 67 def book( = { instrument_name: 'BTC-PERPETUAL' }, &blk) unless [:instrument_name] raise ArgumentError, 'instrument_name argument is required' end if block_given? channel = Naming.book_channel websocket.subscribe channel, params: {}, &blk else http.get '/public/get_order_book', end end |
#buy(instrument_name, amount, options = {}) ⇒ Hashie::Mash
@option options [Float] :stop_price price required for stop limit orders (Only valid for stop orders)
@option options [String] :trigger Defines trigger type: index_price mark_price last_price, required for "stop_limit" order type
@option options [String] :advanced Advanced option order type, can be "implv", "usd". (Only valid for options)
198 199 200 201 |
# File 'lib/deribit/client.rb', line 198 def buy(instrument_name, amount, = {}) params = .merge instrument_name: instrument_name, amount: amount http.get 'private/buy', params end |
#cancel(order_id) ⇒ Hashie::Mash
Cancels an order, specified by order id.
248 249 250 |
# File 'lib/deribit/client.rb', line 248 def cancel(order_id) http.get '/private/cancel', order_id: order_id end |
#cancel_all(options = {}) ⇒ Boolean
Cancels all orders, optionally filtered by instrument or instrument type.
262 263 264 265 |
# File 'lib/deribit/client.rb', line 262 def cancel_all( = {}) uri = Naming.cancel_uri http.get uri, end |
#close(instrument_name, options = { type: :market }) ⇒ Hashie::Mash
Close a position
222 223 224 225 |
# File 'lib/deribit/client.rb', line 222 def close(instrument_name, = { type: :market }) params = .merge instrument_name: instrument_name, type: [:type] http.get '/private/close_position', params end |
#currencies ⇒ Array
Retrieves all cryptocurrencies supported by the API.
39 40 41 |
# File 'lib/deribit/client.rb', line 39 def currencies http.get '/public/get_currencies' end |
#edit(order_id, amount, price, options = {}) ⇒ Hashie::Mash
Changes price and/or quantity of the own order.
239 240 241 242 |
# File 'lib/deribit/client.rb', line 239 def edit(order_id, amount, price, = {}) params = .merge order_id: order_id, amount: amount, price: price http.get '/private/edit', params end |
#index(options = { currency: 'BTC' }) ⇒ Hashie::Mash
Retrieves the current index price for the BTC-USD instruments.
48 49 50 51 52 53 54 |
# File 'lib/deribit/client.rb', line 48 def index( = { currency: 'BTC' }) unless [:currency] raise ArgumentError, 'currency argument is required' end http.get '/public/get_index', end |
#instruments(options = { currency: 'BTC' }) ⇒ Array
Retrieves available trading instruments.
30 31 32 33 34 |
# File 'lib/deribit/client.rb', line 30 def instruments( = { currency: 'BTC' }) raise ArgumentError, 'currency is required' unless [:currency] http.get '/public/get_instruments', end |
#orders(options = { instrument_name: 'BTC-PERPETUAL' }) {|Hashie::Mash| ... } ⇒ Array
Retrieves open orders.
303 304 305 306 307 308 309 310 |
# File 'lib/deribit/client.rb', line 303 def orders( = { instrument_name: 'BTC-PERPETUAL' }, &blk) if block_given? channel = Naming.channel 'user.orders', websocket.subscribe channel, params: , &blk else http.get '/private/get_open_orders_by_instrument', end end |
#positions(options = { currency: 'BTC' }) ⇒ Array
Retrieves current positions.
318 319 320 |
# File 'lib/deribit/client.rb', line 318 def positions( = { currency: 'BTC' }) http.get '/private/get_positions', end |
#quote(options = { instrument_name: 'BTC-PERPETUAL' }, &blk) ⇒ Object
Best bid/ask price and size.
271 272 273 274 275 276 277 278 |
# File 'lib/deribit/client.rb', line 271 def quote( = { instrument_name: 'BTC-PERPETUAL' }, &blk) unless block_given? raise 'block is missing, HTTP-RPC not supported for this endpoint' end channel = Naming.channel_for_instrument 'quote', websocket.subscribe channel, params: , &blk end |
#sell(instrument_name, amount, options = {}) ⇒ Hashie::Mash
Places a sell order for an instrument.
209 210 211 212 |
# File 'lib/deribit/client.rb', line 209 def sell(instrument_name, amount, = {}) params = .merge instrument_name: instrument_name, amount: amount http.get '/private/sell', params end |
#settlements(filters = { instrument_name: 'BTC-PERPETUAL' }) {|Hashie::Mash| ... } ⇒ Hashie::Mash
Retrieves settlement, delivery and bankruptcy events that have occurred.
151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/deribit/client.rb', line 151 def settlements(filters = { instrument_name: 'BTC-PERPETUAL' }) instrument_name = filters[:instrument_name] currency = filters[:currency] unless instrument_name || currency raise ArgumentError, 'either :instrument_name or :currency arg is required' end if block_given? raise Deribit::NotImplementedError, 'not implemented' else http.get '/public/get_last_settlements_by_instrument', filters end end |
#ticker(options = { instrument_name: 'BTC-PERPETUAL' }, &blk) ⇒ Object
Key information about the instrument
285 286 287 288 289 290 291 292 |
# File 'lib/deribit/client.rb', line 285 def ticker( = { instrument_name: 'BTC-PERPETUAL' }, &blk) if block_given? channel = Naming.channel 'ticker', websocket.subscribe channel, params: , &blk else http.get '/public/ticker', end end |
#trades(filters) {|Hashie::Mash| ... } ⇒ Array
Retrieve the latest trades that have occurred for instruments in a specific currency symbol/for a specific instrument and optionally within given time range.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/deribit/client.rb', line 110 def trades(filters, &blk) instrument_name = filters[:instrument_name] currency = filters[:currency] unless instrument_name || currency raise ArgumentError, 'either :instrument_name or :currency args is required' end if block_given? channel = Naming.trades_channel filters websocket.subscribe channel, params: {}, &blk else uri = Naming.trades_uri filters response = http.get uri, filters response.trades end end |