小秦哥 发表于 前天 04:00

股票行情接口,最全的接入方法

股票行情接口,最全的api接入方法

股票行情数据对于投资者和生意业务员来说至关紧张。通过股票行情接口,可以轻松获取实时股票行情数据并实时做出决策。股票行情接口一般有两种,一种是WebSocket,一种是http,通过WebSocket可以获取逐笔的股票tick数据,实时而且高效;通过http接口可以获取股票行情接口中的股票历史数据;
WebSocket是一种高效的双向通讯协议,它允许数据的实时推送,避免了不停的轮询哀求。它提供了快速的数据传输速率,确保您获取到最新的市场行情数据。其次,WebSocket允许您订阅特定的数据源或股票数据产品,只吸收您感兴趣的信息,进步了数据的效率和可用性。
通过接入股票行情数据的HTTP接口,您可以将数据导入到本身的分析工具或系统中,进行更深入的数据分析、模子构建和决策支持
接入方法

哀求方式:Get
数据格式:尺度Json格式
数据时效:实时更新
API阐明文档:网页链接
Token注册:网页链接
实时盘口(买一卖一)接入方法

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
官网: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=%7B%22trace%22%3A%22python_http_test2%22%2C%22data%22%3A%7B%22symbol_list%22%3A%5B%7B%22code%22%3A%20%22700.HK%22%7D%2C%7B%22code%22%3A%20%22UNH.US%22%7D%2C%7B%22code%22%3A%20%22600416.SH%22%7D%5D%7D%7D'

resp1 = requests.get(url=test_url1, headers=test_headers)

# Decoded text returned by the request
text1 = resp1.text
print(text1) 实时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
官网: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=%7B%22trace%22%3A%22python_http_test1%22%2C%22data%22%3A%7B%22code%22%3A%22AAPL.US%22%2C%22kline_type%22%3A1%2C%22kline_timestamp_end%22%3A0%2C%22query_kline_num%22%3A2%2C%22adjust_type%22%3A0%7D%7D'

resp1 = requests.get(url=test_url1, headers=test_headers)

# Decoded text returned by the request
text1 = resp1.text
print(text1) 实时批量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
官网: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=%7B%22trace%22%3A%22python_http_test1%22%2C%22data%22%3A%7B%22code%22%3A%22AAPL.US%22%2C%22kline_type%22%3A1%2C%22kline_timestamp_end%22%3A0%2C%22query_kline_num%22%3A2%2C%22adjust_type%22%3A0%7D%7D'

resp1 = requests.get(url=test_url1, headers=test_headers)

# Decoded text returned by the request
text1 = resp1.text
print(text1)

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 股票行情接口,最全的接入方法