WebsockexAdapter.Examples.DeribitRpc (WebsockexAdapter v0.1.1)

View Source

Shared Deribit JSON-RPC method definitions and request builders.

This module centralizes all Deribit RPC method definitions to avoid duplication across adapter examples.

Summary

Functions

Builds an authentication request for Deribit API.

Builds a JSON-RPC request for the given method and params.

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

auth_request(client_id, client_secret)

@spec auth_request(String.t(), String.t()) :: map()

Builds an authentication request for Deribit API.

Parameters

  • client_id - Your Deribit API client ID
  • client_secret - Your Deribit API client secret

Returns

A JSON-RPC request map for authentication.

build_request(method, params \\ %{})

@spec build_request(String.t(), map()) :: map()

Builds a JSON-RPC request for the given method and params.

Parameters

  • method - The JSON-RPC method name
  • params - Optional parameters map (defaults to empty map)

Returns

A map containing the complete JSON-RPC request structure.

buy(instrument, amount, opts \\ %{})

@spec buy(String.t(), number(), map()) :: map()

Creates a buy order for the specified instrument.

Parameters

  • instrument - Instrument name (e.g., "BTC-PERPETUAL")
  • amount - Order amount in contracts
  • opts - Additional order options (type, price, etc.)

Returns

A JSON-RPC request map for buy order.

cancel(order_id)

@spec cancel(String.t()) :: map()

Cancels an existing order by ID.

Parameters

  • order_id - The order ID to cancel

Returns

A JSON-RPC request map for order cancellation.

get_instruments(currency)

@spec get_instruments(String.t()) :: map()

Retrieves available trading instruments for a currency.

Parameters

  • currency - Currency code (e.g., "BTC", "ETH")

Returns

A JSON-RPC request map for retrieving instruments.

get_open_orders(opts \\ %{})

@spec get_open_orders(map()) :: map()

Retrieves all open orders with optional filters.

Parameters

  • opts - Optional filters (instrument, type, etc.)

Returns

A JSON-RPC request map for retrieving open orders.

get_order_book(instrument, depth \\ 10)

@spec get_order_book(String.t(), integer()) :: map()

Retrieves the order book for a specific instrument.

Parameters

  • instrument - Instrument name (e.g., "BTC-PERPETUAL")
  • depth - Order book depth (default: 10)

Returns

A JSON-RPC request map for order book data.

sell(instrument, amount, opts \\ %{})

@spec sell(String.t(), number(), map()) :: map()

Creates a sell order for the specified instrument.

Parameters

  • instrument - Instrument name (e.g., "BTC-PERPETUAL")
  • amount - Order amount in contracts
  • opts - Additional order options (type, price, etc.)

Returns

A JSON-RPC request map for sell order.

set_heartbeat(interval \\ 30)

@spec set_heartbeat(integer()) :: map()

Sets the heartbeat interval for the WebSocket connection.

Parameters

  • interval - Heartbeat interval in seconds (default: 30)

Returns

A JSON-RPC request map for setting heartbeat.

subscribe(channels)

@spec subscribe([String.t()]) :: map()

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

A JSON-RPC request map for subscription.

test_request()

@spec test_request() :: map()

Builds a test request to verify the connection is alive.

Returns

A JSON-RPC request map for connection testing.

ticker(instrument)

@spec ticker(String.t()) :: map()

Gets ticker data for a specific instrument.

Parameters

  • instrument - Instrument name (e.g., "BTC-PERPETUAL")

Returns

A JSON-RPC request map for ticker data.

unsubscribe(channels)

@spec unsubscribe([String.t()]) :: map()

Unsubscribes from one or more channels.

Parameters

  • channels - List of channel names to unsubscribe from

Returns

A JSON-RPC request map for unsubscription.