smartapi-typescript
Version:
TypeScript library for Angel One SmartAPI broker API
230 lines (229 loc) • 9.33 kB
TypeScript
import { AxiosInstance } from 'axios';
import { ApiResponse, HistoricalDataParams, CandleData, PostbackData, MarketQuoteRequest, MarketQuoteResponse, OptionGreeksParams, OptionGreekData, GainersLosersParams, GainersLosersResponse, OIData } from '../../types';
import { Auth } from '../auth';
/**
* Miscellaneous market data module for SmartAPI
* Handles data operations like historical candles, LTP, quotes, etc.
*/
export declare class MarketData {
private auth;
private httpClient;
private debug;
/**
* Initialize market data module
*/
constructor(auth: Auth, httpClient: AxiosInstance, debug?: boolean);
/**
* Log debug messages if debug mode is enabled
*/
private log;
/**
* Get market quotes using the new Live Market Data API
* Supports three modes: LTP, OHLC, FULL
* Supports up to 50 symbols in a single request
*
* @param request Market quote request with mode and exchangeTokens
* @param options Network configuration options
* @returns Market quote data
*/
getMarketQuote(request: MarketQuoteRequest, options?: {
clientLocalIP?: string;
clientPublicIP?: string;
macAddress?: string;
}): Promise<ApiResponse<MarketQuoteResponse>>;
/**
* Get LTP data using the new Live Market Data API
* Convenience method that uses the getMarketQuote with LTP mode
*
* @param exchangeTokenMap Map of exchange to tokens (e.g., {"NSE": ["3045"], "BSE": ["500112"]})
* @param options Network configuration options
* @returns LTP data
*/
getLTPData(exchangeTokenMap: Record<string, string[]>, options?: {
clientLocalIP?: string;
clientPublicIP?: string;
macAddress?: string;
}): Promise<ApiResponse<MarketQuoteResponse>>;
/**
* Get OHLC data using the new Live Market Data API
* Convenience method that uses the getMarketQuote with OHLC mode
*
* @param exchangeTokenMap Map of exchange to tokens (e.g., {"NSE": ["3045"], "BSE": ["500112"]})
* @param options Network configuration options
* @returns OHLC data
*/
getOHLCData(exchangeTokenMap: Record<string, string[]>, options?: {
clientLocalIP?: string;
clientPublicIP?: string;
macAddress?: string;
}): Promise<ApiResponse<MarketQuoteResponse>>;
/**
* Get full market data using the new Live Market Data API
* Convenience method that uses the getMarketQuote with FULL mode
*
* @param exchangeTokenMap Map of exchange to tokens (e.g., {"NSE": ["3045"], "BSE": ["500112"]})
* @param options Network configuration options
* @returns Full market data including depth
*/
getFullQuote(exchangeTokenMap: Record<string, string[]>, options?: {
clientLocalIP?: string;
clientPublicIP?: string;
macAddress?: string;
}): Promise<ApiResponse<MarketQuoteResponse>>;
/**
* Get last traded price for a symbol (Legacy method)
* @deprecated Use getLTPData() instead which supports multiple symbols
* @param exchange Exchange name (e.g., NSE, BSE)
* @param symbolToken Symbol token
* @param tradingSymbol Trading symbol
* @param options Network configuration options
* @returns LTP data
*/
getLTP(exchange: string, symbolToken: string, tradingSymbol: string, options?: {
clientLocalIP?: string;
clientPublicIP?: string;
macAddress?: string;
}): Promise<ApiResponse>;
/**
* Get last traded price for multiple symbols (Legacy method)
* @deprecated Use getLTPData() instead which has better batching support
* @param instruments Array of instruments (exchange, symboltoken, tradingsymbol)
* @param options Network configuration options
* @returns LTP data for multiple symbols
*/
getMultiLTP(instruments: Array<{
exchange: string;
symboltoken: string;
tradingsymbol: string;
}>, options?: {
clientLocalIP?: string;
clientPublicIP?: string;
macAddress?: string;
}): Promise<ApiResponse>;
/**
* Get comprehensive quote for symbols (Legacy method)
* @deprecated Use getFullQuote() instead which supports multiple symbols
* @param exchange Exchange name (e.g., NSE, BSE)
* @param symbolToken Symbol token
* @param tradingSymbol Trading symbol
* @param options Network configuration options
* @returns Quote data
*/
getQuote(exchange: string, symbolToken: string, tradingSymbol: string, options?: {
clientLocalIP?: string;
clientPublicIP?: string;
macAddress?: string;
}): Promise<ApiResponse>;
/**
* Get market quotes for multiple symbols (Legacy method)
* @deprecated Use getFullQuote() instead which has better batching support
* @param instruments Array of instruments (exchange, token)
* @param options Network configuration options
* @returns Market quotes for multiple symbols
*/
getMultiQuotes(instruments: Array<{
exchange: string;
symboltoken: string;
tradingsymbol: string;
}>, options?: {
clientLocalIP?: string;
clientPublicIP?: string;
macAddress?: string;
}): Promise<ApiResponse>;
/**
* Get historical candle data
* @param params Historical data parameters
* @param options Network configuration options
* @returns Historical candle data
*/
getHistoricalData(params: HistoricalDataParams, options?: {
clientLocalIP?: string;
clientPublicIP?: string;
macAddress?: string;
}): Promise<ApiResponse<CandleData[]>>;
/**
* Get historical candle data with automatic pagination
* Handles large date ranges by splitting into smaller chunks
* @param params Historical data parameters
* @param maxCandlesPerRequest Maximum number of candles per request (default: 2000)
* @param options Network configuration options
* @returns Consolidated historical candle data
*/
getHistoricalDataPaginated(params: HistoricalDataParams, maxCandlesPerRequest?: number, options?: {
clientLocalIP?: string;
clientPublicIP?: string;
macAddress?: string;
}): Promise<ApiResponse<CandleData[]>>;
/**
* Get historical Open Interest data for F&O contracts
* Provides historical OI data for live F&O contracts
*
* @param params Historical data parameters (same as for getHistoricalData)
* @param options Network configuration options
* @returns Historical OI data
*/
getHistoricalOIData(params: HistoricalDataParams, options?: {
clientLocalIP?: string;
clientPublicIP?: string;
macAddress?: string;
}): Promise<ApiResponse<OIData[]>>;
/**
* Get historical Open Interest data with automatic pagination
* Handles large date ranges by splitting into smaller chunks
*
* @param params Historical data parameters
* @param maxEntriesPerRequest Maximum number of entries per request based on interval
* @param options Network configuration options
* @returns Consolidated historical OI data
*/
getHistoricalOIDataPaginated(params: HistoricalDataParams, maxEntriesPerRequest?: number, options?: {
clientLocalIP?: string;
clientPublicIP?: string;
macAddress?: string;
}): Promise<ApiResponse<OIData[]>>;
/**
* Set up webhook configuration for real-time order updates
*
* Note: The actual webhook URL must be registered when creating your API key in the Angel One dashboard.
* This method provides information about webhook behavior and requirements.
*
* @returns Object with webhook information and requirements
*/
getWebhookInfo(): ApiResponse<{
url: string | null;
}>;
/**
* Parse webhook data received from Angel One postback
* This is meant to be used in your webhook endpoint implementation
*
* @param data Raw webhook payload as received from Angel One
* @returns Parsed PostbackData object
*/
static parseWebhookData(data: any): PostbackData;
/**
* Get Option Greeks (Delta, Gamma, Theta, Vega) and Implied Volatility
* for specified underlying and expiry date
*
* @param params Parameters containing the underlying name and expiry date
* @param options Network configuration options
* @returns Option greeks data for multiple strike prices
*/
getOptionGreeks(params: OptionGreeksParams, options?: {
clientLocalIP?: string;
clientPublicIP?: string;
macAddress?: string;
}): Promise<ApiResponse<OptionGreekData[]>>;
/**
* Get Top Gainers/Losers in derivatives segment
* Provides data about top gainers and losers in derivatives segment based on price change or open interest.
*
* @param params Parameters containing datatype and expirytype
* @param options Network configuration options
* @returns Top gainers or losers data based on the specified parameters
*/
getGainersLosers(params: GainersLosersParams, options?: {
clientLocalIP?: string;
clientPublicIP?: string;
macAddress?: string;
}): Promise<ApiResponse<GainersLosersResponse>>;
}