Getting error in Websocket python code
-
I am trying to stream data through websocket through latest python sdk version 1.2.2. But getting the following error in code -
File "<ipython-input-1-89d9cd8c64a7>", line 12, in <module>
WS = WebSocket(FEED_TOKEN, CLIENT_CODE)TypeError: init() missing 1 required positional argument: 'task'
-
Hi @Tapa As suggested reinstall all libraries and update us.
-
@admin Any update on my issue?.
-
Hi @Tapa As discussed on a call we will update you on this.
-
@Tapa Try this
import logging CLIENT_ID = 'asd' PASSWORD = 'asd' API_KEY = 'asd' task = "mw" obj = SmartConnect(api_key = API_KEY) data = obj.generateSession(CLIENT_ID, PASSWORD) FEED_TOKEN = obj.getfeedToken() token = 'mcx_fo|225425' scrip_name = 'CRUDEOIL21APRFUT' exchange = 'MCX' ss = WebSocket(FEED_TOKEN, CLIENT_ID) def on_tick(ws, ticks): logging.info(ticks) def on_connect(ws, response): logging.info('websocket connected') ws.send_request(token, task) def on_close(ws, code, reason): logging.info('websocket closed') ws.stop() ss.on_ticks = on_tick ss.on_connect = on_connect ss.on_close = on_close ss.connect()
-
@admin I am still getting same problem.
-
HI @Tapa please sue the below piece of code and update us.
from smartapi import WebSocket
FEED_TOKEN= ""
CLIENT_CODE=""
token= "nse_cm|2885&nse_cm|1594&nse_cm|11536"
task="mw" #'mw'|'sfi'|'dp'
ss = WebSocket(FEED_TOKEN, CLIENT_CODE)def on_tick(ws, tick):
print("Ticks: {}".format(tick))def on_connect(ws, response):
ws.send_request(token,task)def on_close(ws, code, reason):
ws.stop()Assign the callbacks.
ss.on_ticks = on_tick
ss.on_connect = on_connect
ss.on_close = on_closess.connect( )
-
I am using this code -
@admin Please help