Connection and Callbacks
Example context
import { createClientConfig, PushClient } from '@tigeropenapi/tigeropen';
const config = createClientConfig();
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.ticks.length);
},
onKline: (data) => {
console.log('Kline update:', data.symbol);
},
onDisconnect: () => {
console.log('Disconnected');
},
onError: (err) => {
console.error('Error:', err.message);
},
});
// Initiate connection
await 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 | The internal push module exports Callbacks, but package exports exposes only the root entry and that entry does not re-export the type, so there is currently no supported public import path; callback parameters in an object literal are still inferred by setCallbacks |
cb.onQuote | Quote callback | No | None | Parameter type is contextually inferred |
cb.onTick | SDK-decoded tick callback | No | None | Parameter type is contextually inferred |
cb.onDepth | Market-depth callback | No | None | Parameter type is contextually inferred |
cb.onOption | Option-quote callback | No | None | Parameter type is contextually inferred |
cb.onFuture | Futures-quote callback | No | None | Parameter type is contextually inferred |
cb.onKline | Kline callback | No | None | Parameter type is contextually inferred |
cb.onStockTop | Stock-ranking callback | No | None | Parameter type is contextually inferred |
cb.onOptionTop | Option-ranking callback | No | None | Parameter type is contextually inferred |
cb.onFullTick | Full-tick callback | No | None | Parameter type is contextually inferred |
cb.onQuoteBBO | BBO quote callback | No | None | This API is real; the current dispatcher does not branch on QuoteData.type, so BASIC and BBO payloads with the Quote data type both go to onQuote |
cb.onAsset | Asset callback | No | None | Parameter type is contextually inferred |
cb.onPosition | Position callback | No | None | Parameter type is contextually inferred |
cb.onOrder | Order-status callback | No | None | Parameter type is contextually inferred |
cb.onTransaction | Transaction callback | No | None | Parameter type is contextually inferred |
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. Calling disconnect() invokes onDisconnect synchronously.
Parameters, defaults, and constraints
No parameters.
Returns
void
Type-checked example
pushClient.disconnect();getSubscriptions
getSubscriptionsSignature
getSubscriptions(): Map<SubjectType, string[]>Purpose
Gets the market-data subscriptions recorded in client memory. After an automatic reconnect succeeds, the SDK uses these records to resubscribe.
Only ordinary symbol-based market-data subscriptions can be restored correctly. The HK whole-market quote subscription created by subscribeMarket and ranking subscriptions do not retain the complete market information needed for correct restoration, so resubscribe explicitly after a reconnect. The cached HK value is a market argument, not a list of subscribed symbols.
Parameters, defaults, and constraints
No parameters.
Returns
Map<SubjectType, string[]>
Type-checked example
const subs = pushClient.getSubscriptions();
// Map { SubjectType.Quote => ['AAPL', '00700'], SubjectType.Tick => ['AAPL'] }
console.log(subs);getAccountSubscriptions
getAccountSubscriptionsSignature
getAccountSubscriptions(): Map<SubjectType, string>Purpose
Gets the account push subscriptions recorded in client memory. After an automatic reconnect succeeds, the SDK uses these records to resubscribe.
Parameters, defaults, and constraints
No parameters.
Returns
Map<SubjectType, string>
Type-checked example
const subs = pushClient.getAccountSubscriptions();
console.log(subs);Updated about 1 month ago
