ZenWebsocket.Examples.DeribitRpc (ZenWebsocket v0.1.4)
View SourceShared Deribit JSON-RPC method definitions and request builders.
This module centralizes all Deribit RPC method definitions to avoid duplication across adapter examples.
Uses ZenWebsocket.JsonRpc.build_request/2 and returns the
standard {:ok, map()} tuple for consistency with library conventions.
Summary
Functions
Builds an authentication request for Deribit API.
Builds a generic JSON-RPC request for any Deribit method.
Creates a buy order for the specified instrument.
Cancels an existing order by ID.
Retrieves available trading instruments for a currency.
Retrieves all open orders with optional filters.
Retrieves the order book for a specific instrument.
Creates a sell order for the specified instrument.
Sets the heartbeat interval for the WebSocket connection.
Subscribes to one or more channels for real-time data.
Builds a test request to verify the connection is alive.
Gets ticker data for a specific instrument.
Unsubscribes from one or more channels.
Functions
Builds an authentication request for Deribit API.
Parameters
client_id- Your Deribit API client IDclient_secret- Your Deribit API client secret
Returns
{:ok, request} tuple with JSON-RPC request map for authentication.
Builds a generic JSON-RPC request for any Deribit method.
Parameters
method- The RPC method nameparams- Method parameters (default: %{})
Returns
{:ok, request} tuple with JSON-RPC request map.
Creates a buy order for the specified instrument.
Parameters
instrument- Instrument name (e.g., "BTC-PERPETUAL")amount- Order amount in contractsopts- Additional order options (type, price, etc.)
Returns
{:ok, request} tuple with JSON-RPC request map for buy order.
Cancels an existing order by ID.
Parameters
order_id- The order ID to cancel
Returns
{:ok, request} tuple with JSON-RPC request map for order cancellation.
Retrieves available trading instruments for a currency.
Parameters
currency- Currency code (e.g., "BTC", "ETH")
Returns
{:ok, request} tuple with JSON-RPC request map for retrieving instruments.
Retrieves all open orders with optional filters.
Parameters
opts- Optional filters (instrument, type, etc.)
Returns
{:ok, request} tuple with JSON-RPC request map for retrieving open orders.
Retrieves the order book for a specific instrument.
Parameters
instrument- Instrument name (e.g., "BTC-PERPETUAL")depth- Order book depth (default: 10)
Returns
{:ok, request} tuple with JSON-RPC request map for order book data.
Creates a sell order for the specified instrument.
Parameters
instrument- Instrument name (e.g., "BTC-PERPETUAL")amount- Order amount in contractsopts- Additional order options (type, price, etc.)
Returns
{:ok, request} tuple with JSON-RPC request map for sell order.
Sets the heartbeat interval for the WebSocket connection.
Parameters
interval- Heartbeat interval in seconds (default: 30)
Returns
{:ok, request} tuple with JSON-RPC request map for setting heartbeat.
Subscribes to one or more channels for real-time data.
Parameters
channels- List of channel names to subscribe to
Example
subscribe(["book.BTC-PERPETUAL.raw", "ticker.ETH-PERPETUAL.raw"])Returns
{:ok, request} tuple with JSON-RPC request map for subscription.
@spec test_request() :: {:ok, map()}
Builds a test request to verify the connection is alive.
Returns
{:ok, request} tuple with JSON-RPC request map for connection testing.
Gets ticker data for a specific instrument.
Parameters
instrument- Instrument name (e.g., "BTC-PERPETUAL")
Returns
{:ok, request} tuple with JSON-RPC request map for ticker data.
Unsubscribes from one or more channels.
Parameters
channels- List of channel names to unsubscribe from
Returns
{:ok, request} tuple with JSON-RPC request map for unsubscription.