bbgo_origin/pkg/strategy/rebalance/position_map.go

23 lines
512 B
Go
Raw Permalink Normal View History

2023-03-12 15:48:26 +00:00
package rebalance
import (
"github.com/c9s/bbgo/pkg/types"
)
type PositionMap map[string]*types.Position
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
}