Python Streaming Tick Data Problem with SmartAPI Websocket's
-
I am new to python. Can you guide how to install all these in python.. I mean what software I shall install like "pycharm" or other. Then anything else I need to download
Then what to be done , a complete guide for a new person.
-
@adi3399
For more Info on websocket go to this link : https://smartapi.angelbroking.com/docs/WebSocketStreaming -
@adi3399
Go to this link to find the token information of all tradable instruments : https://margincalculator.angelbroking.com/OpenAPI_File/files/OpenAPIScripMaster.jsonThen Use this code to get live data streaming for any stock or Index
Getting started with SmartAPI Websocket's :from smartapi import SmartConnect
from smartapi import SmartWebSocketLive_Data_API = " Enter Your API Key Here"
Username = "Enter Your Angel Broking User name"
Password = "Enter Your Angel Broking Password"
#create object of call
obj=SmartConnect(api_key=Live_Data_API)#login api call
data = obj.generateSession(Username,Password)
refreshToken= data['data']['refreshToken']#fetch the feedtoken
feedToken=obj.getfeedToken()#fetch User Profile
userProfile= obj.getProfile(refreshToken)feed_token=092017047
FEED_TOKEN=feedToken
CLIENT_CODE=Usernametoken="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()
-
@azkhan Uninstalled and re-installed smartapi python package. There is progress now. it is opening websocket connection and showing response. I need stock price information.. how can I get price? Please advise.
Below is the output of same code. It is showing actual client code correctly , but to show here I changed it to "my client code"
before connect
__on_open################
{'task': 'cn', 'channel': 'NONLM', 'token': 'token number', 'user': 'my client id', 'acctid': 'my client id'}
2021-07-15 13:51:05.092349 : Start task in the background
{'task': 'hb', 'channel': '', 'token': 'token number', 'user': 'my client id', 'acctid': 'my client id'}
2021-07-15 13:51:21.833013 : Start task in the background
{'task': 'hb', 'channel': '', 'token': 'token number', 'user': 'my client id', 'acctid': 'my client id'}
HeartBeat Sending Failed
2021-07-15 13:51:29.792444 : Start task in the background
{'task': 'hb', 'channel': '', 'token': 'token number', 'user': 'my client id', 'acctid': 'my client id'}
HeartBeat Sending Failed
2021-07-15 13:51:35.124963 : Start task in the background
{'task': 'hb', 'channel': '', 'token': 'token number', 'user': 'my client id', 'acctid': 'my client id'}
2021-07-15 13:51:51.841917 : Start task in the background
{'task': 'hb', 'channel': '', 'token': 'token number', 'user': 'my client id', 'acctid': 'my client id'}
HeartBeat Sending Failed
2021-07-15 13:51:59.822315 : Start task in the background
{'task': 'hb', 'channel': '', 'token': 'token number', 'user': 'my client id', 'acctid': 'my client id'}
HeartBeat Sending Failed -
@adi3399 please update your SmartAPI Python library.
-
@azkhan added on_open() function.. still it is not showing tick price info. this is new code
-
This post is deleted! -
This post is deleted! -
@admin Thank you
-
HI @adi3399 We are working on the web socket code we will update you soon with the eta.