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

股票行情数据对于投资者和交易员来说至关重要。通过股票行情接口,可以轻松获取实时股票行情数据并及时做出决策。股票行情接口一般有两种,一种是WebSocket,一种是http,通过WebSocket可以获取逐笔的股票tick数据,实时并且高效;通过http接口可以获取历史数据;

WebSocket是一种高效的双向通信协议,它允许数据的实时推送,避免了不断的轮询请求。它提供了快速的数据传输速度,确保您获取到最新的市场行情数据。其次,WebSocket允许您订阅特定的数据源或股票数据产品,只接收您感兴趣的信息,提高了数据的效率和可用性。

通过接入股票行情数据的HTTP接口,您可以将数据导入到自己的分析工具或系统中,进行更深入的数据分析、模型构建和决策支持

接入方法

请求方式:Get

数据格式:标准Json格式

数据时效:实时更新

数据源:alltick api

API说明文档,浏览器搜索:alltick api

Token注册,浏览器搜索:alltick api


实时盘口(买一卖一)接入方法

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)
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.


实时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)
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.

实时批量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)
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.