How to get fed_token and how to use token and task and how to subscribe and unsubscribe a script?????
-
@rajanprabu Sir it's showing like this____
my code is____import pandas as pd df = pd.read_json('http://margincalculator.angelbroking.com/OpenAPI_File/files/OpenAPIScripMaster.json') print(df)
-
Hi @ashmita Please refer the following code to generate feed token
######################################################
from smartapi import SmartConnectobj=SmartConnect(api_key="put your api key here")
data = obj.generateSession("put your client id here","put your passwd here")
refreshToken= data['data']['refreshToken']#fetch the feedtoken
feedToken=obj.getfeedToken()
print ("this is my feed token" ,feedToken )#fetch User Profile
userProfile= obj.getProfile(refreshToken)now you will have your feed token with you
##########################################################
now use below piece of code to use web socket use feed token which you will get from above code.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( )
-
@ashmita_ said in How to get fed_token and how to use token and task and how to subscribe and unsubscribe a script?????:
I'm not found instrument like Reliance_EQ,
Do you converted json into csv ?
You should use RELIANCE-EQ for equity.
RELIANCE25MAR21FUT for current month contractCan you share your code, so we can help you.
-
possible reliance search terms
RELIANCE-EQ
RELIANCE29APR211660CE
RELIANCE29APR21FUTIf one just wants to use the data they saw market API, otherwise trading API.
-
Hi @ashmita_ please mail us your piece of code @ api@angelbroking.com.
-
@James-Bond Sir I fetched this data in a dataframe but I'm not found instrument like Reliance_EQ, Reliance_Future, Reliance_Options
And sir can you please tell me what is the difference between Trading API and Market Feeds API
when I hover the cursor on I button it's show__
Trading API:- Access full fledged APIs to execute orders i real time, manage use portfolio, stream live market data and more.
Market Feeds APIs:- Access real time market data for various stocks. -
To subscribe multiple scrips at same time, use following format:
"nse_cm|2885&nse_cm|5285&nse_cm|2521&nse_cm|2854"
It should be separated by &
Getting token list:
@ashmita_ said in How to get fed_token and how to use token and task and how to subscribe and unsubscribe a script?????:
Some one give me this link https://margincalculator.angelbroking.com/OpenAPI_File/files/OpenAPIScripMaster.json but it's looks messy and confusing I can't understand how can I use it sir......
@rajanprabu answered your query in above post which is easiest approach to get scrip names and token lists.
-
You can read them in pandas.. Its in json format
df = pd.read_json('http://margincalculator.angelbroking.com/OpenAPI_File/files/OpenAPIScripMaster.json')
Python dictionaries are hashed.. so its faster. But if you prefer csv you can convert them like the following
df.to_csv(file_name)
-
@James-Bond Sir can you please tell me how to get the instruments token list including F&O contract's........
I'm using python sdk....
Some one give me this link https://margincalculator.angelbroking.com/OpenAPI_File/files/OpenAPIScripMaster.json but it's looks messy and confusing I can't understand how can I use it sir......
Also how to subscribe multiple script at the same time mean token format like this
token="nse_cm|2885, token=nse_cm|5285, token=nse_cm|2521, token=nse_cm|2854" -
@ashmita_ said in How to get fed_token and how to use token and task and how to subscribe and unsubscribe a script?????:
Sir what is the meaning of task (task="mw" #'mw'|'sfi'|'dp')???
More info here: https://smartapi.angelbroking.com/docs/WebSocket
@ashmita_ said in How to get fed_token and how to use token and task and how to subscribe and unsubscribe a script?????:
can we subscribe a script using symbol name like this "nse_cm|RELIANCE" instead of using token number like this way "nse_cm|2885" ???
No, we can't use something like nse_cm|RELIANCE. Only scrip token will be considered as acceptable value.
-
This post is deleted! -
@James-Bond Sir what is the meaning of task (task="mw" #'mw'|'sfi'|'dp')???
And sir can we subscribe a script using symbol name like this "nse_cm|RELIANCE" instead of using token number like this way "nse_cm|2885" ??? -
@ashmita_ said in How to get fed_token and how to use token and task and how to subscribe and unsubscribe a script?????:
FEED_TOKEN= "your feed token"
SmartAPI SDK has inbuilt method to generate feed token, so you don't have to worry about it.
-
You can use following code to get Feed Token and subscribe any scrip.
from smartapi import SmartConnect from smartapi import WebSocket obj=SmartConnect(api_key="your_api_key") data = obj.generateSession('client_id', 'password') feedToken=obj.getfeedToken() FEED_TOKEN= feedToken CLIENT_CODE= 'client_id' task="mw" #'mw'|'sfi'|'dp' token="nse_cm|26009" WS = WebSocket(FEED_TOKEN, CLIENT_CODE) def on_tick(ws, tick): print(tick) def on_connect(ws, response): ws.send_request(token) def on_close(ws, code, reason): ws.stop() # Assign the callbacks. WS.on_ticks = on_tick WS.on_connect = on_connect WS.on_close = on_close WS.connect()
To subscribe Reliance (NSE), first you need to find out Reliance scrip / symbol token from following JSON file.
https://margincalculator.angelbroking.com/OpenAPI_File/files/OpenAPIScripMaster.json
then you need to change token in above code. In case of RELIANCE-EQ token is 2885
so change:token="nse_cm|26009"
to
token="nse_cm|2885"
To use above code, you need to update above code with your api key, client id and password.
-
This post is deleted! -
@James-Bond I'm using python SDK. Can you please tell me how to get this FEED_TOKEN= "your feed token"......./
And how to subscribe it mean, code format if we want to subscribe NSE_RELIANCE script..... -
@James-Bond I'm using python sdk....
-
@ashmita_ said in How to get fed_token and how to use token and task and how to subscribe and unsubscribe a script?????:
How to get fed_token and how to use token and task and how to subscribe and unsubscribe a script?????
It's mainly depends on which programming language you're using.
-
Which SDK you're using ?
In case of Python or with any other language, Feed token generally used to access WebSocket to receive live ticks.
Tokens are primarily used to subscribe particular scrip to receive live ticks.