mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-27 09:15:15 +00:00
xmaker: merge all markets into one
This commit is contained in:
parent
e3a2a857cd
commit
51aa34dec7
|
@ -150,6 +150,8 @@ type Strategy struct {
|
|||
|
||||
makerMarket, sourceMarket types.Market
|
||||
|
||||
allMarkets types.MarketMap
|
||||
|
||||
// boll is the BOLLINGER indicator we used for predicting the price.
|
||||
boll *indicatorv2.BOLLStream
|
||||
|
||||
|
@ -1393,9 +1395,6 @@ func (s *Strategy) CrossRun(
|
|||
|
||||
s.sourceSession = sourceSession
|
||||
|
||||
// initialize the price resolver
|
||||
sourceMarkets := s.sourceSession.Markets()
|
||||
|
||||
makerSession, ok := sessions[s.MakerExchange]
|
||||
if !ok {
|
||||
return fmt.Errorf("maker exchange session %s is not defined", s.MakerExchange)
|
||||
|
@ -1413,6 +1412,10 @@ func (s *Strategy) CrossRun(
|
|||
return fmt.Errorf("maker session market %s is not defined", s.Symbol)
|
||||
}
|
||||
|
||||
sourceMarkets := s.sourceSession.Markets()
|
||||
makerMarkets := s.makerSession.Markets()
|
||||
s.allMarkets = sourceMarkets.Merge(makerMarkets)
|
||||
|
||||
indicators := s.sourceSession.Indicators(s.Symbol)
|
||||
|
||||
s.boll = indicators.BOLL(types.IntervalWindow{
|
||||
|
@ -1469,7 +1472,7 @@ func (s *Strategy) CrossRun(
|
|||
})
|
||||
}
|
||||
|
||||
s.priceSolver = pricesolver.NewSimplePriceResolver(sourceMarkets)
|
||||
s.priceSolver = pricesolver.NewSimplePriceResolver(s.allMarkets)
|
||||
s.priceSolver.BindStream(s.sourceSession.MarketDataStream)
|
||||
|
||||
s.accountValueCalculator = bbgo.NewAccountValueCalculator(s.sourceSession, s.priceSolver, s.sourceMarket.QuoteCurrency)
|
||||
|
|
|
@ -270,3 +270,22 @@ func (m MarketMap) Has(symbol string) bool {
|
|||
_, ok := m[symbol]
|
||||
return ok
|
||||
}
|
||||
|
||||
// Merge merges the given market map into the current market map
|
||||
// if the market already exists, it will be skipped
|
||||
func (m MarketMap) Merge(b MarketMap) MarketMap {
|
||||
var a = MarketMap{}
|
||||
for k, v := range m {
|
||||
a[k] = v
|
||||
}
|
||||
|
||||
for k, v := range b {
|
||||
if _, exists := a[k]; exists {
|
||||
continue
|
||||
}
|
||||
|
||||
a[k] = v
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user