Guide: Building a Trading Interface
Token Support
If your wallet fully supports CIP-56 tokens you can freely integrate all Tradecraft pools for trading, along with add and remove liquidity options (which return CIP-56 compliant Tradecraft LP tokens).
If your wallet supports only a whitelist of Canton tokens you will need to manually limit your interface to only allow trading of your wallet's supported tokens.
Pools API
To build a trading interface that supports all pools listed on Tradecraft, start by using the GET /pools API to fetch a list of all pools. Note that multi-hop trades are not yet supported.
To get a list of tradable token pairs for a given token, run a reduce function on the list of pools and construct a mapping of each unique token to a list of other tokens. Every time a token appears in a pool entry, add its paired token to its list of tradable tokens. With the two pools we have online now, your output would look like this:
const tradableTokens = {
'CC': ['USDCx', 'CBTC'],
'USDCx': ['CC'],
'CBTC': ['CC']
}Now you can create a widget with token drop-downs similar to a standard swap widget that looks something like the below image. Each entry in tradableTokens can be added to the first drop-down, and the second drop-down can be populated with the array value for that token.

Quote API
Important
While the API is currently named "quote", these quotes should be presented to users as estimates. Since the on-chain portion of a trade is only initiated after the user sends funds and after Tradecraft gets to their order and begins execution, the price returned from the quote API may not be the price the user receives, unless a limit is specified for the trade.
There are two API's for getting trade quotes–one to specify amount in, and one to specify amount out. Use either or both as your interface requires. For example in the widget above, the API for amount in would be used when the user types in the first input, showing response in the second, and when the user types in the second input, the response would be shown in the first input. Both APIs can be found on the Quotes API page.
Initiating a Trade
There are two options for executing trades, both introduced on the Integration page.
For the Daml package integration option, see Guide: DAR Integration.
For Pool Addresses, see Pool Addresses.
Last updated
Was this helpful?
