REST API Interaction
The REST API is an essential part of the 21X platform, providing a wide range of functionality to interact with trading pairs, order books, and user-specific data. The API is divided into two categories: public and authenticated endpoints.
Why Use the REST API?
Public Endpoints Public endpoints are accessible without authentication and are used to:
Fetch available trading pairs.
Retrieve order book data and price levels.
Access general ticker information for trading pairs.
Authenticated Endpoints Authenticated endpoints require user authentication and are designed for private, wallet-specific operations, such as:
Viewing orders placed by your wallet.
Fetching your order and trade history.
Retrieving order IDs (useful for canceling orders).
These endpoints complement the smart contract interactions by providing additional data and ensuring smooth integration for trading activities.
Client Configuration
The 21X SDK includes a REST API client for seamless interaction with the platform. The client supports both synchronous and asynchronous requests, enabling flexible integration into your applications.
Setting Up the Client
Public Endpoints Use the
Clientclass to interact with public endpoints:Authenticated Endpoints For endpoints requiring authentication, use the
AuthenticatedClientclass and provide a valid token:
Alternatively, you can make use the following environment variables, to auto configure the clients.
Example Usage
Synchronous Example
Calling an endpoint and working with the response:
Asynchronous Example
Using the async version of the client:
Advanced Configuration
The client provides options to customize behavior based on your application's needs.
SSL Verification
For APIs using HTTPS, SSL verification ensures secure connections. You can specify a custom certificate bundle:
To disable SSL verification (not recommended), set verify_ssl=False:
Customizing HTTPX
You can extend or replace the underlying httpx client for advanced use cases:
For even greater control, set a custom httpx.Client instance directly:
Public Endpoints
getTradingPairs
getTradingPairsFetches a list of all available trading pairs on the platform.
Parameters
None
Example Usage
Refer to the API Documentation for detailed request/response structure.
getTradeInfo
getTradeInfoRetrieves trade information for a trading pair
Parameters
id(str): The identifier of the trading pair.
Example Usage
Refer to the API Documentation for detailed request/response structure.
getOrderBookTopOrders
getOrderBookTopOrdersRetrieves the top orders from the order book for a specified trading pair.
Parameters
id(str): The identifier of the trading pair.kind(Union[Unset, OrderKindEnum], optional): The type of orders to retrieve (e.g., buy or sell).max_(Union[Unset, int], optional): The maximum number of orders to return.
Example Usage
Notes
The
kindparameter can be used to filter results by order type (e.g., only buy or sell orders).If
max_is not provided, the endpoint will return a default number of top orders.
Refer to the API Documentation for detailed request/response structure.
getOrderBookPriceLevels
getOrderBookPriceLevelsFetches the price levels from the order book for a specified trading pair.
Parameters
id(str): The identifier of the trading pair.kind(Union[Unset, OrderKindEnum], optional): The type of price levels to retrieve (e.g., buy or sell).max_(Union[Unset, int], optional): The maximum number of price levels to return.
Example Usage
Notes
The
kindparameter allows filtering price levels by type (e.g., only buy or sell price levels).If
max_is omitted, the endpoint defaults to returning a predefined number of price levels.
Refer to the API Documentation for detailed request/response structure.
getPostTradeTransparency
getPostTradeTransparencyRetrieves regulatory post-trade transparency data for the entire exchange. By default, it shows the most recent trades first. You can limit the results to a specific trading pair by providing its ID.
Parameters
query(Union[Unset, GetPostTradeTransparencyQuery], optional): Query parameters to filter the data, such as trading pair ID.cursor(Union[Unset, str], optional): A pagination cursor to navigate through the dataset.limit(Union[Unset, int], optional): The maximum number of trades to retrieve.count(Union[Unset, bool], optional): IfTrue, includes a count of total available trades in the response.
Example Usage
Notes
Providing a
trading_pair_idin the query restricts the results to trades involving that pair.Use the
cursorfor paginated requests, especially when dealing with large datasets.The
countparameter helps determine the total number of trades available without fetching all results.
Refer to the API Documentation for detailed request/response structure.
Authenticated Endpoints
getWalletOrders
getWalletOrdersDescription
This authenticated endpoint fetches all orders associated with the specified wallet. By default, it returns open orders. You can filter the results to a specific trading pair or include completed, canceled, and rejected orders by adjusting the parameters.
Parameters
wallet_address(str, required): The wallet address to fetch orders for.query(Union[Unset, GetWalletOrdersQuery], optional): Filters for the request, such as trading pair ID or status.cursor(Union[Unset, str], optional): A pagination cursor to navigate through the dataset.limit(Union[Unset, int], optional): The maximum number of orders to retrieve.count(Union[Unset, bool], optional): IfTrue, includes a count of total available orders in the response.
Example Usage
Notes
Set
only_opentoFalsein the query to fetch completed, canceled, and rejected orders instead of open ones.Use the
cursorparameter for paginated requests when dealing with a large number of orders.The
countparameter is helpful for understanding the size of the dataset without fetching all results.
Refer to the OpenAPI Documentation for detailed request/response structures.
getWalletTrades
getWalletTradesDescription
This authenticated endpoint retrieves all completed trades involving the specified wallet. You can optionally restrict the results to a specific trading pair.
Parameters
wallet_address(str, required): The wallet address to fetch trades for.query(Union[Unset, GetWalletTradesQuery], optional): Filters for the request, such as trading pair ID or trade time range.cursor(Union[Unset, str], optional): A pagination cursor to navigate through the dataset.limit(Union[Unset, int], optional): The maximum number of trades to retrieve.count(Union[Unset, bool], optional): IfTrue, includes a count of total available trades in the response.
Example Usage
Notes
Use the
trading_pairparameter in the query to restrict results to a specific pair.The
cursorparameter allows for paginated navigation, which is helpful for wallets with a high trade volume.Setting the
countparameter toTrueprovides a total count of trades without retrieving the entire dataset.
Refer to the OpenAPI Documentation for more details on request/response formats.
Last updated

