python接入实时股票行情数据 | python代码速记 | python 技术论坛-金年会app官方网

python接入alltick api的方法,接入后可以查询股票的实时和历史报价,亲测可用。

请求k线

import time
import requests
import json
# extra headers
test_headers = {
    'content-type':'application/json'
}
'''
github:https://github.com/alltick/realtime-forex-crypto-stock-tick-finance-websocket-api
申请免费token:https://alltick.co/register
金年会app官方网官网:https://alltick.co
将如下json进行url的encode,复制到http的查询字符串的query字段里
{"trace":"python_http_test1","data":{"code":"aapl.us","kline_type":1,"kline_timestamp_end":0,"query_kline_num":2,"adjust_type":0}}
'''
test_url1 = 'https://quote.tradeswitcher.com/quote-stock-b-api/kline?token=e945d7d9-9e6e-4721-922a-7251a9d311d0-1678159756806&query={"trace":"python_http_test1","data":{"code":"aapl.us","kline_type":1,"kline_timestamp_end":0,"query_kline_num":2,"adjust_type":0}}'
resp1 = requests.get(url=test_url1, headers=test_headers)
# decoded text returned by the request
text1 = resp1.text
print(text1)

上面代码中是以查询苹果股票(aapl.us)分钟k线为例子的,如果想查询其它类型的k线数据则kline_type传入以下值:1-分钟k,2-为5分钟k,3-为15分钟k,4-为30分钟k,5-为小时k,6-为2小时k,7-为4小时k,8-为日k,9-为周k,10-为月k。
2.2、请求最新成交报价数据

获取最新成交报价数据对于量化策略的分析和判断至关重要。接下来,我将分享如何直接获取这些数据的代码示例:
echarts render error:
syntaxerror: unexpected token ‘i’, “import tim”… is not valid json
上面代码中symbol_list是可以同时传入多个的,分别传入不同的市场的产品也是可以的。

获取最新盘口报价数据


import time
import requests
import json
# extra headers
test_headers = {
    'content-type':'application/json'
}
'''
github:https://github.com/alltick/realtime-forex-crypto-stock-tick-finance-websocket-api
申请免费token:https://alltick.co/register
金年会app官方网官网:https://alltick.co
将如下json进行url的encode,复制到http的查询字符串的query字段里
{"trace":"python_http_test2","data":{"symbol_list":[{"code": "700.hk"},{"code": "unh.us"},{"code": "600416.sh"}]}}
'''
test_url1 = 'https://quote.tradeswitcher.com/quote-stock-b-api/depth-tick?token=e945d7d9-9e6e-4721-922a-7251a9d311d0-1678159756806&query={"trace":"python_http_test2","data":{"symbol_list":[{"code": "700.hk"},{"code": "unh.us"},{"code": "600416.sh"}]}}'
resp1 = requests.get(url=test_url1, headers=test_headers)
# decoded text returned by the request
text1 = resp1.text
print(text1)
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
网站地图