什么是Tick数据
Tick数据,又被称为逐笔行情数据,是市场上最为细致、完整的数据之一。举例来说,当投资者下达一笔新的委托或者股票交易所完成一笔新的成交时,就会形成一笔股票Tick行情。每一笔股票Tick数据行情都记录着市场中的每一个重要事件,为金融交易提供了精准而全面的股票数据支持。
另一方面,快照行情,又被称为切片行情,顾名思义,是对股票Tick数据行情某一特定时刻的快速汇总数据。举例而言,现在广泛使用的期货500毫秒一笔的行情,即将500毫秒内的最高价、最低价、以及成交量等数据进行汇总。这些数据点的汇总形成了一笔快照行情。
举例说明
某天的市场一开始的时候苹果股票的order book(委托挂单)清空(这里不进行auction period的探讨):
1、接着来了第一个卖家:1000@100 :
这时候交易所会发给你一个message,告诉你是苹果股票有人想以100块钱卖出1000股,那么这个order就先挂在了order book上,成为卖一。
2、第二个卖家来了,他想卖得更高: 1000@101:
这时候交易所会发给你另一个message,告诉你是苹果股票有人卖的价格比你差,于是排序在更上面,卖二。以此类推
股票tick数据如何获取
数据来源:打开链接
请求方式:Get
数据格式:标准Json格式[{},...{}]
数据时效:实时更新
API说明文档:打开链接
import json
# Extra headers
test_headers = {
'Content-Type': 'application/json'
}
'''
# Special Note:
# GitHub: https://github.com/alltick/realtime-forex-crypto-stock-tick-finance-websocket-api
# Token Application: https://alltick.co
# Replace "testtoken" in the URL below with your own token
# API addresses for forex, cryptocurrencies, and precious metals:
# https://quote.tradeswitcher.com/quote-b-ws-api
# Stock API address:
# https://quote.tradeswitcher.com/quote-stock-b-ws-api
Encode the following JSON and copy it to the "query" field of the HTTP query string
{"trace": "python_http_test1", "data": {"code": "700.HK", "kline_type": 1, "kline_timestamp_end": 0, "query_kline_num": 2, "adjust_type": 0}}
{"trace": "python_http_test2", "data": {"symbol_list": [{"code": "700.HK"}, {"code": "UNH.US"}]}}
{"trace": "python_http_test3", "data": {"symbol_list": [{"code": "700.HK"}, {"code": "UNH.US"}]}}
'''
test_url1 = 'https://quote.tradeswitcher.com/quote-stock-b-api/kline?token=testtoken&query=%7B%22trace%22%20%3A%20%22python_http_test1%22%2C%22data%22%20%3A%20%7B%22code%22%20%3A%20%22700.HK%22%2C%22kline_type%22%20%3A%201%2C%22kline_timestamp_end%22%20%3A%200%2C%22query_kline_num%22%20%3A%202%2C%22adjust_type%22%3A%200%7D%7D'
test_url2 = 'https://quote.tradeswitcher.com/quote-stock-b-api/depth-tick?token=testtoken&query=%7B%22trace%22%20%3A%20%22python_http_test2%22%2C%22data%22%20%3A%20%7B%22symbol_list%22%3A%20%5B%7B%22code%22%3A%20%22700.HK%22%7D%2C%7B%22code%22%3A%20%22UNH.US%22%7D%5D%7D%7D'
test_url3 = 'https://quote.tradeswitcher.com/quote-stock-b-api/trade-tick?token=testtoken&query=%7B%22trace%22%20%3A%20%22python_http_test3%22%2C%22data%22%20%3A%20%7B%22symbol_list%22%3A%20%5B%7B%22code%22%3A%20%22700.HK%22%7D%2C%7B%22code%22%3A%20%22UNH.US%22%7D%5D%7D%7D'
resp1 = requests.get(url=test_url1, headers=test_headers)
time.sleep(1)
resp2 = requests.get(url=test_url2, headers=test_headers)
time.sleep(1)
resp3 = requests.get(url=test_url3, headers=test_headers)
# Decoded text returned by the request
text1 = resp1.text
print(text1)
text2 = resp2.text
print(text2)
text3 = resp3.text
print(text3)