Skip to content

Commit a0822d3

Browse files
committed
Support multiple jobs for same job type
1 parent fe51337 commit a0822d3

File tree

2 files changed

+95
-42
lines changed

2 files changed

+95
-42
lines changed

config/scheduler-template.ini

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
; ShiPanE-Python-SDK 支持的计划任务类型如下:
2+
;
3+
; NewStocks: 新股申购
4+
; Repo: 逆回购
5+
; Batch: 批量下单
6+
; JoinQuant: 聚宽跟单
7+
; JoinQuantArena: 聚宽擂台(商城)同步
8+
; RiceQuant: 米筐策略跟单
9+
; Uquer: 优矿策略跟单
10+
; Guorn: 果仁策略同步
11+
;
112
; schedule 参数设置,类似于 cron 表达式
213
;
314
; 格式为:[秒(0-59)] [分(0-59)] [时(0-23)] [星期几(0-6 或英文缩写)] [星期(1-53)] [日(1-31)] [月(1-12)] [年(四位数字)]
@@ -34,9 +45,11 @@ client2=account:12345
3445

3546

3647
;
37-
; 自动新股申购配置
48+
; 新股申购
3849
;
3950
[NewStocks]
51+
type=NewStocks
52+
4053
; 是否启用?
4154
enabled=false
4255

@@ -49,9 +62,11 @@ clients=client1
4962

5063

5164
;
52-
; 自动逆回购配置
65+
; 逆回购
5366
;
5467
[Repo]
68+
type=Repo
69+
5570
; 是否启用?
5671
enabled=false
5772

@@ -66,9 +81,11 @@ security=131810
6681

6782

6883
;
69-
; 批量下单配置
84+
; 批量下单
7085
;
7186
[Batch]
87+
type=Batch
88+
7289
; 是否启用?
7390
enabled=false
7491

@@ -82,7 +99,12 @@ clients=client1
8299
folder=C:\\batch-orders
83100

84101

85-
[JoinQuant]
102+
;
103+
; 聚宽策略跟单
104+
;
105+
[JoinQuant-1]
106+
type=JoinQuant
107+
86108
username=
87109
password=
88110

@@ -105,9 +127,11 @@ clients=client1
105127

106128

107129
;
108-
; 聚宽擂台同步
130+
; 聚宽擂台(商城)同步
109131
;
110-
[JoinQuantArena]
132+
[JoinQuantArena-1]
133+
type=JoinQuantArena
134+
111135
; 聚宽账号密码
112136
username=
113137
password=
@@ -173,7 +197,12 @@ order_interval=1
173197
extra_rounds=0
174198

175199

176-
[RiceQuant]
200+
;
201+
; 米筐策略跟单
202+
;
203+
[RiceQuant-1]
204+
type=RiceQuant
205+
177206
username=
178207
password=
179208

@@ -194,7 +223,12 @@ schedule=30 */1 9-15 mon-fri * * * *
194223
clients=client1
195224

196225

197-
[Uqer]
226+
;
227+
; 优矿策略跟单
228+
;
229+
[Uqer-1]
230+
type=Uqer
231+
198232
username=
199233
password=
200234

@@ -216,13 +250,16 @@ clients=client1
216250

217251

218252
;
219-
; 果仁自动同步设置
253+
; 果仁策略同步
254+
;
220255
; 自动同步采用多个轮次,典型的轮次如下:
221256
; 1. 卖单及可用资金可以满足的买单
222257
; 2. 前一次未成交的部分卖单及可用资金可以满足的买单
223258
; 3. 额外轮次将重复步骤 2
224259
;
225-
[Guorn]
260+
[Guorn-1]
261+
type=Guorn
262+
226263
; 手机号码前需加上 +86,例如:+8615012345678
227264
username=
228265
password=

shipane_sdk/scheduler.py

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ def __init__(self):
4040
self._client = Client(self._logger, **dict(self._config.items('ShiPanE')))
4141

4242
def start(self):
43-
self.__add_job(self.__create_new_stock_purchase_job())
44-
self.__add_job(self.__create_repo_job())
45-
self.__add_job(self.__create_batch_job())
46-
self.__add_job(self.__create_join_quant_following_job())
47-
self.__add_job(self.__create_rice_quant_following_job())
48-
self.__add_job(self.__create_uqer_following_job())
49-
self.__add_job(self.__create_guorn_sync_job())
50-
self.__add_job(self.__create_join_quant_sync_job())
43+
for section in self._config.sections():
44+
if not self.__is_job(section):
45+
continue
46+
job = self.__create_job(section)
47+
if job is not None:
48+
self.__add_job(job)
49+
else:
50+
self._logger.warning("[{}] is not a valid job", section)
5151

5252
self._scheduler.start()
5353
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
@@ -64,64 +64,80 @@ def __add_job(self, job):
6464
else:
6565
self._logger.warning('{} is not enabled'.format(job.name))
6666

67-
def __create_new_stock_purchase_job(self):
68-
section = 'NewStocks'
67+
def __create_job(self, section):
68+
job_type = self._config.get(section, 'type')
69+
job = None
70+
if job_type == 'NewStocks':
71+
job = self.__create_new_stock_purchase_job(section)
72+
elif job_type == 'Repo':
73+
job = self.__create_repo_job(section)
74+
elif job_type == 'Batch':
75+
job = self.__create_batch_job(section)
76+
elif job_type == 'JoinQuant':
77+
job = self.__create_join_quant_following_job(section)
78+
elif job_type == 'RiceQuant':
79+
job = self.__create_rice_quant_following_job(section)
80+
elif job_type == 'Uqer':
81+
job = self.__create_uqer_following_job(section)
82+
elif job_type == 'Guorn':
83+
job = self.__create_guorn_sync_job(section)
84+
elif job_type == 'JoinQuantArena':
85+
job = self.__create_join_quant_sync_job(section)
86+
return job
87+
88+
def __create_new_stock_purchase_job(self, section):
6989
options = self.__build_options(section)
7090
client_aliases = self.__filter_client_aliases(section)
71-
return NewStockPurchaseJob(self._client, client_aliases, '{}Job'.format(section), **options)
91+
return NewStockPurchaseJob(self._client, client_aliases, '{}-Job'.format(section), **options)
7292

73-
def __create_repo_job(self):
74-
section = 'Repo'
93+
def __create_repo_job(self, section):
7594
options = self.__build_options(section)
7695
client_aliases = self.__filter_client_aliases(section)
77-
return RepoJob(self._client, client_aliases, '{}Job'.format(section), **options)
96+
return RepoJob(self._client, client_aliases, '{}-Job'.format(section), **options)
7897

79-
def __create_batch_job(self):
80-
section = 'Batch'
98+
def __create_batch_job(self, section):
8199
options = self.__build_options(section)
82100
client_aliases = self.__filter_client_aliases(section)
83-
return BatchJob(self._client, client_aliases, '{}Job'.format(section), **options)
101+
return BatchJob(self._client, client_aliases, '{}-Job'.format(section), **options)
84102

85-
def __create_join_quant_following_job(self):
86-
section = 'JoinQuant'
103+
def __create_join_quant_following_job(self, section):
87104
options = self.__build_options(section)
88105
client_aliases = self.__filter_client_aliases(section)
89106
quant_client = JoinQuantClient(**options)
90-
return OnlineQuantFollowingJob(self._client, quant_client, client_aliases, '{}FollowingJob'.format(section),
107+
return OnlineQuantFollowingJob(self._client, quant_client, client_aliases, '{}-FollowingJob'.format(section),
91108
**options)
92109

93-
def __create_rice_quant_following_job(self):
94-
section = 'RiceQuant'
110+
def __create_rice_quant_following_job(self, section):
95111
options = self.__build_options(section)
96112
client_aliases = self.__filter_client_aliases(section)
97113
quant_client = RiceQuantClient(**options)
98-
return OnlineQuantFollowingJob(self._client, quant_client, client_aliases, '{}FollowingJob'.format(section),
114+
return OnlineQuantFollowingJob(self._client, quant_client, client_aliases, '{}-FollowingJob'.format(section),
99115
**options)
100116

101-
def __create_uqer_following_job(self):
102-
section = 'Uqer'
117+
def __create_uqer_following_job(self, section):
103118
options = self.__build_options(section)
104119
client_aliases = self.__filter_client_aliases(section)
105120
quant_client = UqerClient(**options)
106-
return OnlineQuantFollowingJob(self._client, quant_client, client_aliases, '{}FollowingJob'.format(section),
121+
return OnlineQuantFollowingJob(self._client, quant_client, client_aliases, '{}-FollowingJob'.format(section),
107122
**options)
108123

109-
def __create_guorn_sync_job(self):
110-
section = 'Guorn'
124+
def __create_guorn_sync_job(self, section):
111125
options = self.__build_options(section)
112126
client_aliases = self.__filter_client_aliases(section)
113127
quant_client = GuornClient(**options)
114-
return OnlineQuantSyncJob(self._client, quant_client, client_aliases, '{}SyncJob'.format(section),
128+
return OnlineQuantSyncJob(self._client, quant_client, client_aliases, '{}-SyncJob'.format(section),
115129
**options)
116130

117-
def __create_join_quant_sync_job(self):
118-
section = 'JoinQuantArena'
131+
def __create_join_quant_sync_job(self, section):
119132
options = self.__build_options(section)
120133
client_aliases = self.__filter_client_aliases(section)
121134
quant_client = JoinQuantClient(**options)
122-
return OnlineQuantSyncJob(self._client, quant_client, client_aliases, '{}SyncJob'.format(section),
135+
return OnlineQuantSyncJob(self._client, quant_client, client_aliases, '{}-SyncJob'.format(section),
123136
**options)
124137

138+
def __is_job(self, section):
139+
return self._config.has_option(section, 'type')
140+
125141
def __build_options(self, section):
126142
if not self._config.has_section(section):
127143
return dict()

0 commit comments

Comments
 (0)