Erlang library for Deribit API
The Deribit API is available in this package.
This package contains module:
deribit_api- connects with Deribit API through REST or websocket
rebar3 compile
{ok, Connection} = deribit_api:open("Key", "Secret", websocket).
Result = deribit_api:getlasttrades(Pid, #{ instrument => "BTC-7APR17"} ).
deribit_api:getlasttrades(Connection, #{ instrument => "BTC-7APR17"}, {async, fun(R) -> io:format("Result: ~p~n", [R]) end}).
Ref = deribit_api:getlasttrades(Connection, #{ instrument => "BTC-7APR17"}, async),
receive
{Connection, {Ref, Status, Data}} -> io:format("Status: ~p, Data: ~p~n", [Status, Data])
end.
-
open()
open(Options)
open(AccessKey, AccessSecret)
open(AccessKey, AccessSecret, Option)Creates new
Pid- connection identifier, prepares connection with server. IfOptionis not provided, http connection is used to communicate withderibit.comserver,Params map values:
Name Type Definition AccessKeystringOptional, Access Key needed to access Private functions AccessSecretstringOptional, Access Secret needed to access Private functions Options`atom string`
Parameters in all methods:
| Key | Definition |
|---|---|
Pid |
Required, connection identifier, from deribit_api:open |
Params |
Required map in some methods, see description of each |
Options |
Optional, see description below |
All methods accept optional Options list as last parameter. Allowed values:
- not provided - method returns:
{error, Message}- when error occurred,Messageis error message{ok, Result}- when result was received,Resultis resonse
[async]- result is sent to calling process andRef- request identifier is returned. Sent message format:{Pid, {Ref, ok | error, Data = any()}{async, fun:1}- when result is receivedfunis called.
-
index(Connection)- Doc, public
index(Connection, Options)Get price index, BTC-USD rates.
-
getcurrencies(Connection)- Doc, public
getcurrencies(Connection, Options)Get all supported currencies.
-
getorderbook(Connection, Instrument)- Doc, public
getorderbook(Connection, Instrument, Options)Retrieve the orderbook for a given instrument.
Parameters:
Key Type Decription Instrument`string() binary()` -
getlasttrades(Connection, Params)- Doc, public
getlasttrades(Connection, Params, Options)Retrieve the latest trades that have occured for a specific instrument.
Params map values:
Key Type Decription Instrument`string() binary()` countinteger()Optional, count of trades returned (limitation: max. count is 100) sinceinteger()Optional, “since” trade id, the server returns trades newer than that “since” -
getsummary(Connection, Instrument)- Doc, public
getsummary(Connection, Instrument, Options)Retrieve the summary info such as Open Interest, 24H Volume etc for a specific instrument.
Parameters:
Key Type Decription Instrument`string() binary()` -
account(Connection)- Doc, Private
account(Connection, Options)Get user account summary.
-
buy(Connection, Params)- Doc, private
buy(Connection, Params, Options)Place a buy order in an instrument.
Params map values:
Key Type Decription Instrument`string() binary()` Quantity`integer() float() Price`integer() float() PostOnlyboolean()Optional, if true then the order will be POST ONLY Label`string() binary()` -
sell(Connection, Params)- Doc, private
sell(Connection, Params, Options)Place a sell order in an instrument.
Params map values:
Key Type Decription InstrumentstringRequired, instrument name QuantityintegerRequired, quantity, in contracts ($10 per contract for futures, ฿1 — for options) PricefloatRequired, USD for futures, BTC for options PostOnlybooleanOptional, if true then the order will be POST ONLY LabelstringOptional, user defined maximum 4-char label for the order -
edit(Connection, Params)- Doc
edit(Connection, Params, Options)Edit price and/or quantity of the own order. (Authorization is required).
Params map values:
Key Type Decription OrderIdinteger()Required, ID of the order returned by "sell" or "buy" request Quantity`integer() float() Price`integer() float() -
cancel(Connection, OrderId)- Doc, private
cancel(Connection, OrderId, Options)Cancel own order by id.
Parameters:
Key Type Decription OrderIdinteger()Required, ID of the order returned by "sell" or "buy" request -
cancelall(Connection, Type)- Doc
cancelall(Connection, Type, Options)Cancel all own futures, or all options, or all.
Parameters:
Key Type Decription Type`all futures -
getopenorders(Connection, Params)- Doc, private
getopenorders(Connection, Params, Options)Retrieve open orders.
Params map values:
Key Type Description Instrument`string() binary()` OrderIdinteger()Optional, order id -
positions(Connection)- Doc, private
positions(Connection, Options)Retreive positions.
-
orderhistory(Connection)- Doc, private
orderhistory(Connection, Count)
orderhistory(Connection, Count, Options)Get history.
Parameters
Key Type Description Countinteger()Optional, number of requested records, if not provided all records is returned -
tradehistory(Connection, Params)- Doc, private
tradehistory(Connection, Params, Options)Get private trade history of the account. (Authorization is required). The result is ordered by trade identifiers (trade id-s).
Params map values:
Key Type Description Countinteger()Optional, number of results to fetch. Instrument`string() binary() StartTradeIdinteger()Optional, number of requested records
-
subscribe(Connection, Params)- Doc, private
subscribe(Connection, Params, Options)Subscribe to notifications. Notifications are send to calling process.
Params map values:
Key Type Description Count`list(string()) [all] Events`list(order_book trade -
unsubscribe(Connection)- Doc, privateUnsubscribe notifications.