|
3 | 3 |
|
4 | 4 | # 初始化函数,设定要操作的股票、基准等等 |
5 | 5 | def initialize(context): |
6 | | - # 创建 JoinQuantExecutor 对象 |
7 | | - # 可选参数包括:host, title, account 等 |
8 | | - g.executor = shipane_sdk.JoinQuantExecutor(host='xxx.xxx.xxx.xxx') |
9 | | - |
10 | 6 | # 定义一个全局变量, 保存要操作的股票 |
11 | 7 | # 000001(股票:平安银行) |
12 | 8 | g.security = '000001.XSHE' |
13 | 9 | # 设定沪深300作为基准 |
14 | 10 | set_benchmark('000300.XSHG') |
15 | 11 |
|
16 | 12 |
|
| 13 | +def process_initialize(context): |
| 14 | + # 创建 JoinQuantExecutor 对象 |
| 15 | + # 可选参数包括:host, port, title, account 等 |
| 16 | + g.__executor = shipane_sdk.JoinQuantExecutor(host='xxx.xxx.xxx.xxx') |
| 17 | + |
| 18 | + |
17 | 19 | # 每个单位时间(如果按天回测,则每天调用一次,如果按分钟,则每分钟调用一次)调用一次 |
18 | 20 | def handle_data(context, data): |
19 | | - security = g.security |
20 | | - |
21 | 21 | # 保存 order 对象 |
22 | | - order = order_value('000001.XSHE', 1000) |
23 | | - log.info('JointQuant executed:\n%s', str(order)) |
| 22 | + current_order = order('000001.XSHE', 100) |
| 23 | + log.info('JointQuant executed:\n%s', str(current_order)) |
24 | 24 |
|
25 | 25 | # 实盘易依据聚宽的 order 对象下单 |
26 | | - response = g.executor.execute(order) |
| 26 | + response = g.__executor.execute(current_order) |
27 | 27 | if response is not None: |
28 | 28 | log.info('ShiPanE response:\nstatus_code: %d\ntext: %s', response.status_code, response.text) |
29 | 29 | else: |
30 | 30 | log.error('ShiPanE did not response') |
31 | 31 |
|
| 32 | + current_order = order(g.security, -100) |
| 33 | + g.__executor.execute(current_order) |
| 34 | + |
32 | 35 | # 撤单 |
33 | | - g.executor.cancel(order) |
| 36 | + g.__executor.cancel(current_order) |
0 commit comments