API Deribit

Deribit

Deribit is a cryptocurrency derivatives exchange offering futures and options trading on Bitcoin and Ethereum.

APIs supported

Properties

You can configure the following properties in the Deribit property.

Connection

When the client successfully connects to Deribit servers, the event OnConnect is fired. After the event OnConnect is fired, then you can start to send and receive messages to/from Deribit servers. If you are connecting to the private websocket channel, you must wait till OnDeribitAuthentication event is fired and check if the success parameter is true, before subscribing to any private channel.


TsgcWebSocketClient oClient = new TsgcWebSocketClient();
TsgcWS_API_Deribit oDeribit = new TsgcWS_API_Deribit();
oDeribit.Client = oClient;
oDeribit.Deribit.ApiKey = "your_api_key";
oDeribit.Deribit.ApiSecret = "your_api_secret";
oDeribit.Deribit.TestNet = false;
oClient.Active = true;
void OnConnect(TsgcWSConnection Connection)
{
  DoLog("#Deribit Connected");
}

Events

The Deribit client implements the following events to control the connection flow and get data sent from the WebSocket server:

WebSocket API

The websocket feed provides real-time market data updates for orders and trades.

You can subscribe to the following Public channels:

Method Description
SubscribeTicker Subscribe to the ticker stream for an instrument. Provides real-time price and volume data.
SubscribeTrades Subscribe to the recent trades stream for an instrument.
SubscribeOrderBook Subscribe to the order book stream. Supports configurable grouping, depth levels and update intervals.
SubscribeCandle Subscribe to the candlestick stream. Supports multiple resolutions (e.g. 1, 3, 5, 10, 15, 30, 60, 120, 180, 360, 720, 1D).
SubscribePerpetual Subscribe to perpetual contract data for an instrument. Provides funding rate and other perpetual-specific information.
SubscribeBookChange Subscribe to order book change notifications for an instrument.

You can subscribe to the following Private channels (require authentication):

Method Description
SubscribeOrders Subscribe to order updates for an instrument.
SubscribePositions Subscribe to position updates. Supports filtering by currency and instrument kind.
SubscribeAccountChanges Subscribe to account balance changes for a currency.
SubscribeUserTrades Subscribe to user trade updates for an instrument.

Find below an example of subscribing to websocket channels.


void OnDeribitAuthentication(TObject Sender, bool aSuccess, string aError, string aRawMessage)
{
  if (aSuccess == true)
  {
    oDeribit.SubscribeOrders("BTC-PERPETUAL");
    oDeribit.SubscribePositions("BTC");
  }
}

REST API

The REST API provides Public and Private methods to request data from markets, trading, account, and wallet. Access the REST API through the REST_API property of the component.

Market Data (Public)

Method Description
GetInstruments Get available instruments for a currency.
GetTicker Get ticker information for an instrument.
GetOrderBook Get the order book for an instrument.
GetTrades Get the most recent trades for an instrument.
GetCurrencies Get the list of supported currencies.
GetIndexPrice Get the current index price for an index name.
GetFundingRateHistory Get the funding rate history for an instrument.
GetFundingRateValue Get the current funding rate value for an instrument.
GetBookSummaryByCurrency Get book summary for all instruments of a currency.
GetBookSummaryByInstrument Get book summary for a specific instrument.

Trading (Private)

Method Description
Buy Place a buy order. Supports market and limit order types.
Sell Place a sell order. Supports market and limit order types.
CancelOrder Cancel an existing order by order ID.
CancelAllOrders Cancel all open orders.
CancelAllByInstrument Cancel all open orders for a specific instrument.
EditOrder Edit an existing order (change amount or price).
GetOpenOrders Get the list of open orders for a currency.
GetOrderState Get the state of a specific order.
GetOrderHistory Get the order history for a currency.

Account (Private)

Method Description
GetPositions Get positions for a currency.
GetAccountSummary Get the account summary for a currency.
GetSubAccounts Get the list of sub-accounts.
GetTransactionLog Get the transaction log for a currency.

Wallet (Private)

Method Description
GetDeposits Get the deposit history for a currency.
GetWithdrawals Get the withdrawal history for a currency.
GetTransfers Get the transfer history for a currency.

Find below an example of using the REST API.


TsgcWS_API_Deribit oDeribit = new TsgcWS_API_Deribit();
oDeribit.Deribit.ApiKey = "your_api_key";
oDeribit.Deribit.ApiSecret = "your_api_secret";
// Get ticker
oDeribit.REST_API.GetTicker("BTC-PERPETUAL");
// Place a buy order
oDeribit.REST_API.Buy("BTC-PERPETUAL", 10, "market");
// Get account summary
oDeribit.REST_API.GetAccountSummary("BTC");