forked from yutiansut/QUANTAXIS
-
Notifications
You must be signed in to change notification settings - Fork 8
/
about_event.py
94 lines (66 loc) · 3.86 KB
/
about_event.py
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
# coding: utf-8
import QUANTAXIS as QA
"""
在这里 我们演示两种方法
1. 直接通过QA_Thread 创建一个事件线程做任务
2. 通过QA_Engine 来创建一个QA_Thread 来分派事件
"""
thread = QA.QA_Thread() # 创建一个QA_Thread
engine = QA.QA_Engine() # 创建一个QA_Engine
engine.start() # engine 开启
engine.create_kernel('backtest') # engine创建一个叫 backtest的线程
engine.start_kernel('backtest') # engine 启动该线程
# 创建一个类,继承QA_Worker
class job(QA.QA_Worker):
def __init__(self):
super().__init__()
def run(self, event):
if event.event_type is 'selfdesign':
print(vars(event))
print( )
if event.callback:
event.callback(event.message)
else:
print('unknown/unsupport event type')
jobx = job() # 实例化这个类
# 创建一个event
event = QA.QA_Event(event_type='selfdesign', message='ssss', callback=print)
# 创建一个标准task
task = QA.QA_Task(event=event, worker=jobx, engine='backtest')
# task有result方法
print(task.result)
thread.start() # 开启thread 线程
thread.put(task) # 向thread线程推送任务
engine.run_job(task) # 向engine推送任务
engine.stop_all()
engine.join()
thread.join()
thread.stop()
""" 运行结果
PS E:\quantaxis> & python e:/quantaxis/Documents/about_event.py
QUANTAXIS>> start QUANTAXIS
QUANTAXIS>> Welcome to QUANTAXIS, the Version is 1.0.58
QUANTAXIS>>
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
``########`````##````````##``````````##`````````####````````##```##########````````#``````##``````###```##`````######``
`##``````## ```##````````##`````````####````````##`##```````##```````##```````````###``````##````##`````##```##`````##`
##````````##```##````````##````````##`##````````##``##``````##```````##``````````####```````#```##``````##```##``````##
##````````##```##````````##```````##```##```````##```##`````##```````##`````````##`##```````##`##```````##````##```````
##````````##```##````````##``````##`````##``````##````##````##```````##````````##``###```````###````````##`````##``````
##````````##```##````````##``````##``````##`````##`````##```##```````##```````##````##```````###````````##``````###````
##````````##```##````````##`````##````````##````##``````##``##```````##``````##``````##`````##`##```````##````````##```
##````````##```##````````##````#############````##```````##`##```````##`````###########`````##``##``````##`````````##``
###```````##```##````````##```##```````````##```##```````##`##```````##````##`````````##```##```##``````##```##`````##`
`##``````###````##``````###``##`````````````##``##````````####```````##```##``````````##``###````##`````##````##`````##
``#########``````########```##``````````````###`##``````````##```````##``##````````````##`##``````##````##`````###``###
````````#####`````````````````````````````````````````````````````````````````````````````````````````````````````##``
```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
``````````````````````````Copyright``yutiansut``2018``````QUANTITATIVE FINANCIAL FRAMEWORK`````````````````````````````
```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
{'task_id': 'Task_YWSF2Psa', 'result': None}
{'event_type': 'selfdesign', 'func': None, 'message': 'ssss', 'callback': <built-in function print>}{'event_type': 'selfdesign', 'func': None, 'message': 'ssss', 'callback': <built-in function print>}
ssss
ssss
"""