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.
const order = await sdk.exchange.placeOrder({
marketId: 1,
isBuy: true,
amount: '1.0',
price: '2500.00',
orderType: 'LIMIT',
});Parameters: PlaceOrderRequest
| Field | Type | Required | Description |
|---|---|---|---|
marketId | number | Yes | Market ID (from sdk.info.getMarkets()) |
isBuy | boolean | Yes | true for buy, false for sell |
amount | string | Yes | Order amount as float string (e.g., "1.5") |
price | string | Yes | Order price as float string (e.g., "2500.00", "0" for market orders) |
orderType | OrderType | Yes | "LIMIT" or "MARKET" |
expiryTs | number | No | Expiry timestamp in ms (default: 30 days from now) |
isReduce | boolean | No | Reduce-only order (default: false) |
triggerPrice | string | No | Trigger price for conditional orders (float string) |
triggerCondition | TriggerCondition | No | "TP" or "SL" for conditional orders |
Returns: OrderResponse
{
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).
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
| Field | Type | Required | Description |
|---|---|---|---|
marketId | number | Yes | Market ID |
isBuy | boolean | Yes | true for long entry, false for short entry |
amount | string | Yes | Order amount as float string (e.g., "1.5") |
entryPrice | string | Yes | Entry price ("0" for market orders) |
takeProfitPrice | string | Yes | TP trigger and limit price |
stopLossPrice | string | Yes | SL trigger and limit price |
orderType | OrderType | No | Entry order type (default: "MARKET") |
Returns: PlaceOrderWithTPSLResponse
{
entry: OrderResponse,
takeProfit: OrderResponse,
stopLoss: OrderResponse,
}cancelOrder()
Cancel a specific order by ID.
await sdk.exchange.cancelOrder(12345);Parameters:
| Parameter | Type | Description |
|---|---|---|
orderId | number | Order ID to cancel |
Returns: CancelOrderResponse
{
message: 'order cancelled successfully';
}cancelAllOrders()
Cancel all orders for a specific market.
const result = await sdk.exchange.cancelAllOrders(1); // Market IDParameters:
| Parameter | Type | Description |
|---|---|---|
marketId | number | Market ID to cancel all orders for |
Returns: CancelAllOrdersResponse
{
cancelledOrderIds: [12345, 12346],
skippedOrdersWithReason: [],
}depositCollateral()
Deposit collateral to a subaccount.
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
| Field | Type | Required | Description |
|---|---|---|---|
subAccountId | string | Yes | Subaccount ID (e.g., "1_0xABC..._1") |
sessionKey | string | Yes | Signing address |
productId | number | Yes | Token product ID |
amount | string | Yes | Amount in raw units (big int string) |
nonce | number | Yes | Sequential nonce from sdk.info.getNonce() |
sender | string | Yes | ETH address of the sender |
destinationChainId | number | No | Default: 42161 (Arbitrum) |
chainId | number | No | Default: 1 (Ethereum mainnet) |
withdrawCollateral()
Withdraw collateral from a subaccount.
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
await sdk.exchange.placeOrder({
marketId: 1,
isBuy: true,
amount: '1.0',
price: '2500.00',
orderType: 'LIMIT',
});Market Order
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:
// 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).
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:
| Parameter | Type | Description |
|---|---|---|
request | PlaceOrderRequest | Standard order request |
maxPositionSize | number | Maximum allowed absolute position size (e.g., 10.0) |
Returns: OrderResponse | null — null if the order would exceed the position limit.