This section is for SpoonOS developers who want to call Deribit via the
spoon-toolkit integration and MCP tools, instead of using the Python APIs
directly.
Deribit credentials and network selection are provided via environment
variables (or a .env file):
# Required
DERIBIT_CLIENT_ID=your_client_id
DERIBIT_CLIENT_SECRET=your_client_secret
# Network selection
DERIBIT_USE_TESTNET=true # "true" for testnet, "false" for mainnetRecommended workflow:
- Start with testnet (
DERIBIT_USE_TESTNET=true) for development and dry‑runs. - Only switch to mainnet when you have:
- Verified market data, account, and trading tools on testnet.
- Implemented your own risk controls at the application / agent layer.
All tools read configuration via DeribitConfig in env.py.
Deribit tools are designed to be exposed to Spoon agents through MCP servers
and through the spoon_toolkits package.
At a high level:
- The Python tool classes (for example
GetInstrumentsTool,PlaceBuyOrderTool) are the building blocks. - In Spoon, these tools are typically:
- Registered via an MCP server module that imports and exposes all tools, or
- Imported directly from
spoon_toolkits.data_platforms.deribitin your own custom MCP server.
When integrating with Spoon:
- Treat each Deribit tool as a single RPC‑like operation.
- Use Spoon’s tool configuration (YAML or Python) to:
- Wire in the Deribit MCP server.
- Ensure the necessary environment variables are present in the SpoonOS runtime.
The integration pattern is intentionally similar to the existing
desearchandchainbasetoolkits: you configure environment variables, register the MCP server, and then call tools by name from Spoon agents.
The table below maps Deribit’s official JSON‑RPC endpoints (as documented on
https://docs.deribit.com/) to the corresponding tools in this toolkit.
This is useful when you read Deribit’s docs and want to know “which tool
should I call from Spoon”.
| Deribit JSON‑RPC method | Toolkit tool | Notes |
|---|---|---|
public/get_instruments |
GetInstrumentsTool |
List instruments by currency, kind, etc. |
public/get_ticker |
GetTickerTool |
Ticker, mark price, last price, best bid/ask. |
public/get_order_book |
GetOrderBookTool |
Level‑2 order book for an instrument. |
public/get_last_trades_by_instrument |
GetLastTradesTool |
Recent trades for an instrument. |
public/get_index_price |
GetIndexPriceTool |
Index price for an index. |
private/get_account_summary |
GetAccountSummaryTool |
Account balances, equity, margin, etc. |
private/get_positions |
GetPositionsTool |
Open positions by currency / kind. |
private/get_open_orders_by_instrument |
GetOpenOrdersTool |
Open orders for a specific instrument. |
private/get_order_history_by_instrument |
GetOrderHistoryTool |
Order history for an instrument. |
private/get_trades_by_instrument |
GetTradeHistoryTool |
Trade history for an instrument. |
private/buy |
PlaceBuyOrderTool |
Place buy orders (spot / futures / options). |
private/sell |
PlaceSellOrderTool |
Place sell orders (spot / futures / options). |
private/cancel |
CancelOrderTool |
Cancel a single order by ID. |
private/cancel_all_by_currency / kind |
CancelAllOrdersTool |
Cancel all open orders by currency / kind. |
The tools may perform additional spec‑based validation (contract size, tick size, etc.) before calling Deribit; see the error handling section below for details.
This section describes high‑level workflows that you can implement in Spoon agents by calling the tools in sequence. It is intentionally language‑agnostic (no Python code).
Goal: verify spot trading tools and contract‑size validation with minimal risk.
- Discover instruments
- Call
GetInstrumentsTool(currency="ETH", kind="spot", expired=False). - Prefer instruments containing
USDCorUSDTininstrument_name.
- Call
- Fetch current price
- Call
GetTickerTool(instrument_name=...). - Use
last_priceormark_priceas the reference.
- Call
- Place a deep, non‑filling limit order
- Call
PlaceBuyOrderToolorPlaceSellOrderToolwith:order_type="limit"post_only=Truepriceset far away from the current price (for example 30–40% away).
- The toolkit will:
- Validate
amountagainstcontract_size. - Validate
priceagainsttick_size.
- Validate
- Call
- Verify and cancel
- Call
GetOpenOrdersTool(instrument_name=...)to confirm the order appears. - Cancel it using
CancelOrderTool(order_id=...)orCancelAllOrdersTool(currency="ETH", kind="spot").
- Call
This pattern is used by test_spot_trading.py and
test_0.02eth_safe_trading.py.
Goal: ensure futures buy/sell tools and position reporting work correctly.
- Check current positions
- Call
GetPositionsTool(currency="ETH", kind="future"). - Decide whether it is safe to open a small test position (for example, no large existing exposure).
- Call
- Fetch futures price
- Call
GetTickerTool(instrument_name="ETH-PERPETUAL").
- Call
- Open a small position
- Call
PlaceBuyOrderToolwith:instrument_name="ETH-PERPETUAL"order_type="market"(for functional test), or a deeplimitfor non‑filling tests.amount=1.0(or a very small size, depending on your risk policy).
- Call
- Verify position
- Call
GetPositionsToolagain to confirm a non‑zero size.
- Call
- Close the position
- Call
PlaceSellOrderToolwith:instrument_name="ETH-PERPETUAL"order_type="market"amountequal to the current long size (do not oversell).
- Call
- Final checks
- Ensure
GetPositionsToolreports zero size. - Optionally call
GetOpenOrdersToolto confirm no open futures orders remain.
- Ensure
This pattern is implemented (with extra logging and funding tracking) in
test_complete_trading_workflow.py and test_all_trading_types.py.
Goal: test options functionality with a very small balance, minimizing risk and avoiding tick‑size issues.
This pattern is also described in TRADING_EXPERIENCE.md and implemented in
test_options_safe_roundtrip.py:
- Select a cheap ETH option
- Use
GetInstrumentsTool(currency="ETH", kind="option", expired=False)to list options. - For each candidate instrument:
- Call
GetTickerTool(instrument_name=...)to readmark_price. - Compute
estimated_cost = mark_price × contract_size.
- Call
- Filter to options where
estimated_costis:- Far below the current account balance.
- Below a hard cap (for example
0.005 ETH).
- Pick the cheapest option that passes those filters.
- Use
- Buy 1 contract using a market order
- Call
PlaceBuyOrderToolwith:order_type="market"amount=1.0(1 contract, or 1×contract_size).
- Let the matching engine decide the actual fill price and handle tick‑size / price‑band rules.
- Call
- Verify position
- Call
GetPositionsTool(currency="ETH", kind="option"). - Find the instrument with
size > 0(the option you just bought).
- Call
- Sell using reduce‑only market order
- Call
PlaceSellOrderToolwith:order_type="market"amountequal to the current long size.reduce_only=True(ensure this only closes the position, never opens a short).
- Call
- Final checks
- Verify balances and positions using
GetAccountSummaryToolandGetPositionsTool. - Check recent trades using
GetTradeHistoryTool.
- Verify balances and positions using
This pattern is the safest way to validate options trading end‑to‑end on a small account.
Deribit tools perform two layers of validation:
-
Toolkit‑level validation (pre‑flight)
- Required parameters:
instrument_name,amount, andprice(for limit orders). - Basic checks: values must be positive and non‑null.
- Spec‑based checks using
GetInstrumentsTool:amountmust be a multiple ofcontract_size.pricemust conform totick_sizefor the instrument.
- If these checks fail, the tool:
- Does not call the Deribit API.
- Returns a structured error (typically a dict with an
"error"field and, where possible, suggested adjusted values).
- Required parameters:
-
Deribit API errors
- Even after local validation, Deribit may return errors due to:
- Insufficient funds.
- Internal price bands / additional tick rules (especially for options).
- Network or internal server issues.
- Even after local validation, Deribit may return errors due to:
Spoon developers should treat these as normal, expected conditions and handle them in their own logic. Some common cases:
-
must be a multiple of contract size- Origin: Deribit or toolkit.
- Action:
- Read
contract_sizefrom the error (or fromGetInstrumentsTool). - Adjust
amountto the suggested multiple. - At the agent layer, you can either reduce trade size or explain the required contract size to the end user.
- Read
-
must conform to tick size- Origin: Deribit or toolkit.
- Cause:
- Price not aligned with
tick_size, or not within internal price bands.
- Price not aligned with
- Action:
- Use the
tick_sizereturned by the toolkit. - Adjust prices by rounding to multiples of
tick_size. - For options, consider using market orders as described in the safe options pattern instead of complex limit‑order logic inside the core tool layer.
- Use the
-
not_enough_funds- Origin: Deribit API.
- Action:
- Re‑check account balance via
GetAccountSummaryTool. - Decide at the strategy / application layer whether to:
- Reduce position size.
- Skip the trade.
- Ask the user to deposit more funds.
- Re‑check account balance via
In general:
- Toolkit errors (validation failures) are your signal that the request is malformed at the spec level.
- Deribit errors are your signal that the trade is valid in shape, but not executable under current account or market conditions.
When integrating into SpoonOS, you rarely want to run all examples; instead, use a small curated subset:
-
Core documentation
- This file: high‑level overview, tools list, and Spoon integration hints.
TRADING_EXPERIENCE.md: detailed trading notes (contract sizes, tick sizes, options quirks, safe patterns).
-
Read‑only / smoke tests
examples/test_public_api.pyexamples/test_authentication.pyexamples/test_market_data_tools.pyexamples/test_account_tools.pyexamples/test_mainnet_readonly.py(mainnet read‑only, safe to run with real funds).
-
Spot / futures functional tests
examples/test_spot_trading.py– safe spot limit‑order test (deep limit + cancel).examples/test_0.02eth_safe_trading.py– safe futures test for very small balances.examples/test_complete_trading_workflow.py– end‑to‑end spot + futures workflow.examples/test_all_trading_types.py– combined spot + futures + options test, with full cleanup.
-
Options functional tests
examples/test_options_safe_roundtrip.py– recommended default for options; small‑risk buy+sell pattern.examples/test_options_complete.py– more detailed options workflow, including logs and funding tracking.examples/test_options_auto_trade.py,examples/test_options_close_position.py,examples/test_options_trading.py– additional options examples and diagnostics.
These examples/ are meant as reference workflows and regression tests,
not as a public API. In SpoonOS agents, you should always call the tool
classes (GetInstrumentsTool, PlaceBuyOrderTool, etc.) directly and
apply your own business logic, risk management, and UX layer on top.
Deribit integration for the spoon_toolkits project.
This module provides typed tools for the Deribit JSON‑RPC API
(market data, account, and trading), suitable for use both directly
and via MCP.
Note: This README is written for the upstream
spoon-toolkitrepository. Paths below assume the package layout\n>spoon_toolkits/data_platforms/deribit/.
From the spoon-toolkit project root:
pip install -e .Create a .env file that provides Deribit credentials and network:
DERIBIT_CLIENT_ID=your_client_id
DERIBIT_CLIENT_SECRET=your_client_secret
DERIBIT_USE_TESTNET=true # \"true\" for testnet, \"false\" for mainnetThe module reads configuration via DeribitConfig in env.py.
You can use the tools either through the top‑level spoon_toolkits
package or via the deribit submodule.
from spoon_toolkits import (
GetInstrumentsTool,
GetTickerTool,
PlaceBuyOrderTool,
)
async def main():
tool = GetInstrumentsTool()
result = await tool.execute(currency=\"BTC\", kind=\"future\")
print(result)from spoon_toolkits.data_platforms.deribit import (
GetInstrumentsTool,
GetTickerTool,
PlaceBuyOrderTool,
)from spoon_toolkits.data_platforms.deribit import deribit_mcp
# deribit_mcp is a FastMCP instance that exposes all Deribit tools
# over the MCP protocol.GetInstrumentsTool– list instrumentsGetOrderBookTool– order bookGetTickerTool– ticker / mark priceGetLastTradesTool– recent tradesGetIndexPriceTool– index priceGetBookSummaryTool– book summary
GetAccountSummaryTool– account summaryGetPositionsTool– open positionsGetOrderHistoryTool– order historyGetTradeHistoryTool– trade history
PlaceBuyOrderTool– place buy ordersPlaceSellOrderTool– place sell ordersCancelOrderTool– cancel a single orderCancelAllOrdersTool– cancel all open orders for a currency/kindGetOpenOrdersTool– list open orders by instrumentEditOrderTool– edit an existing order
The examples/ directory contains end‑to‑end scripts demonstrating
how to use the tools safely with small balances:
- Spot and futures:
test_spot_trading.pytest_0.02eth_safe_trading.pytest_complete_trading_workflow.pytest_all_trading_types.py
- Options:
test_options_safe_roundtrip.py– picks a cheap ETH option and\n performs a buy + sell round trip (with detailed logging).test_options_complete.py– more detailed options workflow tests.
For a higher‑level summary of lessons learned (contract sizes, tick sizes, options quirks, and safe patterns), see:
TRADING_EXPERIENCE.md
For API‑level smoke tests (market data, account, auth) see:
examples/test_public_api.pyexamples/test_authentication.pyexamples/test_market_data_tools.pyexamples/test_account_tools.py
-
Core implementation lives under:
spoon_toolkits/data_platforms/deribit/ -
The Deribit JSON‑RPC client is in
jsonrpc_client.pyand is reused by all tools. -
Tools are implemented in
market_data.py,account.py, andtrading.py. -
Higher‑level test workflows and debug scripts reside in
examples/and are not part of the public API surface.