Trading
The TypeScript SDK provides a TradeClient that wraps all order management and account endpoints. Every method is async and returns a typed result (or throws on error).
Quick Start
import { ClientConfig } from 'tigeropen';
import { TradeClient } from 'tigeropen';
const config = new ClientConfig({
propertiesFilePath: 'tiger_openapi_config.properties',
});
const tc = new TradeClient(config);
// Build and place a limit order
const order: Order = {
account: config.account,
symbol: 'AAPL',
secType: 'STK',
action: 'BUY',
orderType: 'LMT',
totalQuantity: 100,
limitPrice: 150.0,
timeInForce: 'DAY',
};
// Preview without placing
const preview = await tc.previewOrder(order);
console.log('Estimated commission:', preview.commission);
// Place the order
const result = await tc.placeOrder(order);
console.log('Order placed, ID:', result.id);Order Object
The Order interface represents an order. Build it as a plain object — TypeScript will enforce the shape at compile time.
Order Fields
| Field | Type | Description |
|---|---|---|
account | string | Account identifier |
symbol | string | Contract symbol, e.g. 'AAPL' |
secType | string | Security type: 'STK', 'OPT', 'FUT', 'WAR', 'IOPT' |
action | string | Order side: 'BUY' or 'SELL' |
orderType | string | 'MKT', 'LMT', 'STP', 'STP_LMT', 'TRAIL' |
totalQuantity | number | Number of shares/contracts |
limitPrice | number | Limit price (required for LMT / STP_LMT) |
auxPrice | number | Stop price (required for STP / STP_LMT) |
timeInForce | string | 'DAY', 'GTC', 'GTD' |
outsideRth | boolean | Allow execution outside regular trading hours |
expiry | string | Option expiry date ('YYYYMMDD') |
strike | number | Option strike price |
right | string | Option type: 'PUT' or 'CALL' |
Example Orders
// Stock limit buy
const limitOrder: Order = {
account: config.account,
symbol: 'AAPL',
secType: 'STK',
action: 'BUY',
orderType: 'LMT',
totalQuantity: 100,
limitPrice: 150.0,
timeInForce: 'DAY',
};
// Stock market sell
const marketOrder: Order = {
account: config.account,
symbol: 'TSLA',
secType: 'STK',
action: 'SELL',
orderType: 'MKT',
totalQuantity: 50,
timeInForce: 'DAY',
};
// Option limit buy (call)
const optionOrder: Order = {
account: config.account,
symbol: 'AAPL',
secType: 'OPT',
action: 'BUY',
orderType: 'LMT',
totalQuantity: 1,
limitPrice: 5.50,
timeInForce: 'DAY',
expiry: '20250117',
strike: 150.0,
right: 'CALL',
};Contract Query
getContract
async getContract(symbol: string, secType: string): Promise<ContractResponse>Returns detailed contract information for a single symbol.
| Parameter | Type | Required | Description |
|---|---|---|---|
symbol | string | Yes | Contract symbol, e.g. 'AAPL' |
secType | string | Yes | Security type: 'STK', 'OPT', 'FUT', 'WAR', 'IOPT' |
const contract = await tc.contract('AAPL', 'STK');
console.log('Exchange:', contract.exchange);getContracts
async getContracts(symbols: string[], secType: string): Promise<ContractResponse[]>Returns contract information for multiple symbols in a single request.
| Parameter | Type | Required | Description |
|---|---|---|---|
symbols | string[] | Yes | List of symbols |
secType | string | Yes | Security type for all symbols |
const contracts = await tc.contracts(['AAPL', 'TSLA', 'MSFT'], 'STK');getQuoteContract
async getQuoteContract(symbol: string, secType: string): Promise<ContractResponse>Returns derivative contract details (options or warrants) for the given underlying symbol.
| Parameter | Type | Required | Description |
|---|---|---|---|
symbol | string | Yes | Underlying symbol |
secType | string | Yes | Derivative type: 'OPT', 'WAR', 'IOPT' |
const quoteContract = await tc.quoteContract('AAPL', 'OPT');Order Management
placeOrder
async placeOrder(order: Order): Promise<PlaceOrderResponse>Submits an order to the exchange. Returns the server-assigned order ID on success.
| Parameter | Type | Required | Description |
|---|---|---|---|
order | Order | Yes | Order details |
const result = await tc.placeOrder(limitOrder);
console.log('Order ID:', result.id);
// { id: 123456789, status: 'Submitted' }previewOrder
async previewOrder(order: Order): Promise<PreviewOrderResponse>Validates an order and returns estimated commission and margin impact without actually placing it.
const preview = await tc.previewOrder(limitOrder);
console.log('Commission:', preview.commission);
console.log('Margin impact:', preview.marginImpact);
// { commission: 1.0, marginImpact: 15000.0, valid: true }modifyOrder
async modifyOrder(id: number, order: Order): Promise<ModifyOrderResponse>Modifies the price or quantity of an existing open order.
| Parameter | Type | Required | Description |
|---|---|---|---|
id | number | Yes | Order ID to modify |
order | Order | Yes | Updated order parameters |
// Change limit price from 150 to 148
const updatedOrder = { ...limitOrder, limitPrice: 148.0 };
const modResult = await tc.modifyOrder(123456789, updatedOrder);cancelOrder
async cancelOrder(id: number): Promise<CancelOrderResponse>Cancels an open order by ID.
| Parameter | Type | Required | Description |
|---|---|---|---|
id | number | Yes | Order ID to cancel |
const cancelResult = await tc.cancelOrder(123456789);Order Query
getOrders
async getOrders(): Promise<OrderResponse[]>Returns all orders (pending, filled, and cancelled) for the current trading day.
const orders = await tc.orders();
console.log(`Total orders today: ${orders.length}`);getActiveOrders
async getActiveOrders(): Promise<OrderResponse[]>Returns only orders that are currently pending (submitted but not yet filled or cancelled).
const activeOrders = await tc.activeOrders();
console.log('Open orders:', activeOrders.length);getInactiveOrders
async getInactiveOrders(): Promise<OrderResponse[]>Returns orders that have been cancelled or have expired.
const inactiveOrders = await tc.inactiveOrders();getFilledOrders
async getFilledOrders(): Promise<OrderResponse[]>Returns orders that have been fully or partially filled.
const filledOrders = await tc.filledOrders();
let totalCost = 0;
for (const o of filledOrders) {
totalCost += o.avgFillPrice * o.filledQuantity;
}Positions and Assets
getPositions
async getPositions(): Promise<PositionResponse[]>Returns all current open positions (symbol, quantity, average cost, market value, unrealized P&L).
const positions = await tc.positions();
for (const p of positions) {
console.log(`${p.symbol}: qty=${p.quantity} unrealizedPnl=${p.unrealizedPnl}`);
}getAssets
async getAssets(): Promise<AssetResponse>Returns account asset summary (net liquidation value, cash balance, buying power, margin usage).
const assets = await tc.assets();
console.log('Net liquidation value:', assets.netLiquidation);
console.log('Buying power:', assets.buyingPower);getPrimeAssets
async getPrimeAssets(): Promise<PrimeAssetResponse>Returns consolidated asset summary for prime (multi-currency) accounts, aggregated across all sub-accounts.
const primeAssets = await tc.primeAssets();getOrderTransactions
async getOrderTransactions(id: number): Promise<TransactionResponse[]>Returns the individual fill records (executions) associated with a specific order.
| Parameter | Type | Required | Description |
|---|---|---|---|
id | number | Yes | Order ID |
const transactions = await tc.orderTransactions(123456789);
for (const tx of transactions) {
console.log(`Fill: price=${tx.price} qty=${tx.quantity} at ${tx.timestamp}`);
}Generic Raw API Call
When the SDK has not yet wrapped a specific API endpoint, use the HttpClient directly:
import { ClientConfig } from 'tigeropen';
import { HttpClient } from 'tigeropen-node-sdk/client';
const config = new ClientConfig({
propertiesFilePath: 'tiger_openapi_config.properties',
});
const httpClient = new HttpClient(config);
// Pass the API method name and a JSON parameter string
const resp = await httpClient.execute('market_state', JSON.stringify({ market: 'US' }));
console.log('Raw response:', resp);Updated 6 days ago
