File tree Expand file tree Collapse file tree 5 files changed +24
-40
lines changed
Expand file tree Collapse file tree 5 files changed +24
-40
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,4 @@ def process_initialize(context):
1717
1818
1919def 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 ()
Original file line number Diff line number Diff line change 1- import tushare as ts
2-
31import shipane_sdk
42
53
@@ -18,16 +16,4 @@ def process_initialize(context):
1816
1917
2018def 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 ()
Original file line number Diff line number Diff line change @@ -18,7 +18,4 @@ def before_trading(context):
1818
1919
2020def 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 ()
Original file line number Diff line number Diff line change 1- import tushare as ts
2-
31import shipane_sdk
42
53
@@ -14,20 +12,8 @@ def initialize(context):
1412def 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
2018def 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 ()
Original file line number Diff line number Diff line change 22
33import time
44
5+ import tushare as ts
6+
57from shipane_sdk .client import *
68from shipane_sdk .models import *
79from 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 )
You can’t perform that action at this time.
0 commit comments