Skip to content

Exchange API

The Exchange API handles all write operations — placing/canceling orders and deposit/withdraw.

Access via sdk.exchange.

INFO

All exchange methods require authentication. Use HundredX.create() to initialize an authenticated SDK instance.

placeOrder()

Place an order. The SDK signs the order using your signing key and sends it with auth headers.

typescript
const order = await sdk.exchange.placeOrder({
  marketId: 1,
  isBuy: true,
  amount: '1.0',
  price: '2500.00',
  orderType: 'LIMIT',
});

Parameters: PlaceOrderRequest

FieldTypeRequiredDescription
marketIdnumberYesMarket ID (from sdk.info.getMarkets())
isBuybooleanYestrue for buy, false for sell
amountstringYesOrder amount as float string (e.g., "1.5")
pricestringYesOrder price as float string (e.g., "2500.00", "0" for market orders)
orderTypeOrderTypeYes"LIMIT" or "MARKET"
expiryTsnumberNoExpiry timestamp in ms (default: 30 days from now)
isReducebooleanNoReduce-only order (default: false)
triggerPricestringNoTrigger price for conditional orders (float string)
triggerConditionTriggerConditionNo"TP" or "SL" for conditional orders

Returns: OrderResponse

typescript
{
  id: 12345,
  subaccountId: '1_0xABC..._1',
  brokerId: 1,
  marketType: 'PERPETUAL',
  marketSymbol: 'ETH-USD',
  type: 'LIMIT',
  side: 'BUY',
  amountx18: '1000000000000000000',
  totalFilledx18: '0',
  pricex18: '2500000000000000000000',
  expiryTs: 1700000000000,
  status: 'OPEN',
  createdAt: '2024-01-01T00:00:00Z',
  updatedAt: '2024-01-01T00:00:00Z',
}

placeOrderWithTPSL()

Place an entry order with take-profit and stop-loss in one call. Sends three orders: entry, TP (reduce-only), and SL (reduce-only).

typescript
const result = await sdk.exchange.placeOrderWithTPSL({
  marketId: 1,
  isBuy: true,
  amount: '1.0',
  entryPrice: '2500.00',
  takeProfitPrice: '2600.00',
  stopLossPrice: '2450.00',
});

console.log(`Entry: ${result.entry.id}`);
console.log(`TP: ${result.takeProfit.id}`);
console.log(`SL: ${result.stopLoss.id}`);

Parameters: PlaceOrderWithTPSLRequest

FieldTypeRequiredDescription
marketIdnumberYesMarket ID
isBuybooleanYestrue for long entry, false for short entry
amountstringYesOrder amount as float string (e.g., "1.5")
entryPricestringYesEntry price ("0" for market orders)
takeProfitPricestringYesTP trigger and limit price
stopLossPricestringYesSL trigger and limit price
orderTypeOrderTypeNoEntry order type (default: "MARKET")

Returns: PlaceOrderWithTPSLResponse

typescript
{
  entry: OrderResponse,
  takeProfit: OrderResponse,
  stopLoss: OrderResponse,
}

cancelOrder()

Cancel a specific order by ID.

typescript
await sdk.exchange.cancelOrder(12345);

Parameters:

ParameterTypeDescription
orderIdnumberOrder ID to cancel

Returns: CancelOrderResponse

typescript
{
  message: 'order cancelled successfully';
}

cancelAllOrders()

Cancel all orders for a specific market.

typescript
const result = await sdk.exchange.cancelAllOrders(1); // Market ID

Parameters:

ParameterTypeDescription
marketIdnumberMarket ID to cancel all orders for

Returns: CancelAllOrdersResponse

typescript
{
  cancelledOrderIds: [12345, 12346],
  skippedOrdersWithReason: [],
}

depositCollateral()

Deposit collateral to a subaccount.

typescript
const nonce = await sdk.info.getNonce(sdk.subaccountId!);

await sdk.exchange.depositCollateral({
  subAccountId: sdk.subaccountId!,
  sessionKey: sdk.signingAddress!,
  productId: 74, // USDC on Arbitrum
  amount: '1000000000000000000', // Raw units (1 USDC = 1000000000000000000 for 18 decimals)
  nonce,
  sender: sdk.ethAddress!,
});

Parameters: DepositCollateralRequest

FieldTypeRequiredDescription
subAccountIdstringYesSubaccount ID (e.g., "1_0xABC..._1")
sessionKeystringYesSigning address
productIdnumberYesToken product ID
amountstringYesAmount in raw units (big int string)
noncenumberYesSequential nonce from sdk.info.getNonce()
senderstringYesETH address of the sender
destinationChainIdnumberNoDefault: 42161 (Arbitrum)
chainIdnumberNoDefault: 1 (Ethereum mainnet)

withdrawCollateral()

Withdraw collateral from a subaccount.

typescript
const nonce = await sdk.info.getNonce(sdk.subaccountId!);

await sdk.exchange.withdrawCollateral({
  subAccountId: sdk.subaccountId!,
  sessionKey: sdk.signingAddress!,
  productId: 74,
  amount: '500000',
  nonce,
  receiver: sdk.ethAddress!,
});

Parameters: WithdrawCollateralRequest — same as deposit but uses receiver instead of sender.

Order Types

Limit Order

typescript
await sdk.exchange.placeOrder({
  marketId: 1,
  isBuy: true,
  amount: '1.0',
  price: '2500.00',
  orderType: 'LIMIT',
});

Market Order

typescript
await sdk.exchange.placeOrder({
  marketId: 1,
  isBuy: true,
  amount: '1.0',
  price: '0',
  orderType: 'MARKET',
});

Take-Profit / Stop-Loss

Use placeOrderWithTPSL() for convenience, or place TP/SL orders individually:

typescript
// Take profit
await sdk.exchange.placeOrder({
  marketId: 1,
  isBuy: false, // Sell to take profit on a long
  amount: '1.0',
  price: '2700.00',
  orderType: 'LIMIT',
  isReduce: true,
  triggerPrice: '2700.00',
  triggerCondition: 'TP',
});

// Stop loss
await sdk.exchange.placeOrder({
  marketId: 1,
  isBuy: false,
  amount: '1.0',
  price: '2300.00',
  orderType: 'LIMIT',
  isReduce: true,
  triggerPrice: '2300.00',
  triggerCondition: 'SL',
});

Risk Management

sdk.safePlaceOrder()

Place an order with position size validation. Checks the current position size against a maximum before placing. Returns null if the order would exceed the limit.

Access via sdk.safePlaceOrder() (top-level, not sdk.exchange).

typescript
const order = await sdk.safePlaceOrder(
  {
    marketId: 1,
    isBuy: true,
    amount: '2.0',
    price: '2500.00',
    orderType: 'LIMIT',
  },
  10.0, // max position size
);

if (order) {
  console.log(`Order placed: ${order.id}`);
} else {
  console.log('Order rejected — position limit exceeded');
}

Parameters:

ParameterTypeDescription
requestPlaceOrderRequestStandard order request
maxPositionSizenumberMaximum allowed absolute position size (e.g., 10.0)

Returns: OrderResponse | nullnull if the order would exceed the position limit.

100x Exchange Market Maker SDK