Node JS API Document
Node JS API Document
Contents
Login & logout
login
logout
Symbols
searchscrip
get_security_info
get_quotes
get_time_price_series
get_option_chain
place_order
modify_order
cancel_order
exit_order
get_orderbook
get_tradebook
get_singleorderhistory
get_holdings
get_positions
get_limits
Websocket API
start_websocket
subscribe
unsubscribe
Example
getting started
Market Functions
Orders and Trade
Login
Connect to the broker, only once this function has returned successfully can any other operations be
performed
No Parameters
place_order
cancel_order(orderno)
Cancel an order
exit_order(orderno)
prd String False Allowed for only H and B products (Cover order and
bracket order)
Order Book
No Parameters
Trade Book
No Parameters
History an order
get_holdings(product_type)
No Parameters
get_limits
product_type String True retrieves the delivery holdings or for a given product
segment String True CM / FO / FX
exchange String True Exchange NSE/BSE/MCX
-------------------------
Cash Primary Fields----
---------------------------
cash String True Cash Margin available
payin String True Total Amount transferred using Payins today
payout String True Total amount requested for withdrawal today
-------------------------
Cash Additional Fields-
------------------------------
brkcollamt String True Prevalued Collateral Amount
unclearedcash String True Uncleared Cash (Payin through cheques)
daycash String True Additional leverage amount /
-------------------------
Additional Risk Limits--
-------------------------
turnoverlmt String True
pendordvallmt String True
-------------------------
Additional Risk
Indicators-----------------
----------
turnover String True Turnover
pendordval String True Pending Order value
-------------------------
Margin used detailed
breakup fields------------
-------------
rzpnl_e_i String True Current realized PNL (Equity Intraday)
searchscrip(exchange, searchtext):
get_security_info(exchange, token):
Note: Please ensure that only a single web-socket connection is started. Opening multiple web-
socket connections is not supported by the API. Starts the websocket
subscribe_orders()
Subscription Acknowledgement:
reporttype Order event for which this message is sent out. (Fill,
Rejected, Cancelled)
trantype Order transaction type, buy or sell
prctyp Order price type (LMT, MKT, SL-LMT, SL-MKT)
ret Order retention type (DAY, EOS, IOC,...)
fillshares Total Filled shares for this order
avgprc Average fill price
fltm Fill Time(present only when reporttype is Fill)
flid Fill ID (present only when reporttype is Fill)
flqty Fill Qty(present only when reporttype is Fill)
flprc Fill Price(present only when reporttype is Fill)
rejreason Order rejection reason, if rejected
exchordid Exchange Order ID
cancelqty Canceled quantity, in case of canceled order
remarks User added tag, while placing order
dscqty Disclosed quantity
trgprc Trigger price for SL orders
snonum This will be present for child orders in case of cover and
bracket orders, if present needs to be sent during exit
snoordt This will be present for child orders in case of cover and
bracket orders, it will indicate whether the order is profit
or stoploss
blprc This will be present for cover and bracket parent order.
This is the differential stop loss trigger price to be entered.
bpprc This will be present for bracket parent order. This is the
differential profit price to be entered.
trailprc This will be present for cover and bracket parent order.
This is required if trailing ticks is to be enabled.
exch_tm This will have the exchange update time
subscribe([instruments])
t='tk' is sent once on subscription for each instrument. This will have all the fields with the
most recent value thereon t='tf' is sent for fields that have changed.
For example
quote event: 03-12-2021 11:54:44{'t': 'tk', 'e': 'NSE', 'tk': '11630', 'ts': 'NTPC-EQ', 'pp':
'2', 'ls': '1', 'ti': '0.05', 'lp': '118.55', 'h': '118.65', 'l': '118.10', 'ap': '118.39', 'v': '162220',
'bp1': '118.45', 'sp1': '118.50', 'bq1': '26', 'sq1': '6325'}
quote event: 03-12-2021 11:54:45{'t': 'tf', 'e': 'NSE', 'tk': '11630', 'lp': '118.45', 'ap':
'118.40', 'v': '166637', 'sp1': '118.55', 'bq1': '3135', 'sq1': '30'}
quote event: 03-12-2021 11:54:46{'t': 'tf', 'e': 'NSE', 'tk': '11630', 'lp': '118.60'}
in the example above we see first message t='tk' with all the values, 2nd message has
lasttradeprice avg price and few other fields with value changed.. note bp1 isnt sent as its
still 118.45 in the next tick ( 3rd message) only last price is changed to 118.6
Subscription Acknowledgement:
Number of Acknowledgements for a single subscription will be the same as the number of
scrips mentioned in the key (k) field.
t tk ‘tk’ represents
touchline
acknowledgement
e NSE, BSE, NFO... Exchange name
tk 22 Scrip Token
pp 2 for NSE, BSE & 4 Price precision
for CDS USDINR
ts Trading Symbol
ti Tick size
ls Lot size
lp LTP
pc Percentage change
v volume
o Open price
h High price
l Low price
c Close price
ap Average trade price
oi Open interest
poi Previous day closing
Open Interest
toi Total open interest for
underlying
bq1 Best Buy Quantity 1
bp1 Best Buy Price 1
sq1 Best Sell Quantity 1
sp1 Best Sell Price 1
Touchline subscription Updates: Accept for t, e, and tk other fields may / may not be present.
unsubscribe()
First configure the endpoints in the api_helper constructor. Thereon provide your credentials
and login as follows.
authparams = {
'userid' : 'USER',
'password' : 'Abc123',
'twoFA' : 'OTP/TOTP',
'vendor_code' : 'vc',
api.login(authparams)
.then((res) => {
return;
}).catch((err) => {
console.error(err);
});
Example Symbol/Contract: Example_market.py
This Example shows API usage for finding scrips and its properties
Search Scrips
The call can be made to get the exchange provided token for a scrip or alternately can
search for a partial string to get a list of matching scrips Trading Symbol:
SymbolName + ExpDate + 'F' for all data having InstrumentName starting with FUT
api.searchscrip(exchange='NSE', searchtext='REL')
This will reply as following
"stat": "Ok",
"values": [
"exch": "NSE",
"token": "18069",
"tsym": "REL100NAV-EQ"
},
"exch": "NSE",
"token": "24225",
"tsym": "RELAXO-EQ"
},
"exch": "NSE",
"token": "4327",
"tsym": "RELAXOFOOT-EQ"
},
"exch": "NSE",
"token": "18068",
"tsym": "RELBANKNAV-EQ"
},
{
"exch": "NSE",
"token": "2882",
"tsym": "RELCAPITAL-EQ"
},
"exch": "NSE",
"token": "18070",
"tsym": "RELCONSNAV-EQ"
},
"exch": "NSE",
"token": "18071",
"tsym": "RELDIVNAV-EQ"
},
"exch": "NSE",
"token": "18072",
"tsym": "RELGOLDNAV-EQ"
},
"exch": "NSE",
"token": "2885",
"tsym": "RELIANCE-EQ"
},
{
"exch": "NSE",
"token": "15068",
"tsym": "RELIGARE-EQ"
},
"exch": "NSE",
"token": "553",
"tsym": "RELINFRA-EQ"
},
"exch": "NSE",
"token": "18074",
"tsym": "RELNV20NAV-EQ"
}
Security Info
This call is done to get the properties of the scrip such as freeze qty and margins
api.get_security_info(exchange='NSE', token='22')
{
"request_time": "17:43:38 31-10-2020",
"stat": "Ok",
"exch": "NSE",
"tsym": "ACC-EQ",
"cname": "ACC LIMITED",
"symname": "ACC",
"seg": "EQT",
"instname": "EQ",
"isin": "INE012A01025",
"pp": "2",
"ls": "1",
"ti": "0.05",
"mult": "1",
"prcftr_d": "(1 / 1 ) * (1 / 1)",
"trdunt": "ACC.BO",
"delunt": "ACC",
"token": "22",
"varmrg": "40.00"
}
api.subscribe('NSE|13')
api.subscribe(['NSE|22', 'BSE|522032'])
First we need to connect to the WebSocket and then subscribe as follows
feed_opened = False
def event_handler_feed_update(tick_data):
def open_callback():
global feed_opened
feed_opened = True
api.start_websocket( order_update_callback=event_handler_order_update,
subscribe_callback=event_handler_feed_update,
socket_open_callback=open_callback)
while(feed_opened==False):
pass
api.subscribe('NSE|13')
api.subscribe(['NSE|22', 'BSE|522032'])
Example - Orders and Trades: example_orders.py
Place Order
Place a Limit order as follows
api.place_order(buy_or_sell='B', product_type='C',
exchange='NSE', tradingsymbol='INFY-EQ',
quantity=1, discloseqty=0,price_type='LMT', price=1500,
trigger_price=None,retention='DAY', remarks='my_order_001')
api.place_order(buy_or_sell='B', product_type='C',
exchange='NSE', tradingsymbol='INFY-EQ',
quantity=1, discloseqty=0,price_type='MKT', price=0,
trigger_price=None,retention='DAY', remarks='my_order_001')
api.place_order(buy_or_sell='B', product_type='C',
exchange='NSE', tradingsymbol='INFY-EQ',
quantity=1, discloseqty=0,price_type='SL-LMT', price=1500,
trigger_price=1450,retention='DAY', remarks='my_order_001')
api.place_order(buy_or_sell='B', product_type='H',
exchange='NSE', tradingsymbol='INFY-EQ',
quantity=1, discloseqty=0,price_type='LMT', price=1500, trigger_price=None,
retention='DAY', remarks='my_order_001', bookloss_price = 1490)
api.place_order(buy_or_sell='B', product_type='B',
exchange='NSE', tradingsymbol='INFY-EQ',
quantity=1, discloseqty=0,price_type='LMT', price=1500, trigger_price=None,
retention='DAY', remarks='my_order_001', bookloss_price = 1490, bookprofit_price =
1510)
Modify Order
Modify a New Order by providing the OrderNumber
Cancel Order
Cancel a New Order by providing the Order Number
api.cancel_order(orderno=orderno)
Connecting to the Websocket will automatically subscribe and provide the order updates in
the call back as follows Note: Feed and Order updates are received from the same websocket
and needs to be connected once only.
feed_opened = False
def event_handler_order_update(order):
def open_callback():
global feed_opened
feed_opened = True
api.start_websocket( order_update_callback=event_handler_order_update,
subscribe_callback=event_handler_feed_update,
socket_open_callback=open_callback)
while(feed_opened==False):
pass