from sharekhanConnect import SharekhanConnect
api_key = "Your API KEY" """ version_id="Version Value """ login = SharekhanConnect(api_key)
""" Pass version_id if it is needed """ print(login.login_url(version_id))
""" After Successfully Login You will receive the request token value then you have to decrypt the token value by using secret key and then swap the request token which is a combination of RequestId and CustomerId Then after that decrypt the request token value """
request_token = "Valid Request Token Value" secret_key = "Your Secret Key value" session = login.generate_session(request_token, secret_key)
""" You have to pass the encrypted request token after manipulation """
requestToken="After encrypt the request token pass valid reques_token value" access_token=login.get_access_token(apiKey=api_key,requestToken,userId=12345,versionId=1005) print(access_token)
sharekhan = SharekhanConnect(access_token=access_token)
orderparams={ "customerId": XXXXXX, "scripCode": 251731, "tradingSymbol": "GOLDPETAL", "exchange": "MX", "transactionType": "B", "quantity": 1, "disclosedQty": 0, "price": "0", "triggerPrice": "0", "rmsCode": "ANY", "afterHour": "N", "orderType": "NORMAL", "channelUser": "XXXXXX", "validity": "GFD", "requestType": "NEW", "productType": "INVESTMENT", "instrumentType": "FS", "strikePrice": -1, "expiry": "28/04/2023", "optionType": "XX" } order=sharekhan.placeOrder(orderparams) print("PlaceOrder: {}".format(order))
customerId="customerId < long data type>" order=sharekhan.trades(customerId) print("Postion Reports: {}".format(order))
exchange="exchange value " customerId="customerId " orderId="orderId " order=sharekhan.exchange(exchange, customerId, orderId) print("Order Details: {}".format(order))
exchange="exchange value " customerId="customerId " orderId="orderId " order=sharekhan.exchangetrades(exchange, customerId, orderId) print("Trade Generated By an Order : {}".format(order))
customerId="customerId " order=sharekhan.holdings(customerId) print("Holdings : {}".format(order))
exchange="exchange value " order=sharekhan.master(exchange) print("Script Master : {}".format(order))
exchange="exchange value " scripcode="Unique scripcode provided by the broker " interval="Available Intervals " order=sharekhan.historicaldata(exchange, scripcode, interval) print("Holdings Data: {}".format(order))
from sharekhanWebsocket import SharekhanWebSocket
access_token = "Your Access-Token"
params={ "access_token": access_token }
action = 1 mode = 1
token_list = {"action":"subscribe","key":["feed"],"value":[""]} feed={"action":"feed","key":["ltp"],"value":["NC22,NF37833,NF37834,MX253461,RN7719"]}
sws = SharekhanWebSocket(access_token) def on_data(wsapp, message): print("Ticks: {}".format(message))
def on_open(wsapp): print("on open") # sws.subscribe(token_list) # sws.fetchData(feed) # sws.unsubscribe(feed)
def on_error(wsapp, error): print(error)
def on_close(wsapp): print("Close")
sws.on_open = on_open sws.on_data = on_data sws.on_error = on_error sws.on_close = on_close
sws.connect()