2023-03-12 15:48:26 +00:00
|
|
|
package rebalance
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/c9s/bbgo/pkg/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PositionMap map[string]*types.Position
|
|
|
|
|
2023-03-15 08:01:13 +00:00
|
|
|
func (m PositionMap) CreatePositions(markets []types.Market) PositionMap {
|
2023-03-12 15:48:26 +00:00
|
|
|
for _, market := range markets {
|
2023-03-14 06:37:54 +00:00
|
|
|
if _, ok := m[market.Symbol]; ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Infof("creating position for symbol %s", market.Symbol)
|
2023-03-12 15:48:26 +00:00
|
|
|
position := types.NewPositionFromMarket(market)
|
|
|
|
position.Strategy = ID
|
|
|
|
position.StrategyInstanceID = instanceID(market.Symbol)
|
|
|
|
m[market.Symbol] = position
|
|
|
|
}
|
|
|
|
return m
|
|
|
|
}
|