making websocket callbacks as async
-
Hello,
so below is the code posted on github for accessing real time data.
Can anyone please help me in converting this to a async codefrom smartapi import SmartWebSocket
feed_token=092017047
FEED_TOKEN="YOUR_FEED_TOKEN"
CLIENT_CODE="YOUR_CLIENT_CODE"token="mcx_fo|224395"
token="EXCHANGE|TOKEN_SYMBOL" #SAMPLE: nse_cm|2885&nse_cm|1594&nse_cm|11536&nse_cm|3045
token="mcx_fo|226745&mcx_fo|220822&mcx_fo|227182&mcx_fo|221599"
task="mw" # mw|sfi|dp
ss = SmartWebSocket(FEED_TOKEN, CLIENT_CODE)
def on_message(ws, message):
print("Ticks: {}".format(message))def on_open(ws):
print("on open")
ss.subscribe(task,token)def on_error(ws, error):
print(error)def on_close(ws):
print("Close")Assign the callbacks.
ss._on_open = on_open
ss._on_message = on_message
ss._on_error = on_error
ss._on_close = on_closess.connect()
so i am trying to do something like this:
async with smartapi_websocket(client_id, api_id, etc....) as ws:
here I perform other async calls, and probably do not disturb the main thread* -
@Sukhwant280 Hi Sukhwant, actually I am just using tick data and previous day data to trade programmatically so I am not storing any thing, what is your requirement exactly? I'll try to assist.
Best regards.
-
@namanviz Hi Mate, do you have a running code to store the data from websocket mw or dp into a csv or dataframe using python, as i am struggling from last 3 weeks
thanks in advance
SukhwantFYi - sorry i don't have a solution for your question