mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 00:05:15 +00:00
xgap: initialize logger
This commit is contained in:
parent
8dcd6f2f72
commit
2ea0c86c67
|
@ -34,7 +34,7 @@ func (s *Strategy) ID() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Strategy) InstanceID() string {
|
func (s *Strategy) InstanceID() string {
|
||||||
return fmt.Sprintf("%s:%s", ID, s.Symbol)
|
return fmt.Sprintf("%s:%s:%s", ID, s.TradingExchange, s.Symbol)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Strategy struct {
|
type Strategy struct {
|
||||||
|
@ -43,12 +43,15 @@ type Strategy struct {
|
||||||
|
|
||||||
Environment *bbgo.Environment
|
Environment *bbgo.Environment
|
||||||
|
|
||||||
Symbol string `json:"symbol"`
|
Symbol string `json:"symbol"`
|
||||||
SourceExchange string `json:"sourceExchange"`
|
TradingExchange string `json:"tradingExchange"`
|
||||||
TradingExchange string `json:"tradingExchange"`
|
|
||||||
MinSpread fixedpoint.Value `json:"minSpread"`
|
SourceSymbol string `json:"sourceSymbol"`
|
||||||
Quantity fixedpoint.Value `json:"quantity"`
|
SourceExchange string `json:"sourceExchange"`
|
||||||
DryRun bool `json:"dryRun"`
|
|
||||||
|
MinSpread fixedpoint.Value `json:"minSpread"`
|
||||||
|
Quantity fixedpoint.Value `json:"quantity"`
|
||||||
|
DryRun bool `json:"dryRun"`
|
||||||
|
|
||||||
DailyMaxVolume fixedpoint.Value `json:"dailyMaxVolume,omitempty"`
|
DailyMaxVolume fixedpoint.Value `json:"dailyMaxVolume,omitempty"`
|
||||||
DailyTargetVolume fixedpoint.Value `json:"dailyTargetVolume,omitempty"`
|
DailyTargetVolume fixedpoint.Value `json:"dailyTargetVolume,omitempty"`
|
||||||
|
@ -63,6 +66,8 @@ type Strategy struct {
|
||||||
lastSourceKLine, lastTradingKLine types.KLine
|
lastSourceKLine, lastTradingKLine types.KLine
|
||||||
sourceBook, tradingBook *types.StreamOrderBook
|
sourceBook, tradingBook *types.StreamOrderBook
|
||||||
|
|
||||||
|
logger logrus.FieldLogger
|
||||||
|
|
||||||
stopC chan struct{}
|
stopC chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +79,12 @@ func (s *Strategy) Initialize() error {
|
||||||
if s.FeeBudget == nil {
|
if s.FeeBudget == nil {
|
||||||
s.FeeBudget = &common.FeeBudget{}
|
s.FeeBudget = &common.FeeBudget{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.logger = logrus.WithFields(logrus.Fields{
|
||||||
|
"strategy": ID,
|
||||||
|
"strategy_instance": s.InstanceID(),
|
||||||
|
"symbol": s.Symbol,
|
||||||
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +96,11 @@ func (s *Strategy) Defaults() error {
|
||||||
if s.UpdateInterval == 0 {
|
if s.UpdateInterval == 0 {
|
||||||
s.UpdateInterval = types.Duration(time.Second)
|
s.UpdateInterval = types.Duration(time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.SourceSymbol == "" {
|
||||||
|
s.SourceSymbol = s.Symbol
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,8 +110,8 @@ func (s *Strategy) CrossSubscribe(sessions map[string]*bbgo.ExchangeSession) {
|
||||||
panic(fmt.Errorf("source session %s is not defined", s.SourceExchange))
|
panic(fmt.Errorf("source session %s is not defined", s.SourceExchange))
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSession.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: "1m"})
|
sourceSession.Subscribe(types.KLineChannel, s.SourceSymbol, types.SubscribeOptions{Interval: "1m"})
|
||||||
sourceSession.Subscribe(types.BookChannel, s.Symbol, types.SubscribeOptions{Depth: types.DepthLevel5})
|
sourceSession.Subscribe(types.BookChannel, s.SourceSymbol, types.SubscribeOptions{Depth: types.DepthLevel5})
|
||||||
|
|
||||||
tradingSession, ok := sessions[s.TradingExchange]
|
tradingSession, ok := sessions[s.TradingExchange]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -153,7 +169,7 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
|
||||||
})
|
})
|
||||||
|
|
||||||
if s.SourceExchange != "" {
|
if s.SourceExchange != "" {
|
||||||
s.sourceBook = types.NewStreamBook(s.Symbol, sourceSession.ExchangeName)
|
s.sourceBook = types.NewStreamBook(s.SourceSymbol, sourceSession.ExchangeName)
|
||||||
s.sourceBook.BindStream(s.sourceSession.MarketDataStream)
|
s.sourceBook.BindStream(s.sourceSession.MarketDataStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user