How to Connect
Last updated
Last updated
To support a wide range of integration needs, we offer three main interfaces for interacting with the platform:
REST API – Provides access to structured data that is also available on-chain, such as asset metadata, order book snapshots, or transaction data. Additionally, the REST API allows users to submit primary market orders (i.e., initial purchases directly from the issuer). While much of this data can be accessed via the blockchain, the REST API offers a simpler and more convenient interface for off-chain systems.
WebSocket API – Enables subscriptions to dynamic market data, including live trades, open orders, and price feeds. This API is optimized for performance and low-latency updates, making it well-suited for trading interfaces, monitoring tools, or analytics dashboards.
Smart Contract Interface – Allows for direct on-chain interactions, particularly for executing secondary market orders. This requires using the contract’s ABI and a connected Web3 provider (e.g., via ethers.js
, web3.py
, or similar libraries).
To simplify integration, we provide a Python SDK that wraps both the REST API and the smart contract interface. On request, we also support SDKs in other languages and offer custom integrations for custody solutions or institutional environments.
For example, if you want to trade a fund (FUND) for Euro (EURQ), the pair would be FUND/EURQ
. Make sure to take note of the respective id
of a trading pair. You will need it for further api calls.
The buy
array contains the orders that want to buy the base tokens with the quote currency, sorted by descending price. The sell
array contains the orders that want to sell the base tokens for the quote currency, sorted by ascending price.
The difference between the highest bid and the lowest ask is called the spread. The spread indicates how liquid the market is for that trading pair.
To place an order on our platform, you need to have enough balance of the base tokens (when selling) or quote tokens (when buying) in your wallet. You can check your balance your wallet app or website. Up next, we will show you how to interact with our smart-contract, approve tokens, place orders and execute trades.
The order-book smart contract is the core component of the 21X DLT Exchange, where users can place and cancel buy and sell orders for various tokens. In this section, we will explain how you can interact with the contract using its functions.
The newBuyOrder
function allows you to create a new buy order for a specific token and amount. You don't need to specify the token address, as it is already included in the specific trading pair. What you need to specify is the amount of tokens you want to buy, and the price per token. Quantity and Price have to be provided in scaled format. For details please refer to the Order data explanation. The function will emit a OrderReceived
event with the order details when it is added to the Order Book and store the order in the contract's state.
Depending on if the order can be immediately executed or not, the function will also emit NewBuyOrder
and/or NewBuyInitiatedTrade
events.
Beforehand you need to make approval of appropriate amount of quote tokens to be collected by the order book address.
The newSellOrder
function allows you to create a new sell order for a specific token and amount. You don't need to specify the token address, as it is already included in the specific trading pair. What you need to specify is the amount of tokens you want to buy, and the price per token. Quantity and Price have to be provided in scaled format. For details please refer to the Order data explanation. The function will emit a OrderReceived
event with the order details when it is added to the Order Book and store the order in the contract's state.
Depending on if the order can be immediately executed or not, the function will also emit NewSellOrder
and/or NewSellInitiatedTrade
events.
Beforehand you need to make approval of appropriate amount of base tokens to be collected by the order book address.
The cancelBuyOrder
function allows you to cancel a buy order that you have previously created. You need to specify the order ID, which you can obtain from the NewBuyOrder
or OrderReceived
event or the contract's state. The function will emit a CancelOrder
event with the order details and return the remaining tokens that were allocated for the order.
Note that you can only cancel orders that were sent from the same wallet, and only as long as they have not been executed.
The cancelSellOrder
function allows you to cancel a buy order that you have previously created. You need to specify the order ID, which you can obtain from the NewSellOrder
or OrderReceived
event or the contract's state. The function will emit a CancelOrder
event with the order details and return the remaining tokens that were allocated for the order.
Note that you can only cancel orders that were sent from the same wallet, and only as long as they have not been executed.
To see what trading pairs are available on our platform, you can use the endpoint. This will return a list of pairs, where baseTokenData.symbol
is the token you want to buy or sell, and quoteTokenSymbol
is the currency you want to use as payment or receive as payment.
To get the price history of a trading pair, you can use the endpoint. This will return a series of data points in the format x, o, h, l, c
, where x
is the encoded timestamp of the start of the time interval, o
(open) is the price at the start of a time interval, h
(high) is the highest price during that interval, l
(low) is the lowest price during that interval, and c
(close) is the price at the end of that interval.
To get the current price and volume of a trading pair, you can use the endpoint. This will return the latest data in the format , where lastPrice
is the last traded price of the pair, referencePrice
is the closing price of the previous trading day, tradeVolume24h
is the total amount of base tokens traded in the past 24 hours and priceChange24h
is the price change in percentage. Additionally, you will receive information on the current trading status and potential trading halts.
To see the current state of the order book for a trading pair, you can use the endpoint or the . This will return a list of orders in two arrays: buy
and sell
. Each order is represented by a pair of values: [quantity, limit]
, where limit
is the price per base token, and quantity
is the total number of base tokens available/requested at that price.
The difference between these two endpoints is that aggregates orders with the same price limit into one item, while lists every order individually.