Repository navigation
Expand file tree
/
Copy pathget_push_data.py
More file actions
executable file
·121 lines (95 loc) · 3.52 KB
/
Copy pathget_push_data.py
File metadata and controls
executable file
·121 lines (95 loc) · 3.52 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- coding: utf-8 -*-
"""
Examples for use the python functions: get push data
"""
from futuquant.open_context import *
class StockQuoteTest(StockQuoteHandlerBase):
"""
获得报价推送数据
"""
def on_recv_rsp(self, rsp_str):
"""数据响应回调函数"""
ret_code, content = super(StockQuoteTest, self).on_recv_rsp(rsp_str)
if ret_code != RET_OK:
print("StockQuoteTest: error, msg: %s" % content)
return RET_ERROR, content
print("StockQuoteTest\n ", content)
return RET_OK, content
class OrderBookTest(OrderBookHandlerBase):
"""
获得摆盘推送数据
"""
def on_recv_rsp(self, rsp_str):
"""数据响应回调函数"""
ret_code, content = super(OrderBookTest, self).on_recv_rsp(rsp_str)
if ret_code != RET_OK:
print("OrderBookTest: error, msg: %s" % content)
return RET_ERROR, content
print("OrderBookTest\n", content)
return RET_OK, content
class CurKlineTest(CurKlineHandlerBase):
"""
获取K线推送数据
"""
def on_recv_rsp(self, rsp_str):
"""数据响应回调函数"""
ret_code, content = super(CurKlineTest, self).on_recv_rsp(rsp_str)
if ret_code != RET_OK:
print("CurKlineTest: error, msg: %s" % content)
return RET_ERROR, content
print("CurKlineTest\n", content)
return RET_OK, content
class TickerTest(TickerHandlerBase):
"""
获取逐笔推送数据
"""
def on_recv_rsp(self, rsp_str):
"""数据响应回调函数"""
ret_code, content = super(TickerTest, self).on_recv_rsp(rsp_str)
if ret_code != RET_OK:
print("TickerTest: error, msg: %s" % content)
return RET_ERROR, content
print("TickerTest\n", content)
return RET_OK, content
class RTDataTest(RTDataHandlerBase):
"""
获取分时推送数据
"""
def on_recv_rsp(self, rsp_str):
"""数据响应回调函数"""
ret_code, content = super(RTDataTest, self).on_recv_rsp(rsp_str)
if ret_code != RET_OK:
print("RTDataTest: error, msg: %s" % content)
return RET_ERROR, content
print("RTDataTest\n")
print(content)
return RET_OK, content
class BrokerTest(BrokerHandlerBase):
"""
获取经纪队列推送数据
"""
def on_recv_rsp(self, rsp_str):
"""数据响应回调函数"""
ret_code, content = super(BrokerTest, self).on_recv_rsp(rsp_str)
if ret_code != RET_OK:
print("BrokerTest: error, msg: %s " % content)
return RET_ERROR, content
print("BrokerTest\n", content[0])
print("BrokerTest\n", content[1])
return RET_OK, content
if __name__ == "__main__":
quote_context = OpenQuoteContext(host='127.0.0.1', port=11111)
# 获取推送数据
quote_context.subscribe('HK.00700', "QUOTE", push=True)
quote_context.set_handler(StockQuoteTest())
quote_context.subscribe('HK.00700', "K_DAY", push=True)
quote_context.set_handler(CurKlineTest())
quote_context.subscribe('HK.00700', "ORDER_BOOK", push=True)
quote_context.set_handler(OrderBookTest())
quote_context.subscribe('HK.00700', "TICKER", push=True)
quote_context.set_handler(TickerTest())
quote_context.subscribe('HK.00700', "RT_DATA", push=True)
quote_context.set_handler(RTDataTest())
quote_context.subscribe('HK.00700', "BROKER", push=True)
quote_context.set_handler(BrokerTest())
quote_context.start()