Skip to content

Commit 7160292

Browse files
committed
Fix repo task for RiceQuant; simplify tasks for online quant
1 parent 5ff8dd9 commit 7160292

File tree

5 files changed

+24
-40
lines changed

5 files changed

+24
-40
lines changed

examples/joinquant/new_stocks_purchase.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,4 @@ def process_initialize(context):
1717

1818

1919
def purchase_new_stocks(context):
20-
if context.run_params.type == 'sim_trade':
21-
g.__manager.purchase_new_stocks()
22-
else:
23-
log.info('回测中不进行新股申购')
20+
g.__manager.purchase_new_stocks()

examples/joinquant/repo.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import tushare as ts
2-
31
import shipane_sdk
42

53

@@ -18,16 +16,4 @@ def process_initialize(context):
1816

1917

2018
def repo(context):
21-
if context.run_params.type == 'sim_trade':
22-
security = '131810'
23-
df = ts.get_realtime_quotes(security)
24-
order = {
25-
'action': 'SELL',
26-
'symbol': security,
27-
'type': 'LIMIT',
28-
'price': float(df['bid'][0]),
29-
'amountProportion': 'ALL'
30-
}
31-
g.__manager.execute(**order)
32-
else:
33-
log.info('回测中不进行逆回购')
19+
g.__manager.repo()

examples/ricequant/new_stocks_purchase.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,4 @@ def before_trading(context):
1818

1919

2020
def purchase_new_stocks(context, bar_dict):
21-
if context.run_info.run_type == RUN_TYPE.PAPER_TRADING:
22-
context.__manager.purchase_new_stocks()
23-
else:
24-
logger.info('回测中不进行新股申购')
21+
context.__manager.purchase_new_stocks()

examples/ricequant/repo.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import tushare as ts
2-
31
import shipane_sdk
42

53

@@ -14,20 +12,8 @@ def initialize(context):
1412
def process_initialize(context):
1513
# 创建 RiceQuantStrategyManagerFactory 对象
1614
# 参数为 shipane_sdk_config_template.yaml 中配置的 manager id
17-
g.__manager = shipane_sdk.RiceQuantStrategyManagerFactory(context).create('manager-1')
15+
context.__manager = shipane_sdk.RiceQuantStrategyManagerFactory(context).create('manager-1')
1816

1917

2018
def repo(context):
21-
if context.run_info.run_type == RUN_TYPE.PAPER_TRADING:
22-
security = '131810'
23-
quote_df = ts.get_realtime_quotes(security)
24-
order = {
25-
'action': 'SELL',
26-
'symbol': security,
27-
'type': 'LIMIT',
28-
'price': float(quote_df['bid'][0]),
29-
'amountProportion': 'ALL'
30-
}
31-
g.__manager.execute(**order)
32-
else:
33-
log.info('回测中不进行逆回购')
19+
context.__manager.repo()

shipane_sdk/base_manager.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import time
44

5+
import tushare as ts
6+
57
from shipane_sdk.client import *
68
from shipane_sdk.models import *
79
from shipane_sdk.support import *
@@ -106,6 +108,22 @@ def purchase_new_stocks(self):
106108
except:
107109
self._logger.exception('[%s] 打新失败', trader.id)
108110

111+
def repo(self):
112+
security = '131810'
113+
quote_df = ts.get_realtime_quotes(security)
114+
order = {
115+
'action': 'SELL',
116+
'symbol': security,
117+
'type': 'LIMIT',
118+
'price': float(quote_df['bid'][0]),
119+
'amountProportion': 'ALL'
120+
}
121+
for trader in self._traders.values():
122+
try:
123+
trader.execute(**order)
124+
except:
125+
self._logger.exception('[%s] 逆回购失败', trader.id)
126+
109127
def execute(self, order=None, **kwargs):
110128
if order is None and not kwargs:
111129
return
@@ -330,7 +348,7 @@ def _is_expired(self, common_order):
330348

331349
def _pre_check(self):
332350
if not self._config['enabled']:
333-
self._logger.info("[%s] 同步未启用,不执行", self.id)
351+
self._logger.info("[%s] 交易未启用,不执行", self.id)
334352
return False
335353
if self._strategy_context.is_backtest():
336354
self._logger.info("[%s] 当前为回测环境,不执行", self.id)

0 commit comments

Comments
 (0)