# `ZenWebsocket.Examples.DeribitRpc`
[🔗](https://github.com/ZenHive/zen_websocket/blob/v0.8.0/lib/zen_websocket/examples/deribit_rpc.ex#L1)

Shared 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.

# `auth_request`

```elixir
@spec auth_request(String.t(), String.t()) :: {:ok, map()}
```

Builds an authentication request for Deribit API.

## Parameters
- `client_id` - Your Deribit API client ID
- `client_secret` - Your Deribit API client secret

## Returns
`{:ok, request}` tuple with JSON-RPC request map for authentication.

# `build_request`

```elixir
@spec build_request(String.t(), map()) :: {:ok, map()}
```

Builds a generic JSON-RPC request for any Deribit method.

## Parameters
- `method` - The RPC method name
- `params` - Method parameters (default: %{})

## Returns
`{:ok, request}` tuple with JSON-RPC request map.

# `buy`

```elixir
@spec buy(String.t(), number(), map()) :: {:ok, 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
`{:ok, request}` tuple with JSON-RPC request map for buy order.

# `cancel`

```elixir
@spec cancel(String.t()) :: {:ok, map()}
```

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.

# `get_instruments`

```elixir
@spec get_instruments(String.t()) :: {:ok, map()}
```

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.

# `get_open_orders`

```elixir
@spec get_open_orders(map()) :: {:ok, map()}
```

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.

# `get_order_book`

```elixir
@spec get_order_book(String.t(), integer()) :: {:ok, map()}
```

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.

# `sell`

```elixir
@spec sell(String.t(), number(), map()) :: {:ok, 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
`{:ok, request}` tuple with JSON-RPC request map for sell order.

# `set_heartbeat`

```elixir
@spec set_heartbeat(integer()) :: {:ok, map()}
```

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.

# `subscribe`

```elixir
@spec subscribe([String.t()]) :: {:ok, 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
`{:ok, request}` tuple with JSON-RPC request map for subscription.

# `test_request`

```elixir
@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.

# `ticker`

```elixir
@spec ticker(String.t()) :: {:ok, map()}
```

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.

# `unsubscribe`

```elixir
@spec unsubscribe([String.t()]) :: {:ok, map()}
```

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.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
