如何获取Level2行情接口连接?
深交所Level-2行情,市場需求量確實比較大。
很多人需要滬深L2實時行情,但是也有很多人只要深交所L2行情,不要上交所L2行情。我接觸過的只要一種行情的,都是只要深交所的,沒有說只要上交所不要深交所的。
至于深交所Level2實時行情程序接口,最好的是直接向深交所采購。延遲最低,行情質(zhì)量最高,穩(wěn)定性最好。當(dāng)然,收費也是最貴的,采購流程也是很麻煩的,對程序開發(fā)者的技術(shù)能力要求也是最高的。支持的接口語言還挺多的,支持C++、C#、Java、Python,window和linux系統(tǒng)都支持。
Level2行情接口鏈接
1.下載行情工具
https://gitee.com/l2gogogo/l2-push-python/tree/master/cli
2.目錄說明
名稱 說明
conf 配置目錄
data 數(shù)據(jù)目錄
log 日志目錄
txtool 命令行工具-Linux
txtool.exe 命令行工具-Windows
3.行情工具常用命令
命令 說明
txtool -h 查看幫助
txtool version 查看工具版本號
txtool proxy 啟動本地代理服務(wù)器。默認(rèn)命令,Windows可直接雙擊執(zhí)行
4.接入說明
1.下載行情工具,修改conf/proxy.toml
1.設(shè)置用戶名和密碼:User/Passwd
2.設(shè)置推送服務(wù)器地址:RpcServer/TcpServer
2.打開命令窗口,切換到cli目錄,執(zhí)行命令啟動本地代理服務(wù)器
1.Linux系統(tǒng)執(zhí)行:txtool proxy
2.Windows系統(tǒng)執(zhí)行:txtool.exe proxy
3.如果提示本機端口已占用,可修改配置項Address(代理服務(wù)器監(jiān)聽地址)
3.啟動成功,調(diào)用代理服務(wù)器提供的GRPC接口
1.接口地址見配置項Address,默認(rèn)為:localhost:8090
2.接口定義,見目錄proto
4.代理服務(wù)器配置
1.proxy.toml 配置代理服務(wù)器監(jiān)聽地址,是否將推送消息寫入本地文件等
2.log.toml 配置日志格式,是否寫入控制臺和文件等
Level2行情接口
l接口定義,見目錄proto
訂閱事件
get_subscription查詢訂閱
add_subscription新增訂閱
del_subscription取消訂閱
數(shù)據(jù)推送事件
tick_record_stream 推送逐筆成交行情數(shù)據(jù)
order_record_stream 推送逐筆委托行情數(shù)據(jù)
order_queue_record_stream推送委托隊列行情數(shù)據(jù)
stock_quote_record_stream 推送股票十檔行情行情數(shù)據(jù)
代碼示例
# -*- coding: utf-8 -*-
# 此Demo只是演示接入過程
import grpc
import entity_pb2
import proxy_pb2_grpc
import threading
from multiprocessing import Process
# 代理服務(wù)器監(jiān)聽的地址和端口
ServerConnect = grpc.insecure_channel('localhost:5000')
Stub = proxy_pb2_grpc.ProxyStub(ServerConnect)
# 查詢訂閱
def get_subscription():
? ? # rep返回code為1代表成功,其余狀態(tài)碼可參考接入文檔,data是返回訂閱股票的情況
? ? Result = Stub.GetSubscription(entity_pb2.Void())
? ? print(Result)
# 新增訂閱
def add_subscription():
? ? # 實例ProtoBuf協(xié)議的方法
? ? String = entity_pb2.String()
? ? # 修改協(xié)議的值
? ? # 2:市場代碼標(biāo)識(1為上海證券,2為深圳證券)
? ? # 000002:股票代碼
? ? # 15:訂閱全部標(biāo)識(1為逐筆成交,2為逐筆委托,4為委托隊列,8為股票十檔行情,如果想全部訂閱可直接填入15,原理是1+2+4+8,如果想訂閱某幾個行情將幾個行情標(biāo)識相加即可)
? ? String.value = '2_000002_15'
? ? # String.value = '2_000001_15,2_000002_5,2_000003_12,批量訂閱'
? ? # rep返回code為1代表成功,其余狀態(tài)碼可參考接入文檔
? ? Result = Stub.AddSubscription(String)
? ? print(Result)
# 取消訂閱
def del_subscription():
? ? # 實例ProtoBuf協(xié)議的方法
? ? String = entity_pb2.String()
? ? # 修改協(xié)議的值
? ? # 2:市場代碼標(biāo)識(1為上海證券,2為深圳證券)
? ? # 000002:股票代碼
? ? # 15:取消全部標(biāo)識(1為逐筆成交,2為逐筆委托,4為委托隊列,8為股票十檔行情,如果想全部取消可直接填入15,原理是1+2+4+8,如果想取消某幾個行情將幾個行情標(biāo)識相加即可)
? ? String.value = '2_000002_15'
? ? # String.value = '2_000001_15,2_000002_5,2_000003_12,批量取消'
? ? # rep返回code為1代表成功,其余狀態(tài)碼可參考接入文檔
? ? Result = Stub.DelSubscription(String)
? ? print(Result)
# 推送逐筆成交行情數(shù)據(jù)
def tick_record_stream():
? ? StreamResult = Stub.NewTickRecordStream(entity_pb2.Void())
? ? # 用For循環(huán)就可以不斷消費數(shù)據(jù)
? ? for Result in StreamResult:
? ? ? ? print(Result)
# 推送逐筆委托行情數(shù)據(jù)
def order_record_stream():
? ? StreamResult = Stub.NewOrderRecordStream(entity_pb2.Void())
? ? # 用For循環(huán)就可以不斷消費數(shù)據(jù)
? ? for Result in StreamResult:
? ? ? ? print(Result)
# 推送委托隊列行情數(shù)據(jù)
def order_queue_record_stream():
? ? StreamResult = Stub.NewOrderQueueRecordStream(entity_pb2.Void())
? ? # 用For循環(huán)就可以不斷消費數(shù)據(jù)
? ? for Result in StreamResult:
? ? ? ? print(Result)
# 推送股票十檔行情行情數(shù)據(jù)
def stock_quote_record_stream():
? ? StreamResult = Stub.NewStockQuoteRecordStream(entity_pb2.Void())
? ? # 用For循環(huán)就可以不斷消費數(shù)據(jù)
? ? for Result in StreamResult:
? ? ? ? print(Result)
if __name__ == '__main__':
? ? # 可以使用多線程并發(fā)接收推送數(shù)據(jù)
? ? ThreadOne = threading.Thread(target=tick_record_stream)
? ? ThreadTwo = threading.Thread(target=order_record_stream)
? ? ThreadThree = threading.Thread(target=order_queue_record_stream)
? ? ThreadFour = threading.Thread(target=stock_quote_record_stream)
? ? # 多進程并發(fā)接收推送數(shù)據(jù)
? ? # ProcessOne = Process(target=tick_record_stream)
? ? # ProcessTwo = Process(target=order_record_stream)
? ? # ProcessThree = Process(target=order_queue_record_stream)
? ? # ProcessFour = Process(target=stock_quote_record_stream)
? ? # 這設(shè)置為隨主線程退出子線程,避免產(chǎn)生孤兒或僵尸線程
? ? ThreadOne.daemon = True
? ? ThreadTwo.daemon = True
? ? ThreadThree.daemon = True
? ? ThreadFour.daemon = True
? ? # ProcessOne.daemon = True
? ? # ProcessTwo.daemon = True
? ? # ProcessThree.daemon = True
? ? # ProcessFour.daemon = True
? ? # 有一點值得注意一下,假如訂閱的股票相對活躍,推送的數(shù)據(jù)就不會有休眠的狀態(tài)出現(xiàn),因為Python的GIL鎖,所以用多線程接收推送效率不顯著,這個時候可以考慮用多進程來接收推送
? ? ThreadOne.start()
? ? ThreadTwo.start()
? ? ThreadThree.start()
? ? ThreadFour.start()
? ? # ProcessOne.start()
? ? # ProcessTwo.start()
? ? # ProcessThree.start()
? ? # ProcessFour.start()
? ? ThreadOne.join()
? ? ThreadTwo.join()
? ? ThreadThree.join()
? ? ThreadFour.join()
? ? # ProcessOne.join()
? ? # ProcessTwo.join()
? ? # ProcessThree.join()
? ? # ProcessFour.join()
總結(jié)
以上是生活随笔為你收集整理的如何获取Level2行情接口连接?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 病毒分类
- 下一篇: 在VM安装最新版Linux镜像