Skip to content

QuantDesk/SharekhanAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

forked repo for internal use

from sharekhan import sharekhanConnect

from sharekhanConnect import SharekhanConnect

Make a object call

api_key = "Your API KEY" """ version_id="Version Value """ login = SharekhanConnect(api_key)

Print the login url

""" Pass version_id if it is needed """ print(login.login_url(version_id))

Pass the required parameters for decryption and encryption

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

Generate access token

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

Make a object for SharekhanConnect class

sharekhan = SharekhanConnect(access_token=access_token)

Place order history

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

Retrieves all positions

customerId="customerId < long data type>" order=sharekhan.trades(customerId) print("Postion Reports: {}".format(order))

Retrieve history of an given order

exchange="exchange value " customerId="customerId " orderId="orderId " order=sharekhan.exchange(exchange, customerId, orderId) print("Order Details: {}".format(order))

Retrieves the trade generated by an order

exchange="exchange value " customerId="customerId " orderId="orderId " order=sharekhan.exchangetrades(exchange, customerId, orderId) print("Trade Generated By an Order : {}".format(order))

services Holdings

customerId="customerId " order=sharekhan.holdings(customerId) print("Holdings : {}".format(order))

Script Master

exchange="exchange value " order=sharekhan.master(exchange) print("Script Master : {}".format(order))

Historical Data

exchange="exchange value " scripcode="Unique scripcode provided by the broker " interval="Available Intervals " order=sharekhan.historicaldata(exchange, scripcode, interval) print("Holdings Data: {}".format(order))

websocket Programming Testing

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

Assign the callbacks.

sws.on_open = on_open sws.on_data = on_data sws.on_error = on_error sws.on_close = on_close

sws.connect()

About

Repository to hold the public API code for Sharekhan

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages