Connection and Callbacks
Example context
import { createClientConfig, PushClient } from '@tigeropenapi/tigeropen';
const config = createClientConfig({
tigerId: 'your_tiger_id',
privateKey: 'your_private_key',
account: 'your_account',
});
const pushClient = new PushClient(config);
// Set up callback functions
pushClient.setCallbacks({
onConnect: () => {
console.log('Connected');
// Subscribe after connection is established
pushClient.subscribeQuote(['AAPL', '00700']);
},
onQuote: (data) => {
console.log('Quote update:', data.symbol, data.latestPrice);
},
onTick: (data) => {
console.log('Tick update:', data.symbol, data.volume);
},
onKline: (data) => {
console.log('Kline update:', data.symbol);
},
onDisconnect: () => {
console.log('Disconnected');
},
onError: (err) => {
console.error('Error:', err.message);
},
});
// Initiate connection
pushClient.connect();state
stateSignature
get state(): ConnectionStatePurpose
Reads the current push connection state.
Parameters, defaults, and constraints
No parameters.
Returns
ConnectionState
Possible values: ConnectionState.Disconnected, ConnectionState.Connecting, ConnectionState.Connected
Type-checked example
const result = pushClient.state;
console.log(result);setCallbacks
setCallbacksSignature
setCallbacks(cb: Callbacks): voidPurpose
Replaces the current push callback set. All push data is received asynchronously through callbacks.
Parameters, defaults, and constraints
| Parameter | Type | Required | SDK default | Constraints |
|---|---|---|---|---|
cb | Callbacks | Yes | None | — |
cb.onQuote | ((data: QuoteData) => void) | undefined | No | None | — |
cb.onTick | ((data: TradeTickData) => void) | undefined | No | None | — |
cb.onDepth | ((data: QuoteDepthData) => void) | undefined | No | None | — |
cb.onOption | ((data: QuoteData) => void) | undefined | No | None | — |
cb.onFuture | ((data: QuoteData) => void) | undefined | No | None | — |
cb.onKline | ((data: KlineData) => void) | undefined | No | None | — |
cb.onStockTop | ((data: StockTopData) => void) | undefined | No | None | — |
cb.onOptionTop | ((data: OptionTopData) => void) | undefined | No | None | — |
cb.onFullTick | ((data: TickData) => void) | undefined | No | None | — |
cb.onQuoteBBO | ((data: QuoteData) => void) | undefined | No | None | — |
cb.onAsset | ((data: AssetData) => void) | undefined | No | None | — |
cb.onPosition | ((data: PositionData) => void) | undefined | No | None | — |
cb.onOrder | ((data: OrderStatusData) => void) | undefined | No | None | — |
cb.onTransaction | ((data: OrderTransactionData) => void) | undefined | No | None | — |
cb.onConnect | (() => void) | undefined | No | None | — |
cb.onDisconnect | (() => void) | undefined | No | None | — |
cb.onError | ((err: Error) => void) | undefined | No | None | — |
cb.onKickout | ((message: string) => void) | undefined | No | None | — |
Returns
void
Type-checked example
pushClient.setCallbacks({
onConnect: () => {
console.log('Connected');
pushClient.subscribeQuote(['AAPL']);
},
onQuote: (data) => {
console.log(`${data.symbol} latest: ${data.latestPrice}`);
},
onError: (err) => {
console.error('Push error:', err.message);
},
});connect
connectSignature
connect(): Promise<void>Purpose
Connects to the push server and authenticates. Triggers the onConnect callback upon success.
Parameters, defaults, and constraints
No parameters.
Returns
Promise<void>Type-checked example
await pushClient.connect();disconnect
disconnectSignature
disconnect(): voidPurpose
Closes the push connection and stops automatic reconnect. Triggers the onDisconnect callback.
Parameters, defaults, and constraints
No parameters.
Returns
void
Type-checked example
pushClient.disconnect();getSubscriptions
getSubscriptionsSignature
getSubscriptions(): Map<SubjectType, string[]>Purpose
Gets the current market data subscriptions.
Parameters, defaults, and constraints
No parameters.
Returns
Map<SubjectType, string[]>
Type-checked example
const subs = pushClient.getSubscriptions();
// Map { 'Quote' => ['AAPL', '00700'], 'Tick' => ['AAPL'] }
console.log(subs);getAccountSubscriptions
getAccountSubscriptionsSignature
getAccountSubscriptions(): Map<SubjectType, string>Purpose
Gets the current account push subscriptions.
Parameters, defaults, and constraints
No parameters.
Returns
Map<SubjectType, string>
Type-checked example
const subs = pushClient.getAccountSubscriptions();
console.log(subs);Updated 1 day ago
