User Feedback - WebSocket 2.0 Beta Rollout – Python Language
-
@admin
This script i not working. No error, nothing happens, It times out. Why ?
I have tried many a times today.Code below:
from SmartApi.smartWebSocketV2 import SmartWebSocketV2
from smartapi import SmartConnect
import pyotpobj=SmartConnect(api_key="") # feed app API key.
#optional
#access_token = "your access token",
#refresh_token = "your refresh_token")
#login api call
token=''Login needs to be done through MPIN now.
data = obj.generateSession("","",pyotp.TOTP(token).now())
print(data)
refreshToken= data['data']['refreshToken']
jwt_token = data['data']['jwtToken']#fetch the feedtoken
feedToken=obj.getfeedToken()
AUTH_TOKEN = jwt_token
API_KEY = ******* #feed app API key
CLIENT_CODE = '*******'
FEED_TOKEN = feedTokencorrelation_id = "Testing"
action = 1
mode = 3token_list = [{"exchangeType": 1, "tokens": ["26009","11536","1594","2885"]}]
sws = SmartWebSocketV2(AUTH_TOKEN, API_KEY, CLIENT_CODE, FEED_TOKEN)
def on_data(wsapp, message):
print("Ticks: {}".format(message))def on_open(wsapp):
print("on open")sws.subscribe(correlation_id, mode, token_list)
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_closesws.connect()
Rsult:
on open
-
@J88913 dont install SmartApi. download and keep it in the same folder as program
-
Hi @Javajp @vishant @whemant @Kiran @Narendra_Javvadi @vrkhyd @zubuco @N399438
We are excited to announce the release of updated SmartAPI libraries that now fully support WebSocket 2.0, further enhancing your trading experience. The latest versions of the SmartAPI Python SDK (1.3.4), SmartAPI Java SDK (2.1.0) and the SmartAPI Node.js Library (1.0.15) incorporate WebSocket 2.0 implementation, ensuring faster market data updates, reduced latency, and improved overall performance.
-
@vrkhyd how can you get the live data?
I am facing the same issue -
@whemant Hi,
send a mail to vemula.ramkishore@gmail.com -
@Ankita do you get any solution on this issue?
If Yes so help me -
@dharm change the function as following
@staticmethod def _parse_token_value(binary_packet): token = "" binary_packet = binary_packet.decode("UTF-8") for i in range(len(binary_packet)): if binary_packet[i] == '\x00': return token token += str(binary_packet[i]) return token
-
What is total_buy_quantity and total_sell_quantity?
When are they different? I mean whatever is bought is sold as well. Thanks. -
nvm, I gather that this is the amount of pending buy and sell orders at the Exchange.
-
@sathyaraj
We can fix this error by updating _on_close method with additional arguments in SmartWebSocketV2.py file.def _on_close(self, wsapp**, close_status_code, close_msg**):
<Error: SmartWebSocketV2._on_close() takes 2 positional arguments but 4 were given>
This error is thrown because on_close method of websocket class takes multiple arguments which are missing in SmartWebSocket library. Example code:
https://websocket-client.readthedocs.io/en/latest/examples.html -
@DIYD57519 Im no getting on open. Instead, I'm getting "attempting to resubscibe/reconnect". Any help is appreciated.
Thanks in advance -
Hi @jaideep-siddula , I'm also having the same issue, have you found the solution?
-
@jaideep-siddula @DIYD57519, I'm also getting "attempting to resubscibe/reconnect", is there any solution, as I've drilled a bit and got Handshake status 404 not found.