ShoonyaAPI-js
ShoonyaAPI-js
Build
to build this package and install it on your server please use
API
ShoonyaApi
login
Symbols
searchscrip
get_security_info
get_quotes
get_time_price_series
place_order
modify_order
cancel_order
exit_order
get_orderbook
get_singleorderhistory
get_holdings
get_positions
get_limits
Websocket API
start_websocket
subscribe
unsubscribe
Example
getting started
Market Functions
Orders and Trade
connect to the broker, only once this function has returned successfully can any other operations
be performed
cancel an order
history an order
#credentials
user = '< user id>'
u_pwd = '< password >'
factor2 = 'second factor'
vc = 'vendor code'
app_key = 'secret key'
imei = 'uniq identifier'
ret = api.login(userid=user, password=pwd, twoFA=factor2, vendor_code=vc,
api_secret=app_key, imei=imei)
print(ret)
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')
{
"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'])
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
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)
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
Author
Kumar Anand
License
Copyright © 2021 Kambala Solutions Pvt Ltd- All Rights Reserved
Copying of this file, via any medium is strictly prohibited.
Proprietary and confidential.
All file transfers are logged.