smartapi-typescript
Version:
TypeScript library for Angel One SmartAPI broker API
69 lines (68 loc) • 1.98 kB
TypeScript
import { EventEmitter } from 'events';
/**
* SmartAPI Order Status WebSocket client
* Implementation based on Order Status WebSocket API documentation
* Used for real-time order updates
*/
export declare class OrderStatusWebSocket extends EventEmitter {
private jwtToken;
private wsUrl;
private ws;
private connectionState;
private reconnectAttempts;
private maxReconnectAttempts;
private reconnectInterval;
private heartbeatInterval;
private pingInterval;
private debug;
private isBrowser;
private clientCode;
/**
* Initialize a new OrderStatusWebSocket client
* @param jwtToken JWT token from login API (auth token)
* @param debug Enable debug logging
*/
constructor(jwtToken: string, debug?: boolean);
/**
* Log debug messages if debug mode is enabled
* @param message Message to log
* @param data Optional data to log
*/
private log;
/**
* Connect to the Order Status WebSocket server
*/
connect(): Promise<boolean>;
/**
* Attempt to reconnect to the WebSocket server
*/
private attemptReconnect;
/**
* Set up ping/pong heartbeat to keep the connection alive
* According to the documentation, clients should send a ping message every 10 seconds
*/
private setupHeartbeat;
/**
* Clear the heartbeat interval
*/
private clearHeartbeat;
/**
* Disconnect from the WebSocket server
*/
disconnect(): void;
/**
* Check if the WebSocket is currently connected
* @returns True if connected, false otherwise
*/
isConnected(): boolean;
/**
* Get the client code received in the connection response
* @returns Client code or empty string if not connected yet
*/
getClientCode(): string;
/**
* Set the JWT token (useful if token gets refreshed)
* @param jwtToken New JWT token
*/
setJwtToken(jwtToken: string): void;
}