Documentation
API Reference
Trade
ℹ️

To interact with the Cede SDK, you need to create an instance of the SDK and register at least one exchange instance. Refer to the General info section for details.

Most of the methods in the trade module follow the sequence of a typical trading flow. These methods allow you to retrieve market pairs, obtain the best bid and ask rates, determine minimum amounts, prepare orders, and create, retrieve, update, or cancel orders.

Get market pairs

Fetch all available market pairs. You can use this method to get the list of all available pairs on an exchange and to get the minimum base and quote amounts.

method: getMarketPairs
params:

  • exchangeInstanceId - string, optional
    The exchange instance ID.
  • auth - The authentication object for the exchange. See authentication section for details.
  • opts.forceReload - boolean | undefined, optional
    All market pairs are loaded only once in the SDK. Use true if you want to update the list of markets.
  • opts.requestPriority - 1 | 2 | 3, optional
    The request priority.
    Default: 2 (medium).

response structure: Promise<MarketPair[]>, see MarketPair for details.

const marketPairs = await cedeSDK.api.getMarketPairs({ exchangeInstanceId, auth });

Get bid and ask rates

Fetch the best bid and ask rates for a market pair. You can use this method to get the current market rate to estimate a received amount. In case of a buy order, use the ask rate, in case of a sell order, use the bid rate.

method: getMarketRate
params:

  • exchangeInstanceId - string
    The exchange instance ID.
  • auth - The authentication object for the exchange. See authentication section for details.
  • pairSymbol - string
    The pair symbol in the format of base/quote. For example, BTC/USDC.

response structure:

  • bid - string
    The best bid rate (the highest price a buyer is willing to pay).
  • ask - string
    The best ask rate (the lowest price a seller is willing to accept).
const order = await cedeSDK.api.getMarketRate({ 
  exchangeInstanceId,
  auth,
  pairSymbol: "ETH/USDT", 
});

Get minimum amounts

Before submitting an order, you will need to retrieve the minimum amounts for the base and quote tokens, as well as the price. To do this, use:

method: getMinAmounts
params:

  • exchangeInstanceId - string
    The exchange instance ID.
  • auth - The authentication object for the exchange. See authentication section for details.
  • pairSymbol - string
    The pair symbol in the format of base/quote. For example, BTC/USDC.
  • orderSide - "buy" | "sell"
    The order side.
  • price - string
    The price in quote currency. For the market order, use the current market rate value from the getMarketRate method.

response structure:

  • minBaseAmount - string
    The minimum base amount (in base currency).
  • minQuoteAmount - string
    The minimum quote amount (in quote currency).
  • minPrice - string
    The minimum price.
const minAmounts = await cedeSDK.api.getMinAmounts({ 
  exchangeInstanceId,
  auth,
  pairSymbol: "ETH/USDT"
  orderSide: "buy",
  price: "3103.7"
});

Prepare order

Use this method to calculate the trade fee for a market order and to use the createOrderRequest to create the order. Since some exchanges include trading fees in the amount and others append it, this method automatically adjusts the traded amount to include the fee, ensuring sufficient funds are available to cover the fee.

method: prepareOrder
parameters:

  • exchangeInstanceId - string, optional
    The exchange instance ID.
  • auth - The authentication object for the exchange. See authentication section for details.
  • pairSymbol - string
    The pair symbol in the format of base/quote. For example, BTC/USDC.
  • orderType - "market" | "limit"
    The order type.
  • orderSide - "buy" | "sell"
    The order side.
  • amount - string
    The amount in base currency.
  • price - string
    The price in quote currency. For market orders, use the current market rate value from the getMarketRate method.

response structure:

  • estimatedAmount - string
    The estimated amount after the fee.
  • estimatedFee - Fee
    The estimated fee, see Fee for details.
  • createOrderRequest - CreateOrderRequest
    The create order request object that you should pass in createOrder function params, see CreateOrderRequest for details.
const preparedOrderData = await cedeSDK.api.prepareOrder({ 
  exchangeInstanceId,
  auth,
  pairSymbol: "ETH/USDT",
  orderType: OrderType.MARKET,
  orderSide: "buy",
  price: "3103.7",
  amount: "0.1",
});

Create order

To create a market or a limit order, use:

method: createOrder
params: auth parameter (See authentication section for details) with CreateOrderParams, see CreateOrderParams for details. You should pass the createOrderRequest from prepareOrder method.
response structure: Promise<Order>, see Order for details.

The order ID corresponds to the order ID returned by the exchange.

const order = await cedeSDK.api.createOrder(createOrderRequest); // createOrderRequest is the object returned by the prepareOrder method

Get order

To get an order, use:

method: getOrder
params:

  • exchangeInstanceId - string
    The exchange instance ID.
  • auth - The authentication object for the exchange. See authentication section for details.
  • orderId - string
    The order ID returned by the exchange.
  • pairSymbol - string
    The pair symbol in the format of base/quote. For example, BTC/USDC.

response structure: Promise<Order>, see Order for details.

const order = await cedeSDK.api.getOrder({ 
  exchangeInstanceId, 
  auth,
  pairSymbol: "ETH/USDT", 
  orderId: "461b392b-e786-4f86-ade2-b918db8aa9ff" 
});

Update order

To update an order, use:

method: updateOrder
params:

  • exchangeInstanceId - string
    The exchange instance ID.
  • auth - The authentication object for the exchange. See authentication section for details.
  • orderId - string
    The order ID returned by the exchange.
  • pairSymbol - string
    The pair symbol in the format of base/quote. For example, BTC/USDC.
  • orderSide - "buy" | "sell", optional
    The order side.
  • orderType - "market" | "limit", optional
    The order type.
  • price - string, optional
    The price in quote currency.
  • amount - string, optional
    The amount in base currency.

response structure: Promise<Order>, see Order for details.

💡

Be careful, the order ID might change after the update. If the exchange doesn't support updating orders, a new order will be created and the old one will be canceled.

const order = await cedeSDK.api.updateOrder({ 
  exchangeInstanceId,
  auth,
  pairSymbol: "ETH/USDT",
  orderId: "ce6a3ae3-0708-4d3a-831a-c88d78eb44d5",
  amount: "0.0002"
});

Cancel order

To cancel an order, use:

method: cancelOrder
params:

  • exchangeInstanceId - string
    The exchange instance ID.
  • auth - The authentication object for the exchange. See authentication section for details.
  • orderId - string
    The order ID returned by the exchange.
  • pairSymbol - string The pair symbol in the format of base/quote. For example, BTC/USDC. response structure: Promise<"canceled" | "already_filled">
const order = await cedeSDK.api.cancelOrder({ 
  exchangeInstanceId,
  auth,
  orderId: "13960869081",
  pairSymbol: "ETH/USDT"
});

Get open orders

To get open orders, use:

method: getOpenOrders
params:

  • exchangeInstanceId - string
    The exchange instance ID.
  • auth - The authentication object for the exchange. See authentication section for details.
  • pairSymbol - string
    The pair symbol in the format of base/quote. For example, BTC/USDC.
  • since - number, optional
    The timestamp to get orders since. Cede SDK doesn't unify this parameter, make sure to check the exchange API.
  • limit - number, optional
    The maximum number of orders to return. Cede SDK doesn't unify this parameter, make sure to check the exchange API.

response structure: Promise<Order[]>, see Order for details.

const orders = await cedeSDK.api.getOpenOrders({ 
  exchangeInstanceId,
  auth,
  pairSymbol: "ETH/USDT"
});

Get Open Future Positions

To get open future positions, use:

method: getOpenFuturePositions
params:

  • exchangeInstanceId - string
    The exchange instance ID.
  • auth - The authentication object for the exchange. See authentication section for details.

response structure: Promise<FuturePosition[]>, see FuturePosition for details.

const positions = await cedeSDK.api.getOpenFuturePositions({ exchangeInstanceId, auth });