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

股票行情接口,最全的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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值