Skip to main content

Creating trades

Creating a trade is also known as filling an order, or buying an asset. A user executes a trade by agreeing to purchase an asset at the terms specified in the order and then becomes the new owner of the asset.

Typescript SDK

1. Initialize the SDK

In order to use the SDK, you need to initialize it.

2. Generate signers

Creating a trade for a user requires a user's signature, so your application will need to create signers. See the guide on how to generate signers. Then setup GenericIMXProvider

3. Create the trade

When setting taker fees in the trade params
  • You cannot set more than 3 recipients
  • You cannot set the same recipient more than once
  • The combined fee percentage can’t exceed 100%
  • Individual percentage fees can’t be <= 0%
📚SDK reference

Request

Creating a trade for the order with ID 7232:

const createTrade = async (orderId: number) => {
const ethAddress = await wallet.ethSigner.getAddress();
const tradeData = {
order_id: orderId,
user: ethAddress
} as GetSignableTradeRequest;

const response = await imxProvider.createTrade(tradeData);
return response;
}

createTrade(7232)
.then((result) => {
console.log(result)
})
.catch((e) => {
console.log(e)
})

Example response:

{ 
trade_id: 226892, // ID of trade within Immutable X
status: '' // Current status of trade
}