Skip to content

Commit d046ebb

Browse files
committed
fix policy.ID may confuse if appear in multiple run_policies
fix api_server.enable auto redirect to /dash in live mode
1 parent 97a992f commit d046ebb

File tree

17 files changed

+75
-71
lines changed

17 files changed

+75
-71
lines changed

biz/biz.go

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -193,26 +193,22 @@ Even if the job has no entry tasks, this method should be called to postpone the
193193
添加批量入场任务。
194194
即使job没有入场任务,也应该调用此方法,用于推迟入场时间TFEnterMS
195195
*/
196-
func AddBatchJob(account, tf string, job *strat.StratJob, isInfo bool) {
196+
func AddBatchJob(account, tf string, job *strat.StratJob, infoEnv *ta.BarEnv) {
197197
lockBatch.Lock()
198198
defer lockBatch.Unlock()
199199
key := fmt.Sprintf("%s_%s_%s", tf, account, job.Strat.Name)
200200
tasks, ok := strat.BatchTasks[key]
201201
if !ok {
202202
tasks = &strat.BatchMap{
203-
Map: make(map[string]*strat.BatchTask),
203+
Map: make(map[string]*strat.JobEnv),
204204
TFMSecs: int64(utils2.TFToSecs(tf) * 1000),
205205
}
206206
strat.BatchTasks[key] = tasks
207207
}
208208
// Delay 3s to wait for execution
209209
// 推迟3s等待执行
210210
tasks.ExecMS = btime.TimeMS() + core.DelayBatchMS
211-
var batchType = strat.BatchTypeInOut
212-
if isInfo {
213-
batchType = strat.BatchTypeInfo
214-
}
215-
tasks.Map[job.Symbol.Symbol] = &strat.BatchTask{Job: job, Type: batchType}
211+
tasks.Map[job.Symbol.Symbol] = &strat.JobEnv{Job: job, Env: infoEnv}
216212
}
217213

218214
func TryFireBatches(currMS int64) int {
@@ -241,38 +237,40 @@ func TryFireBatches(currMS int64) int {
241237
}
242238
continue
243239
}
244-
var enterJobs []*strat.StratJob
245-
var infoJobs = make(map[string]*strat.StratJob)
240+
var mainJobs []*strat.StratJob
241+
var infoJobs = make(map[string]*strat.JobEnv)
246242
var stgy *strat.TradeStrat
247243
for pair, task := range tasks.Map {
248244
stgy = task.Job.Strat
249-
if task.Type == strat.BatchTypeInOut {
250-
enterJobs = append(enterJobs, task.Job)
251-
} else if task.Type == strat.BatchTypeInfo {
252-
infoJobs[pair] = task.Job
245+
if task.Env == nil {
246+
mainJobs = append(mainJobs, task.Job)
253247
} else {
254-
panic(fmt.Sprintf("unsupport BatchType: %v", task.Type))
248+
infoJobs[pair] = task
255249
}
256250
}
257-
account := strings.Split(key, "_")[1]
251+
arr := strings.Split(key, "_")
252+
timeframe, account := arr[0], arr[1]
258253
openOds, lock := ormo.GetOpenODs(account)
259254
lock.Lock()
260255
allOrders := utils.ValsOfMap(openOds)
261256
lock.Unlock()
262257
delete(strat.BatchTasks, key)
263-
if len(enterJobs) > 0 {
258+
for _, job := range mainJobs {
259+
job.InitBar(allOrders)
260+
}
261+
if len(infoJobs) > 0 {
262+
stgy.OnBatchInfos(timeframe, infoJobs)
263+
}
264+
if len(mainJobs) > 0 {
264265
// Check all batch tasks at this time and decide which ones to enter or exit
265266
// 检查此时间所有批量任务,决定哪些入场或那些出场
266-
for _, job := range enterJobs {
267-
job.InitBar(allOrders)
268-
}
269-
stgy.OnBatchJobs(enterJobs)
267+
stgy.OnBatchJobs(mainJobs)
270268
// Perform entry/exit tasks
271269
// 执行入场/出场任务
272270
odMgr := GetOdMgr(account)
273271
var ents []*ormo.InOutOrder
274272
var exits []*ormo.InOutOrder
275-
for _, job := range enterJobs {
273+
for _, job := range mainJobs {
276274
if len(job.Entrys) == 0 && len(job.Exits) == 0 {
277275
continue
278276
}
@@ -290,9 +288,6 @@ func TryFireBatches(currMS int64) int {
290288
}
291289
}
292290
}
293-
if len(infoJobs) > 0 {
294-
stgy.OnBatchInfos(infoJobs)
295-
}
296291
}
297292
return waitNum
298293
}

biz/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ webhook:
118118
exception:
119119
content: '{name}: {status}'
120120
api_server:
121-
enabled: false
121+
enable: false
122122
bind_ip: 127.0.0.1
123123
port: 8001
124124
jwt_secret_key: '123456789'

biz/trader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (t *Trader) onAccountKline(account string, env *ta.BarEnv, bar *orm.InfoKli
128128
if !barExpired {
129129
isBatch = job.Strat.BatchInOut && job.Strat.OnBatchJobs != nil
130130
if isBatch {
131-
AddBatchJob(account, bar.TimeFrame, job, false)
131+
AddBatchJob(account, bar.TimeFrame, job, nil)
132132
} else {
133133
enters = append(enters, job.Entrys...)
134134
}
@@ -151,7 +151,7 @@ func (t *Trader) onAccountKline(account string, env *ta.BarEnv, bar *orm.InfoKli
151151
job.IsWarmUp = bar.IsWarmUp
152152
job.Strat.OnInfoBar(job, env, bar.Symbol, bar.TimeFrame)
153153
if job.Strat.BatchInfo && job.Strat.OnBatchInfos != nil {
154-
AddBatchJob(account, bar.TimeFrame, job, true)
154+
AddBatchJob(account, bar.TimeFrame, job, env)
155155
}
156156
}
157157
// 处理订单

config/biz.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -756,23 +756,23 @@ func DumpYaml(desensitize bool) ([]byte, *errs.Error) {
756756
return data, nil
757757
}
758758

759+
// ID return name_index
759760
func (c *RunPolicyConfig) ID() string {
760-
if c.Dirt == "" {
761-
return c.Name
762-
}
761+
return fmt.Sprintf("%s_%d", c.Name, c.Index)
762+
}
763+
764+
func (c *RunPolicyConfig) Key() string {
765+
name := c.Name
763766
if c.Dirt == "long" {
764-
return c.Name + ":l"
767+
name += ":l"
765768
} else if c.Dirt == "short" {
766-
return c.Name + ":s"
769+
name += ":s"
767770
} else {
768771
panic(fmt.Sprintf("unknown run_policy dirt: %v", c.Dirt))
769772
}
770-
}
771-
772-
func (c *RunPolicyConfig) Key() string {
773773
tfStr := strings.Join(c.RunTimeframes, "|")
774774
pairStr := strings.Join(c.Pairs, "|")
775-
return fmt.Sprintf("%s/%s/%s", c.ID(), tfStr, pairStr)
775+
return fmt.Sprintf("%s/%s/%s", name, tfStr, pairStr)
776776
}
777777

778778
func (c *RunPolicyConfig) OdDirt() int {
@@ -889,6 +889,7 @@ func (c *RunPolicyConfig) ToYaml() string {
889889

890890
func (c *RunPolicyConfig) Clone() *RunPolicyConfig {
891891
res := &RunPolicyConfig{
892+
Index: c.Index,
892893
Name: c.Name,
893894
Filters: c.Filters,
894895
RunTimeframes: c.RunTimeframes,

config/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ type RunPolicyConfig struct {
150150
PairParams map[string]map[string]float64 `yaml:"pair_params,omitempty" mapstructure:"pair_params"`
151151
defs map[string]*core.Param
152152
Score float64
153+
Index int // index in run_policy array
153154
}
154155

155156
type StratPerfConfig struct {

core/data.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ var (
4343
MemProfile bool
4444

4545
ConcurNum = 2 // The maximum number of K-line tasks to be downloaded at the same time. If it is too high, a 429 current limit will occur. 最大同时下载K线任务数,过大会出现429限流
46-
Version = "v0.2.14-beta.3"
47-
UIVersion = "v0.2.12"
46+
Version = "v0.2.14-beta.4"
47+
UIVersion = "v0.2.14-beta.4"
4848
SysLang string // language code for current system 当前系统语言设置
4949
LogFile string
5050
DevDbPath string

doc/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ webhook: # 发送消息的配置
172172
exception:
173173
content: '{name}: {status}'
174174
api_server: # 供外部通过api控制机器人
175-
enabled: true
175+
enable: true
176176
bind_ip: 127.0.0.1
177177
port: 8001
178178
jwt_secret_key: nj234hujivhguih2rj3y4234nkjoghfy9088weurt

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.23.0
44

55
require (
66
github.com/anyongjin/go-bayesopt v1.0.2
7-
github.com/banbox/banexg v0.2.23
7+
github.com/banbox/banexg v0.2.25
88
github.com/banbox/banta v0.2.0
99
github.com/c-bata/goptuna v0.9.0
1010
github.com/dgraph-io/ristretto v0.2.0

go.sum

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7X
33
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
44
github.com/anyongjin/go-bayesopt v1.0.2 h1:845NHAdxk4x1FxeOS5McoaWO33ZfE2AR434j9lnEHAM=
55
github.com/anyongjin/go-bayesopt v1.0.2/go.mod h1:KB64n3O9sPBql6pPnOKh0w8bnOSG1TIMNb+9c/9iQs0=
6-
github.com/banbox/banexg v0.2.23 h1:7ao69yvBYOD3pOoqeFTm9uOnNpbfqF0SC6gtq6XReKc=
7-
github.com/banbox/banexg v0.2.23/go.mod h1:OW31oCQoMsPjetaPgtTgHZvBzn34t2CzYYA4iW3TWIs=
6+
github.com/banbox/banexg v0.2.24 h1:/JvL1p9iv4WLzacetDiFMW0yLrup8LL60fDN94dKngI=
7+
github.com/banbox/banexg v0.2.24/go.mod h1:OW31oCQoMsPjetaPgtTgHZvBzn34t2CzYYA4iW3TWIs=
8+
github.com/banbox/banexg v0.2.25/go.mod h1:OW31oCQoMsPjetaPgtTgHZvBzn34t2CzYYA4iW3TWIs=
89
github.com/banbox/banta v0.2.0 h1:fXdPHrPBDi3PQTV14pm84yBKIH2teB/3LQ9BUpTmIhI=
910
github.com/banbox/banta v0.2.0/go.mod h1:+9PG7f4QZtfpJfKpGp7aToOUg2ByatDosHjjvGFjaVc=
1011
github.com/beevik/ntp v1.4.3 h1:PlbTvE5NNy4QHmA4Mg57n7mcFTmr1W1j3gcK7L1lqho=

opt/common.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,12 @@ func (o *OptInfo) runGetBtResult(pol *config.RunPolicyConfig) {
113113
o.BTResult = bt.BTResult
114114
}
115115

116-
func (o *OptInfo) ToPol(name, dirt, tfStr, pairStr string) *config.RunPolicyConfig {
116+
func (o *OptInfo) ToPol(idx int, name, dirt, tfStr, pairStr string) *config.RunPolicyConfig {
117117
if o.Dirt == "" {
118118
o.Dirt = dirt
119119
}
120120
res := &config.RunPolicyConfig{
121+
Index: idx,
121122
Name: name,
122123
Dirt: o.Dirt,
123124
Params: o.Params,

0 commit comments

Comments
 (0)