0% found this document useful (0 votes)
35 views

Node JS API Document

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Node JS API Document

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Node JS API Document

Contents
Login & logout

 login
 logout

Symbols

 searchscrip
 get_security_info
 get_quotes
 get_time_price_series
 get_option_chain

Orders and Trades

 place_order
 modify_order
 cancel_order
 exit_order
 get_orderbook
 get_tradebook
 get_singleorderhistory

Holdings and Limits

 get_holdings
 get_positions
 get_limits

Websocket API

 start_websocket
 subscribe
 unsubscribe
Example

 getting started
 Market Functions
 Orders and Trade
Login

(userid, password, twoFA, vendor_code, api_secret, imei)

Connect to the broker, only once this function has returned successfully can any other operations be
performed

Param Type Optional Description

userid String False user Login ID For Example (FA12345)

password String False User Need to enter Shoonya Login


Password , If Using Curl then needs to
password Encryption Via SHA256
twoFA String False User Need to Enter OTP/ TOTP

vendor_code String False Vendor Code For Example (FA12345_U)

*User Can Find the Vendor Code in Prism


, given in API Key Field
api_secret String False API Key

*User Can Find the API Key in Prism ,


There is given the option for Generate
the API Key
imei String False imei identification For Example (ABC123)
, it is variable value.

*User Can Find the IMEI Number in


Prism, given in API key Field
logout()

Terminate the session

Param Type Optional Description

No Parameters

place_order

(buy_or_sell, product_type,exchange, tradingsymbol, quantity, discloseqty, price_type,


price=0.0, trigger_price=None, retention='DAY', amo='NO', remarks=None)

Place an order to OMS

Param Type Optional Description

buy_or_sell String False B -> BUY, S -> SELL


product_type String False C / M / H Product name (Select from ‘prarr’ Array
provided in User Details response, and if same is
allowed for selected, exchange. Show product display
name, for user to select, and send corresponding prd in
API call)
exchange String False Exchange NSE / NFO / CDS / MCX / BSE

tradingsymbol String False Unique id of contract on which order to be placed. (use


url encoding to avoid special char error for symbols like
M&M
quantity String False order quantity
discloseqty String False order disc qty
price_type String False PriceType enum class
price String False Price
trigger_price String False Trigger Price
retention String False DAY / IOC / EOS
amo String True Flag for After Market Order, YES/NO
remarks string True client order id or free text
modify_order

(orderno, exchange, tradingsymbol, newquantity,newprice_type, newprice,


newtrigger_price, amo):

Modify the quantity pricetype or price of an order

Param Type Optional Description

orderno String False orderno to be modified


exchange String False Exchange NSE / NFO / CDS / MCX / BSE
tradingsymbol String False RELIANCE-EQ / L&TFH29SEP22P97 /
USDINR25NOV22C76 / CRUDEOIL16NOV22P5400 /
WHIRLPOOL Unique id of contract on which order to
be placed. (use url encoding to avoid special char
error for symbols like M&M
newquantity Integer False new order quantity
newprice_type String False PriceType enum class
newprice Double False Price
newtrigger_price Double False Trigger Price

cancel_order(orderno)

Cancel an order

Param Type Optional Description

orderno String False orderno with status open

exit_order(orderno)

Exits a cover or bracket order

Param Type Optional Description

Orderno String False orderno with status open

prd String False Allowed for only H and B products (Cover order and
bracket order)
Order Book

List of Orders placed for the account

Param Type Optional Description

No Parameters

Trade Book

List of Trades of the account

Param Type Optional Description

No Parameters

single order history(orderno)

History an order

Param Type Optional Description

orderno String False orderno

get_holdings(product_type)

retrieves the holdings as a list

Param Type Optional Description

product_type String True retrieves the delivery holdings or for a given


product
The response is as follows,

Param Type Optional Description

Stat String False Holding request success or failure indication.


get_positions()

Retrieves the positions cf and day as a list

Param Type Optional Description

No Parameters

The response is as follows,

Param Type Optional Description

stat String False Position book success or failure indication.


exch String False Exchange segment
tsym String False Trading symbol / contract.
token String False Contract Token

uid String False User Id


actid String False Account Id

prd String False Product name


netqty String False Net Position Quantity
netavgprc String False Net Position Average Price
daybuyqty String False Day Buy Quantity
daysellqty String False Day Sell Quantity
daybuyavgprc String False Day Buy Average Price
daysellavgprc String False Day Sell Average Price
daybuyamt String False Day Buy Amount
daysellamt String False Day Sell Amount
cfbuyqty String False Carry Forward Sell Quantity
cforgavgprc String False Original Average Price
cfsellqty String False Carry Forward Sell Quantity

cfbuyavgprc String False Carry Forward Buy Average Price


cfsellavgprc String False Carry Forward Sell Average Price
cfbuyamt String False Carry Forward Buy Amount
cfsellamt String False Carry Forward Sell Amount

lp String False LTP

rpnl String False Realized Profit and Loss

urmtom String False UnRealized Mark To Market (Can be recalculated in


LTP update : = netqty * (lp from web socket -
netavgprc) * prcftr
bep String False Breakeven Price
openbuyqty String False Open Buy Order Quantity
opensellqty String False Open Sell Order Quantity
openbuyamt String False Open Buy Order Amount
opensellamt String False Open Sell Order Amount
openbuyavgprc String False
opensellavgprc String False
mult String False
pp String False
prcftr String False
ti String False
ls String False
request_time String False

get_limits

Retrieves the margin and limits set

Param Type Optional Description

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

The response is as follows,

Param Type Optional Description

stat Ok or False Limits request success or failure indication.


Not_Ok
actid String True Account id
prd String True Product name
seg String True Segment CM / FO / FX
exch String True
Exchange

-------------------------
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 /

Amount added to handle system errors - by broker.


-------------------------
Margin Utilized----------
------------------------
marginused String True Total margin / fund used today
mtomcurper String True Mtom current percentage
-------------------------
Margin Used
components--------------
-------
Cbu String True CAC Buy used
csc String True CAC Sell Credits
rpnl String True Current realized PNL
unmtom String True Current unrealized mtom
marprt String True Covered Product margins
span String True Span used
expo String True Exposure margin

Premium String True Premium used


varelm String True Var Elm Margin
grexpo String True Gross Exposure
greexpo_d String True Gross Exposure derivative
scripbskmar String True Scrip basket margin
addscripbskmrg String True Additional scrip basket margin
brokerage String True Brokerage amount
collateral String True Collateral calculated based on uploaded holdings
grcoll String True Valuation of uploaded holding pre haircut

-------------------------
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)

rzpnl_e_m String True Current realized PNL (Equity Margin)

rzpnl_e_c String True Current realized PNL (Equity Cash n Carry)


rzpnl_d_i String True Current realized PNL (Derivative Intraday)
rzpnl_d_m String True Current realized PNL (Derivative Margin)
rzpnl_f_i String True Current realized PNL (FX Intraday)
rzpnl_f_m String True Current realized PNL (FX Margin)
rzpnl_c_i String True Current realized PNL (Commodity Intraday)

rzpnl_c_m String True Current realized PNL (Commodity Margin)

uzpnl_e_i String True Current unrealized MTOM (Equity Intraday)

uzpnl_e_m String True Current unrealized MTOM (Equity Margin)


uzpnl_e_c String True Current unrealized MTOM (Equity Cash n Carry)

uzpnl_d_i String True Current unrealized MTOM (Derivative Intraday)


uzpnl_d_m String True Current unrealized MTOM (Derivative Margin)
uzpnl_f_i String True Current unrealized MTOM (FX Intraday)
uzpnl_f_m String True Current unrealized MTOM (FX Margin)
uzpnl_c_i String True Current unrealized MTOM (Commodity Intraday)
uzpnl_c_m String True Current unrealized MTOM (Commodity Margin)
span_d_i string TRUE Span Margin (Derivative Intraday)

span_d_m string TRUE Span Margin (Derivative Margin)

span_f_i string TRUE Span Margin (FX Intraday)


span_f_m string TRUE Span Margin (FX Margin)
span_c_i string TRUE Span Margin (Commodity Intraday)

span_c_m string TRUE Span Margin (Commodity Margin)

expo_d_i string TRUE Exposure Margin (Derivative Intraday)

expo_d_m string TRUE Exposure Margin (Derivative Margin)

expo_f_i string TRUE Exposure Margin (FX Intraday)


expo_f_m string TRUE Exposure Margin (FX Margin)
expo_c_i string TRUE Exposure Margin (Commodity Intraday)

expo_c_m string TRUE Exposure Margin (Commodity Margin)

premium_d_i string TRUE Option premium (Derivative Intraday)

premium_d_m string TRUE Option premium (Derivative Margin)

premium_f_i string TRUE Option premium (FX Intraday)


premium_f_m string TRUE Option premium (FX Margin)
premium_c_i string TRUE Option premium (Commodity Intraday)

premium_c_m string TRUE Option premium (Commodity Margin)

varelm_e_i string TRUE Var Elm (Equity Intraday)


varelm_e_m string TRUE Var Elm (Equity Margin)
varelm_e_c string TRUE Var Elm (Equity Cash n Carry)
marprt_e_h string TRUE Covered Product margins (Equity High leverage)

marprt_e_b string TRUE Covered Product margins (Equity Bracket Order)

marprt_d_h string TRUE Covered Product margins (Derivative High


leverage)

marprt_d_b string TRUE Covered Product margins (Derivative Bracket


Order)
marprt_f_h string TRUE Covered Product margins (FX High leverage)

marprt_f_b string TRUE Covered Product margins (FX Bracket Order)

marprt_c_h string TRUE Covered Product margins (Commodity High


leverage)

marprt_c_b string TRUE Covered Product margins (Commodity Bracket


Order)
scripbskmar_e_i string TRUE Scrip basket margin (Equity Intraday)

scripbskmar_e_m string TRUE Scrip basket margin (Equity Margin)

scripbskmar_e_c string TRUE Scrip basket margin (Equity Cash n Carry)

addscripbskmrg_d_i string TRUE Additional scrip basket margin (Derivative


Intraday)
addscripbskmrg_d_m string TRUE Additional scrip basket margin (Derivative
Margin)

addscripbskmrg_f_i string TRUE Additional scrip basket margin (FX Intraday)

addscripbskmrg_f_m string TRUE Additional scrip basket margin (FX Margin)

addscripbskmrg_c_i string TRUE Additional scrip basket margin (Commodity


Intraday)

addscripbskmrg_c_m string TRUE Additional scrip basket margin (Commodity


Margin)

brkage_e_i string TRUE Brokerage (Equity Intraday)


brkage_e_m string TRUE Brokerage (Equity Margin)
brkage_e_c string TRUE Brokerage (Equity CAC)
brkage_e_h string TRUE Brokerage (Equity High Leverage)

brkage_e_b string TRUE Brokerage (Equity Bracket Order)

brkage_d_i string TRUE Brokerage (Derivative Intraday)


brkage_d_m string TRUE Brokerage (Derivative Margin)
brkage_d_h string TRUE Brokerage (Derivative High Leverage)

brkage_d_b string TRUE Brokerage (Derivative Bracket Order)

brkage_f_i string TRUE Brokerage (FX Intraday)


brkage_f_m string TRUE Brokerage (FX Margin)
brkage_f_h string TRUE Brokerage (FX High Leverage)
brkage_f_b string TRUE Brokerage (FX Bracket Order)
brkage_c_i string TRUE Brokerage (Commodity Intraday)

brkage_c_m string TRUE Brokerage (Commodity Margin)


brkage_c_h string TRUE Brokerage (Commodity High Leverage)

brkage_c_b string TRUE Brokerage (Commodity Bracket Order)

peak_mar string TRUE Peak margin used by the client


request_time string TRUE This will be present only in a successful response.

emsg string TRUE This will be present only in a failure response.

searchscrip(exchange, searchtext):

Search for scrip or contract and its properties

Param Type Optional Description

exchange String True Exchange NSE / NFO / BSE / CDS


searchtext String True Search Text ie partial or complete text ex: INFY-EQ,
INF..

The response is as follows,

Param Type Optional Description

stat string TRUE ok or Not_ok


values string TRUE properties of the scrip
emsg string FALSE Error Message
Param Type Optional Description

exch string TRUE Exchange NSE / NFO / BSE / CDS

Trading Symbol is the readable Unique id of


tsym string TRUE
contract/scrip
token string TRUE Unique Code of contract/scrip

get_security_info(exchange, token):

gets the complete details and its properties

Param Type Optional Description

exchange string TRUE Exchange NSE / NFO / BSE / CDS

token string TRUE token number of the contract

The response is as follows,

Param Type Optional Description

stat string TRUE ok or Not_ok


values string TRUE properties of the scrip
emsg string FALSE Error Message
Param Type Optional Description
exch string TRUE Exchange NSE / NFO / BSE / CDS
Trading Symbol is the readable
tsym string TRUE
Unique id of contract/scrip
cname string TRUE Company Name
symnam string TRUE Symbol Name
seg string TRUE Segment
exd string TRUE Expiry Date
instname string TRUE Instrument Name
strprc string TRUE Strike Price
optt string TRUE Option Type
isin string TRUE ISIN
ti string TRUE Tick Size
ls string TRUE Lot Size
pp string TRUE Price Precision
mult string TRUE Multiplier
gp_nd string TRUE GN/GD * PN/PD
prcunt string TRUE Price Units
prcqqty string TRUE Price Quote Qty
trdunt string TRUE Trade Units
delunt string TRUE Delivery Units
frzqty string TRUE Freeze Qty
gsmind string TRUE GSM indicator
elmbmrg string TRUE ELM Buy Margin
elmsmrg string TRUE ELM Sell Margin
addbmrg string TRUE Additional Long Margin
addsmrg string TRUE Additional Short Margin
splbmrg string TRUE Special Long Margin
splsmrg string TRUE Special Short Margin
delmrg string TRUE Delivery Margin
tenmrg string TRUE Tender Margin
tenstrd string TRUE Tender Start Date
tenendd string TRUE Tender End Date
exestrd string TRUE Exercise Start Date
exeendd string TRUE Exercise End Date
elmmrg string TRUE ELM Margin
varmrg string TRUE VAR Margin
expmrg string TRUE Exposure Margin
token string TRUE Contract Token
prcftr_d string TRUE ((GN / GD) * (PN/PD))
get_quotes(exchange, token):

gets the complete details and its properties

Param Type Optional Description

exchange string TRUE Exchange NSE / NFO / BSE / CDS


token string TRUE token number of the contract

the response is as follows,

Param Type Optional Description

stat string TRUE ok or Not_ok


values string TRUE properties of the scrip

Param Type Optional Description

exch string TRUE Exchange NSE / NFO / BSE / CDS


Trading Symbol is the readable
tsym string TRUE
Unique id of contract/scrip
cname string TRUE Company Name
symname string TRUE Symbol Name
seg string TRUE Segment
instname string TRUE Instrument Name
isin string TRUE ISIN
pp string TRUE Price precision
ls string TRUE Lot Size
ti string TRUE Tick Size
mult string TRUE Multiplier
uc string TRUE Upper circuit limitlc
lc string TRUE Lower circuit limit
prcftr_d string TRUE Price factor((GN / GD) * (PN/PD))
token string TRUE Token
lp string TRUE LTP
o string TRUE Open Price
h string TRUE Day High Price
l string TRUE Day Low Price
v string TRUE Volume
ltq string TRUE Last trade quantity
ltt string TRUE Last trade time
bp1 string TRUE Best Buy Price 1
sp1 string TRUE Best Sell Price 1
bp2 string TRUE Best Buy Price 2
sp2 string TRUE Best Sell Price 2
bp3 string TRUE Best Buy Price 3
sp3 string TRUE Best Sell Price 3
bp4 string TRUE Best Buy Price 4
sp4 string TRUE Best Sell Price 4
bp5 string TRUE Best Buy Price 5
sp5 string TRUE Best Sell Price 5
bq1 string TRUE Best Buy Quantity 1
sq1 string TRUE Best Sell Quantity 1
bq2 string TRUE Best Buy Quantity 2
sq2 string TRUE Best Sell Quantity 2
bq3 string TRUE Best Buy Quantity 3
sq3 string TRUE Best Sell Quantity 3
bq4 string TRUE Best Buy Quantity 4
sq4 string TRUE Best Sell Quantity 4
bq5 string TRUE Best Buy Quantity 5
sq5 string TRUE Best Sell Quantity 5
bo1 string TRUE Best Buy Orders 1
so1 string TRUE Best Sell Orders 1
bo2 string TRUE Best Buy Orders 2
so2 string TRUE Best Sell Orders 2
bo3 string TRUE Best Buy Orders 3
so3 string TRUE Best Sell Orders 3
bo4 string TRUE Best Buy Orders 4
so4 string TRUE Best Sell Orders 4
bo5 string TRUE Best Buy Orders 5
so5 string TRUE Best Sell Orders 5
get_time_price_series

(Exchange, token, starttime, endtime, interval):

gets the chart data for the symbol

Json Fields Possible value Description

uid* Logged in User Id


exchange* Exchange
token*
Start time (seconds since
starttime
1 jan 1970)
End Time (seconds since
endtime
1 jan 1970)
Candle size in minutes
“1”, ”3”, “5”, “10”, “15”,
interval (optional field, if not given
“30”, “60”, “120”, “240”
assume to be “1”)

The response is as follows,

Param Type Optional Description

stat string TRUE ok or Not_ok

values string TRUE properties of the scrip

emsg string FALSE Error Message

Param Type Optional Description

time string TRUE DD/MM/CCYY hh:mm:ss


into string TRUE Interval Open
inth string TRUE Interval High
get_option_chain

(exchange, tradingsymbol, strikeprice, count):

Param Type Optional Description

exchange string FALSE Exchange (UI need to check if exchange in NFO /


CDS / MCX / or any other exchange which has
options, if not don't allow)
tradingsymbol string FALSE Trading symbol of any of the option or future.
Option chain for that underlying will be
returned. (use url encoding to avoid special char
error for symbols like M&M)

strikeprice float FALSE Mid price for option chain selection

the response is as follows,

Param Type Optional Description

stat string TRUE ok or Not_ok


values string TRUE properties of the scrip
emsg string FALSE Error Message

Param Type Optional Description

exch string FALSE Exchange


tsym string FALSE Trading Symbol of Contract
token string FALSE Contract token
start_websocket()

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

Param Type Optional Description

subscribe_callback function FALSE callback for market updates


order_update_callback function FALSE callback for order updates

socket_open_callback function FALSE callback when socket is open


(reconnection also)

subscribe_orders()

get order and trade update callbacks

Subscription Acknowledgement:

Json Fields Possible value Description

‘ok’ represents order


t ok update subscription
acknowledgement

Order Update subscription Updates:

Json Fields Possible value Description


t om ‘om’ represents touchline feed

norenordno Noren Order Number


uid User Id
actid Account ID
exch Exchange
tsym Trading symbol
qty Order quantity
prc Order Price
prd Product
status Order status (New, Replaced, Complete, Rejected etc)

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])

send a list of instruments to watch

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

Param Type Optional

instruments list FALSE

Subscription Acknowledgement:

Number of Acknowledgements for a single subscription will be the same as the number of
scrips mentioned in the key (k) field.

Json Fields Possible value Description

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()

Send a list of instruments to stop watch

Example - Getting Started

First configure the endpoints in the api_helper constructor. Thereon provide your credentials
and login as follows.

const Api = require("./lib/RestApi");

authparams = {

'userid' : 'USER',

'password' : 'Abc123',

'twoFA' : 'OTP/TOTP',

'vendor_code' : 'vc',

'api_secret' : 'secret shared',

'imei' : 'machine identifier'

api = new Api({});

api.login(authparams)

.then((res) => {

console.log('Reply: ', 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

SymbolName + ExpDate + 'P' + StrikePrice for all data having InstrumentName


starting with OPT and with OptionType PE

SymbolName + ExpDate + 'C' + StrikePrice for all data having InstrumentName


starting with OPT and with OptionType C

For MCX, F to be ignored for FUT instruments

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')

The response for the same would be

{
"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"
}

Subscribe to a live feed

Subscribe to a single token as follows

api.subscribe('NSE|13')

Subscribe to a list of tokens as follows

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):

print(f"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

# subscribe to a single token

api.subscribe('NSE|13')

#subscribe to multiple tokens

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')

Place a Market Order as follows

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')

Place a StopLoss Order as follows

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')

Place a Cover Order as follows

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)

Place a Bracket Order as follows

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

api.modify_order(exchange='NSE', tradingsymbol='INFY-EQ', orderno=orderno,


newquantity=2, newprice_type='LMT', newprice=1505)

Cancel Order
Cancel a New Order by providing the Order Number

api.cancel_order(orderno=orderno)

Subscribe to Order Updates

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):

print(f"order feed {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

You might also like