Skip to content

Commit 58d4e5f

Browse files
committed
update to 0.2x
1 parent c77c67e commit 58d4e5f

File tree

9 files changed

+76
-56
lines changed

9 files changed

+76
-56
lines changed

Diff for: .idea/.gitignore

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/QACTPBeeBroker.iml

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/inspectionProfiles/profiles_settings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/misc.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: QACTPBeeBroker/__init__.py

+32-54
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,56 @@
1-
import multiprocessing
2-
from string import digits
3-
import json
4-
from json import dumps
5-
from datetime import time, datetime, date
6-
from time import sleep
7-
8-
from ctpbee import ExtAbstract
9-
from ctpbee import CtpBee
10-
from ctpbee import subscribe
1+
from datetime import date
112

12-
from QAPUBSUB.producer import publisher_routing
133
import pymongo
4+
from QAPUBSUB.producer import publisher_routing
5+
from ctpbee import CtpBee
6+
from ctpbee import CtpbeeApi
7+
from ctpbee import dumps
8+
from ctpbee import auth_time
149

15-
16-
def auth_time(timed):
17-
from datetime import time
18-
DAY_START = time(9, 0) # 日盘启动和停止时间
19-
DAY_END = time(15, 0)
20-
NIGHT_START = time(21, 0) # 夜盘启动和停止时间
21-
NIGHT_END = time(2, 30)
22-
23-
if timed <= DAY_END and timed >= DAY_START:
24-
return True
25-
if timed >= NIGHT_START:
26-
return True
27-
if timed <= NIGHT_END:
28-
return True
29-
return False
30-
31-
32-
class DataRecorder(ExtAbstract):
10+
class DataRecorder(CtpbeeApi):
3311
def __init__(self, name, app=None):
3412
super().__init__(name, app)
35-
self.tick_database_name = "tick"
36-
self.bar_base_name = "bar"
37-
self.shared_data = {}
38-
self.created = False
39-
self.recover = False
40-
self.move = []
41-
self.mimi = set()
4213
self.pub = publisher_routing(exchange='CTPX', routing_key='')
4314

4415
def on_trade(self, trade):
4516
pass
4617

4718
def on_contract(self, contract):
48-
pass
19+
""" 订阅所有合约代码 """
20+
self.app.subscribe(contract.symbol)
4921

5022
def on_order(self, order):
5123
pass
5224

25+
def on_log(self, log):
26+
""" 处理log信息 """
27+
pass
28+
5329
def on_tick(self, tick):
54-
"""tick process function"""
55-
symbol = tick.symbol
56-
r = tick.__dict__
30+
""" 处理tick推送 """
31+
if not auth_time(tick.datetime.time()):
32+
return
5733
try:
58-
r['exchange'] = str(tick.exchange.value)
59-
r['datetime'] = str(r['datetime'])
60-
x = json.dumps(r)
61-
self.pub.pub(x, routing_key=r['symbol'])
34+
x = dumps(tick) #
35+
self.pub.pub(x, routing_key=tick.symbol)
6236
except Exception as e:
6337
print(e)
6438

6539
def on_bar(self, bar):
66-
"""bar process function"""
67-
bar.exchange = bar.exchange.value
68-
interval = bar.interval
40+
""" 处理bar推送 """
41+
pass
42+
43+
def on_position(self, position) -> None:
44+
""" 处理持仓推送 """
45+
pass
46+
47+
def on_account(self, account) -> None:
48+
""" 处理账户信息 """
49+
pass
6950

7051
def on_shared(self, shared):
71-
"""process shared function"""
72-
# print(shared)
52+
""" 处理分时图数据 """
53+
pass
7354

7455

7556
def go():
@@ -88,7 +69,8 @@ def go():
8869
}
8970

9071
app.config.from_mapping(info)
91-
data_recorder = DataRecorder("data_recorder", app)
72+
data_recorder = DataRecorder("data_recorder")
73+
app.add_extension(data_recorder) # 或者直接 data_recorder = DataRecorder("data_recorder", app)
9274
app.start()
9375
print('start engine')
9476
import time
@@ -106,10 +88,6 @@ def go():
10688
contractdb.update_one({'gateway_name': 'ctp', 'symbol': cont['symbol']}, {
10789
'$set': cont}, upsert=True)
10890

109-
for contract in app.recorder.get_all_contracts():
110-
print(contract.symbol)
111-
subscribe(contract.symbol)
112-
11391

11492
if __name__ == '__main__':
11593
go()

Diff for: QACTPBeeBroker/sub.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from QAPUBSUB.consumer import subscriber_routing
22
import click
33

4-
54
@click.command()
65
@click.option('--code',default='rb1910')
76
def sub(code):

Diff for: readme.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
quantaxis的 ctpbee https://github.com/somewheve/ctpbee/ 对接
44

5-
ctpbee这个项目用的太爽了...再次感谢somewhere
5+
ctpbee这个项目用的太爽了...再次感谢somewheve
6+
7+
更新时间: 2019-7-28
8+
更新内容: 更换ctpbee到0.2+的行情支持
69

710

811

0 commit comments

Comments
 (0)