gitee.com/quant1x/engine@v1.8.4/cache/cache_trader.go (about) 1 package cache 2 3 import ( 4 "fmt" 5 "gitee.com/quant1x/engine/config" 6 "gitee.com/quant1x/gox/api" 7 "strings" 8 "sync" 9 ) 10 11 const ( 12 keyOrdersPath = "qmt" // QMT订单缓存路径 13 ) 14 15 var ( 16 qmtOnce sync.Once 17 qmtOrderPath = "" // QMT订单路径 18 ) 19 20 // QMT默认路径 21 func defaultQmtCachePath() string { 22 path := fmt.Sprintf("%s/%s", GetRootPath(), keyOrdersPath) 23 return path 24 } 25 26 func lazyInitQmt() { 27 traderParameter := &config.GlobalConfig.Trader 28 traderParameter.OrderPath = strings.TrimSpace(traderParameter.OrderPath) 29 if len(traderParameter.OrderPath) > 0 && api.CheckFilepath(traderParameter.OrderPath, true) == nil { 30 // 如果配置了路径且有效 31 qmtOrderPath = traderParameter.OrderPath 32 } else { 33 qmtOrderPath = defaultQmtCachePath() 34 } 35 traderParameter.OrderPath = qmtOrderPath 36 } 37 38 func initMiniQmt() { 39 qmtOnce.Do(lazyInitQmt) 40 } 41 42 // GetQmtCachePath QMT订单文件路径 43 func GetQmtCachePath() string { 44 qmtOnce.Do(lazyInitQmt) 45 return qmtOrderPath 46 }