Skip to content

Commit 5a4b99b

Browse files
committed
Fix JoinQuant persistence issue
1 parent fcd4c67 commit 5a4b99b

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

examples/simply_joinquant_strategy.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,34 @@
33

44
# 初始化函数,设定要操作的股票、基准等等
55
def initialize(context):
6-
# 创建 JoinQuantExecutor 对象
7-
# 可选参数包括:host, title, account 等
8-
g.executor = shipane_sdk.JoinQuantExecutor(host='xxx.xxx.xxx.xxx')
9-
106
# 定义一个全局变量, 保存要操作的股票
117
# 000001(股票:平安银行)
128
g.security = '000001.XSHE'
139
# 设定沪深300作为基准
1410
set_benchmark('000300.XSHG')
1511

1612

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+
1719
# 每个单位时间(如果按天回测,则每天调用一次,如果按分钟,则每分钟调用一次)调用一次
1820
def handle_data(context, data):
19-
security = g.security
20-
2121
# 保存 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))
2424

2525
# 实盘易依据聚宽的 order 对象下单
26-
response = g.executor.execute(order)
26+
response = g.__executor.execute(current_order)
2727
if response is not None:
2828
log.info('ShiPanE response:\nstatus_code: %d\ntext: %s', response.status_code, response.text)
2929
else:
3030
log.error('ShiPanE did not response')
3131

32+
current_order = order(g.security, -100)
33+
g.__executor.execute(current_order)
34+
3235
# 撤单
33-
g.executor.cancel(order)
36+
g.__executor.cancel(current_order)

0 commit comments

Comments
 (0)