对于Angel Broking SmartAPI,有人知道如何在更新时将JSON文件中的NSE实时股票市场feed存储到



我一直在尝试在天使经纪SmartAPI中创建一个算法交易机器人。我正在从API获取实时数据。我只是对如何存储作为API输出抛出的实时数据feed感到困惑。

FEED_TOKEN= feedToken
CLIENT_CODE=clientID
token="nse_cm|3063" # For Vedanta
task="mw"
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")
def on_tick(ws, tick):
print("Ticks: {}".format(tick))
def on_connect():
print('Connected')

# Assign the callbacks.
ss._on_open = on_open
ss._on_connect = on_connect
ss._on_message = on_message
ss._on_error = on_error
ss._on_close = on_close

ss.connect()

这是吐出输出的函数。输出示例如下:

Ticks: [{'e': 'nse_cm', 'ltp': '309.85', 'ltq': '56', 'ltt': 'NA', 'name': 'sf', 'tk': '3063'}]
Ticks: [{'name': 'tm', 'tvalue': '10/08/2021 10:41:55'}]
Ticks: [{'e': 'nse_cm', 'ltp': '309.90', 'ltq': '100', 'ltt': 'NA', 'name': 'sf', 'tk': '3063'}]
Ticks: [{'ap': '310.23', 'bp': '309.85', 'bq': '809', 'bs': '6725', 'c': '309.55', 'cng': '00.35', 'e': 'nse_cm', 'lo': '308.10', 'ltp': '309.90', 'ltq': '100', 'ltt': '10/08/2021 10:41:55', 'name': 'sf', 'nc': '00.1131', 'sp': '310.00', 'tbq': '754644', 'tk': '3063', 'to': '677822767.92', 'tsq': '1047420', 'v': '2184904'}]
Ticks: [{'name': 'tm', 'tvalue': '10/08/2021 10:41:56'}]
Ticks: [{'e': 'nse_cm', 'ltp': '309.85', 'ltq': '1', 'ltt': 'NA', 'name': 'sf', 'tk': '3063'}]
Ticks: [{'name': 'tm', 'tvalue': '10/08/2021 10:41:57'}]
Ticks: [{'e': 'nse_cm', 'ltp': '309.85', 'ltq': '95', 'ltt': 'NA', 'name': 'sf', 'tk': '3063'}]
Ticks: [{'name': 'tm', 'tvalue': '10/08/2021 10:41:58'}]
Ticks: [{'ap': '310.23', 'bp': '309.85', 'bq': '150', 'bs': '6725', 'c': '309.55', 'cng': '00.30', 'e': 'nse_cm', 'lo': '308.10', 'ltp': '309.85', 'ltq': '95', 'ltt': '10/08/2021 10:41:56', 'name': 'sf', 'nc': '00.0969', 'sp': '310.00', 'tbq': '748288', 'tk': '3063', 'to': '678133308.15', 'tsq': '1048198', 'v': '2185905'}]
Ticks: [{'e': 'nse_cm', 'ltp': '310.00', 'ltq': '200', 'ltt': 'NA', 'name': 'sf', 'tk': '3063'}]
Ticks: [{'name': 'tm', 'tvalue': '10/08/2021 10:41:59'}]

我如何存储这些数据,我不知道输出来自API的哪里。PS.这使用websockets,你可以在

找到详细信息https://github.com/angelbroking-github/smartapi-python

文档链接:

https://smartapi.angelbroking.com/docs/WebSocketStreaming

如果您想将数据存储为程序本身的变量,您可以将json数据附加到on_message函数中的列表

最新更新