ExecutionClient
The ExecutionClient handles all order-related operations including creation, amendment, cancellation, and status queries.
Creating Orders
Single Order
const order = await client.execution.createOrder({
side: 'buy',
asset: 'BTC',
quantity: 1.0,
price: 50000,
orderType: 'limit', // 'limit' | 'market'
timeInForce: 'GTC', // 'GTC' | 'IOC' | 'FOK'
clientOrderId: 'my-123', // Optional custom ID
});
console.log(order);
// {
// id: 'ord_abc123',
// clientOrderId: 'my-123',
// side: 'buy',
// asset: 'BTC',
// quantity: '1.0',
// filledQuantity: '0',
// price: '50000',
// orderType: 'limit',
// timeInForce: 'GTC',
// status: 'open',
// createdAt: '2024-01-15T10:30:00Z',
// updatedAt: '2024-01-15T10:30:00Z'
// }
Batch Orders
const result = await client.execution.createBatchOrders([
{ side: 'buy', asset: 'BTC', quantity: 0.5, price: 49000 },
{ side: 'buy', asset: 'BTC', quantity: 0.5, price: 48000 },
{ side: 'sell', asset: 'BTC', quantity: 1.0, price: 52000 },
]);
console.log(`Created: ${result.successful.length}`);
console.log(`Failed: ${result.failed.length}`);
Listing Orders
// List open orders
const openOrders = await client.execution.listOrders({
statuses: 'open,partially_filled',
});
// Filter by asset and side
const btcBuys = await client.execution.listOrders({
asset: 'BTC',
side: 'buy',
statuses: 'open',
page: 1,
limit: 50,
});
// Paginated response
console.log(btcBuys);
// {
// data: [...orders],
// total: 150,
// page: 1,
// limit: 50,
// hasMore: true
// }
Getting Order Details
// By order ID
const order = await client.execution.getOrder('ord_abc123');
// By client order ID
const order = await client.execution.getOrderByClientId('my-custom-id');
Amending Orders
const amended = await client.execution.amendOrder('ord_abc123', {
quantity: 2.0, // New quantity
price: 51000, // New price
});
Cancelling Orders
Single Order
await client.execution.cancelOrder('ord_abc123');
Cancel All Orders
// Cancel all orders
await client.execution.cancelAllOrders();
// Cancel all BTC orders
await client.execution.cancelAllOrders({ asset: 'BTC' });
// Cancel all buy orders
await client.execution.cancelAllOrders({ side: 'buy' });
// Cancel all BTC sell orders
await client.execution.cancelAllOrders({ asset: 'BTC', side: 'sell' });
Order Fills
const fills = await client.execution.getOrderFills('ord_abc123');
for (const fill of fills) {
console.log(`Filled ${fill.quantity} @ ${fill.price}`);
console.log(`Fee: ${fill.fee} ${fill.feeCurrency}`);
}
Types
import type {
Order,
OrderFill,
CreateOrderParams,
AmendOrderParams,
ListOrdersParams,
OrderSide,
OrderType,
OrderStatus,
TimeInForce,
} from 'zenotc';
CreateOrderParams
| Field | Type | Required | Description |
|---|---|---|---|
side | 'buy' | 'sell' | Yes | Order side |
asset | string | Yes | Asset symbol (e.g., 'BTC') |
quantity | number | Yes | Order quantity |
price | number | For limit | Limit price |
orderType | 'limit' | 'market' | No | Default: 'limit' |
timeInForce | 'GTC' | 'IOC' | 'FOK' | No | Default: 'GTC' |
clientOrderId | string | No | Custom order ID |
Order Status
| Status | Description |
|---|---|
open | Order is active and unfilled |
partially_filled | Order is partially filled |
filled | Order is completely filled |
cancelled | Order was cancelled |
expired | Order expired (for IOC/FOK) |
rejected | Order was rejected |