import { WebSocket } from 'ws'; /** Common response format. */ interface Response { /** ok / error. */ s: string; /** This is the code to identify specific responses. */ code?: number; /** This is the message to identify the specific error responses. */ message?: string; } /** Attributes required for authorization of all requests. */ interface Authorization { /** This is the app_id which you have received after creating the app. */ app_id: string; /** This value will be used for all the requests. */ access_token: string; } /** Root URL for Market data notifications. */ declare const MARKET_DATA_URL: string; /** Root URL for Order update notifications. */ declare const ORDER_UPDATE_URL: string; /** Common notification format. */ type Notification = Response; /** Update for order placed by the user in the current trading day. */ interface OrderUpdate { /** The unique order id assigned for each order. */ id: string; /** The order id provided by the exchange. */ exchOrdId: string; /** The symbol for which order is placed. */ symbol: string; /** Fytoken is a unique identifier for every symbol. */ fyToken: string; /** The segment this order is placed in. */ segment: string; /** Exchange instrument type. */ instrument: string; /** The type of order. */ type: number; /** The order is buy or sell. */ side: number; /** The product type. */ productType: string; /** The status of the order. */ status: number; /** The order number and status of the order. */ orderNumStatus: string; /** True when placing AMO order. */ offlineOrder: boolean; /** The original order qty. */ qty: number; /** The remaining qty. */ remainingQuantity: number; /** The filled qty after partial trades. */ filledQty: number; /** The limit price for the order. */ limitPrice: number; /** The stop price for the order. */ stopPrice: number; /** Disclosed quantity. */ discloseQty: number; /** Remaining disclosed quantity. */ dqQtyRem: number; /** Day or IOC. */ orderValidity: string; /** The order time as per DD-MMM-YYYY hh:mm:ss in IST. */ orderDateTime: string; /** The parent order id will be provided only for applicable orders. */ parentId?: string; /** The average traded price for the order. */ tradedPrice: number; /** This is used to sort the orders based on the time. */ slNo: number; /** The error messages are shown here. */ message: string; } /** String notification on order update. */ interface OrderUpdateNotification extends Notification { /** Websocket type [1]. */ ws_type?: number; /** Data for the notification. */ d?: OrderUpdate; } /** Header for each binary message. */ interface Header { /** Fytoken is a unique identifier for every symbol. */ token: BigInt; /** Timestamp sent by exchange (UNIX epoch). */ tt: number; /** 7202: OI data (NSE FO/CD, MCX), 7207/7208: NSE, BSE (indices/data), 31038: MCX. */ fyCode: number; /** Market status flag? */ marketStat: number; /** Packet length, including header? */ pktlen: number; /** Has L2 data (market depth)? */ L2: number; } /** Open interest data (fyCode === 7202). */ interface OiData { /** Open interest. */ oi: number; /** Previous day open interest. */ pdoi: number; } /** Common data (fyCode !== 7202). */ interface CommonData { /** Price conversion, divisor for all prices. */ price_conv: number; /** LTP is the price from which the next sale of the stocks happens. */ ltp: number; /** Price at market opening time. */ open_price: number; /** Highest price for the day. */ high_price: number; /** Lowest price for the day. */ low_price: number; /** Close price of the previous trading day. */ prev_close_price: number; /** Open price (1 minute). */ o: number; /** High price (1 minute). */ h: number; /** Low price (1 minute). */ l: number; /** Close price (1 minute). */ c: number; /** Volume (1 minute). */ v: BigInt; /** Open interest. */ oi: BigInt; /** Previous day open interest. */ pdoi: BigInt; } /** Additional data (fyCode === 7208, 31038). */ interface L1Data { /** Last traded quantity. */ LTQ: number; /** Last traded time (UNIX epoch). */ L2_LTT: number; /** Average traded price. */ ATP: number; /** Today's volume. */ volume: number; /** Total buy quantity. */ tot_buy: BigInt; /** Total sell quantity. */ tot_sell: BigInt; /** Highest bid price. */ bid: number; /** Lowest ask price. */ ask: number; } /** Open buy/sell orders at a particular price (L2 === 1). */ interface L2MarketOffer { /** Bid/ask price. */ price: number; /** Bid/ask volume. */ volume: number; /** Number of orders. */ ord: number; } /** Market depth data, 5 rows (L2 === 1). */ interface L2Data { /** Bidding price along with volume and total number of orders. */ bids: L2MarketOffer[]; /** Offer price with volume and total number of orders. */ asks: L2MarketOffer[]; } /** Market data (oi/quote/depth) for symbols subscribed by the user. */ interface MarketData extends Header, CommonData, L1Data, L2Data { } /** Binary notification on Market data. */ interface MarketDataNotification extends Notification { /** Data for the notification. */ d?: MarketData; } /** * Notified function. * @param notification notification */ type OnNotification = (notification: Notification) => void; /** * Order update notified function. * @param notification notification */ type OnOrderUpdateNotification = (notification: OrderUpdateNotification) => void; /** * Market data notified function. * @param notification notification */ type OnMarketDataNotification = (notification: MarketDataNotification) => void; /** Handler for reciever which has passed (resolved). */ type OnResolve = (response: Response) => void; /** Handler for reciever which has failed (rejected). */ type OnReject = (error: Error) => void; /** Recieve response to a request, which can pass or fail. */ interface Reciever { /** Pass (resolve) handler for reciever. */ resolve: OnResolve; /** Fail (reject) handler for reciever. */ reject: OnReject; } /** * Provides the API for creating and managing a WebSocket connection to * a server, as well as for sending and receiving data on the connection. */ declare class Connection extends WebSocket { /** To recieve response to a request. */ recievers: Reciever[]; } /** * Connect to Order update URL with WebSocket. * @param auth authorization \{app_id, access_token\} * @param fn notified function * @returns WebSocket connection */ declare function connectOrderUpdate(auth: Authorization, fn: OnOrderUpdateNotification): Promise; /** * Subscribe to order update. * @param conn websocket connection */ declare function subscribeOrderUpdate(conn: Connection): Promise; /** * Unsubscribe to order update. * @param conn websocket connection */ declare function unsubscribeOrderUpdate(conn: Connection): Promise; /** * Connect to Market data URL with WebSocket. * @param auth authorization \{app_id, access_token\} * @param fn notified function * @returns WebSocket connection */ declare function connectMarketData(auth: Authorization, fn: OnMarketDataNotification): Promise; /** * Subscribe to market quote. * @param conn websocket connection * @param symbols list of symbols */ declare function subscribeMarketQuote(conn: Connection, symbols: string[]): Promise; /** * Subscribe to market depth. * @param conn websocket connection * @param symbols list of symbols */ declare function subscribeMarketDepth(conn: Connection, symbols: string[]): Promise; /** * Unsubscribe to market quote. * @param conn websocket connection * @param symbols list of symbols */ declare function unsubscribeMarketQuote(conn: Connection, symbols: string[]): Promise; /** * Unsubscribe to market depth. * @param conn websocket connection * @param symbols list of symbols */ declare function unsubscribeMarketDepth(conn: Connection, symbols: string[]): Promise; export { type Authorization, type CommonData, Connection, type Header, type L1Data, type L2Data, type L2MarketOffer, MARKET_DATA_URL, type MarketData, type MarketDataNotification, type Notification, ORDER_UPDATE_URL, type OiData, type OnMarketDataNotification, type OnNotification, type OnOrderUpdateNotification, type OnReject, type OnResolve, type OrderUpdate, type OrderUpdateNotification, type Reciever, type Response, connectMarketData, connectOrderUpdate, subscribeMarketDepth, subscribeMarketQuote, subscribeOrderUpdate, unsubscribeMarketDepth, unsubscribeMarketQuote, unsubscribeOrderUpdate };