Skip to main content

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

FieldTypeRequiredDescription
side'buy' | 'sell'YesOrder side
assetstringYesAsset symbol (e.g., 'BTC')
quantitynumberYesOrder quantity
pricenumberFor limitLimit price
orderType'limit' | 'market'NoDefault: 'limit'
timeInForce'GTC' | 'IOC' | 'FOK'NoDefault: 'GTC'
clientOrderIdstringNoCustom order ID

Order Status

StatusDescription
openOrder is active and unfilled
partially_filledOrder is partially filled
filledOrder is completely filled
cancelledOrder was cancelled
expiredOrder expired (for IOC/FOK)
rejectedOrder was rejected