WebsockexNova.Examples.ClientDeribitMacro (WebsockexNova v0.1.0)

View Source

Deribit-specific client API using the ClientMacro.

This demonstrates how to build a Deribit WebSocket API client with minimal code, leveraging the WebsockexNova.ClientMacro.

Summary

Functions

Authenticate using credentials.

Close the connection.

Connect to WebSocket API with sensible defaults from the adapter. User-supplied opts override defaults.

Get information about locked currencies on the platform.

Retrieves the current time from Deribit (in milliseconds).

Introduce the client software to Deribit over WebSocket.

Send a ping and wait for pong response.

Place a market order (buy/sell at market price)

Send a text message.

Get connection status.

Subscribe to a channel.

Subscribe to a Deribit ticker channel for a given instrument (e.g., "BTC-PERPETUAL").

Subscribe to a Deribit trades channel for a given instrument (e.g., "BTC-PERPETUAL").

Tests the connection to the API server and returns its version.

Unsubscribe from a channel.

Functions

authenticate(conn, credentials \\ %{}, opts \\ nil)

Authenticate using credentials.

close(conn)

Close the connection.

connect(opts \\ %{})

Connect to WebSocket API with sensible defaults from the adapter. User-supplied opts override defaults.

default_opts()

get_account_summary(conn, currency, opts \\ nil)

Get account summary

get_platform_status(conn, opts \\ nil)

Get information about locked currencies on the platform.

Example

{:ok, status} = DeribitClient.get_platform_status(conn)
# status will include information on locked currencies

get_time(conn, opts \\ nil)

Retrieves the current time from Deribit (in milliseconds).

This is useful for checking clock skew between your software and Deribit's systems.

Example

{:ok, timestamp} = DeribitClient.get_time(conn)
# timestamp will be something like 1550147385946

hello(conn, client_name, client_version, opts \\ nil)

Introduce the client software to Deribit over WebSocket.

Deribit will also introduce itself in the response.

Parameters

  • client_name - Client software name
  • client_version - Client software version

Example

{:ok, response} = DeribitClient.hello(conn, "MyTradingApp", "1.0.0")
# response will include Deribit's version information

ping(conn, opts \\ nil)

Send a ping and wait for pong response.

place_market_order(conn, map, opts \\ nil)

Place a market order (buy/sell at market price)

send_json(conn, payload, opts \\ nil)

Send a JSON message.

send_text(conn, text, opts \\ nil)

Send a text message.

status(conn, opts \\ nil)

Get connection status.

subscribe(conn, channel, opts \\ nil)

Subscribe to a channel.

subscribe_to_ticker(conn, instrument, opts \\ nil)

Subscribe to a Deribit ticker channel for a given instrument (e.g., "BTC-PERPETUAL").

subscribe_to_trades(conn, instrument, opts \\ nil)

Subscribe to a Deribit trades channel for a given instrument (e.g., "BTC-PERPETUAL").

test(conn, expected_result \\ nil, opts \\ nil)

Tests the connection to the API server and returns its version.

Use to verify API reachability and version.

Parameters

  • expected_result - (Optional) If set to "exception", triggers error

Example

{:ok, version_info} = DeribitClient.test(conn)
# version_info will include Deribit's API version

unsubscribe(conn, channel, opts \\ nil)

Unsubscribe from a channel.