diff --git a/config/rebalance.yaml b/config/rebalance.yaml index 8a6f7f8bd..14a784c93 100644 --- a/config/rebalance.yaml +++ b/config/rebalance.yaml @@ -33,10 +33,9 @@ exchangeStrategies: targetWeights: BTC: 50% ETH: 25% - MAX: 15% - USDT: 10% + USDT: 25% threshold: 1% maxAmount: 1_000 # max amount to buy or sell per order orderType: LIMIT_MAKER # LIMIT, LIMIT_MAKER or MARKET dryRun: false - onStart: false + onStart: true diff --git a/pkg/strategy/rebalance/order_executor_map.go b/pkg/strategy/rebalance/order_executor_map.go index 45fd3272e..a4d0d386f 100644 --- a/pkg/strategy/rebalance/order_executor_map.go +++ b/pkg/strategy/rebalance/order_executor_map.go @@ -14,6 +14,7 @@ func NewGeneralOrderExecutorMap(session *bbgo.ExchangeSession, positionMap Posit m := make(GeneralOrderExecutorMap) for symbol, position := range positionMap { + log.Infof("creating order executor for symbol %s", symbol) orderExecutor := bbgo.NewGeneralOrderExecutor(session, symbol, ID, instanceID(symbol), position) m[symbol] = orderExecutor } @@ -29,6 +30,7 @@ func (m GeneralOrderExecutorMap) BindEnvironment(environ *bbgo.Environment) { func (m GeneralOrderExecutorMap) BindProfitStats(profitStatsMap ProfitStatsMap) { for symbol, orderExecutor := range m { + log.Infof("binding profit stats for symbol %s", symbol) orderExecutor.BindProfitStats(profitStatsMap[symbol]) } } @@ -50,6 +52,7 @@ func (m GeneralOrderExecutorMap) Sync(ctx context.Context, obj interface{}) { func (m GeneralOrderExecutorMap) SubmitOrders(ctx context.Context, submitOrders ...types.SubmitOrder) (types.OrderSlice, error) { var allCreatedOrders types.OrderSlice for _, submitOrder := range submitOrders { + log.Infof("submitting order: %+v", submitOrder) orderExecutor, ok := m[submitOrder.Symbol] if !ok { return nil, fmt.Errorf("order executor not found for symbol %s", submitOrder.Symbol) diff --git a/pkg/strategy/rebalance/position_map.go b/pkg/strategy/rebalance/position_map.go index 162da96f9..5bbbfeb9c 100644 --- a/pkg/strategy/rebalance/position_map.go +++ b/pkg/strategy/rebalance/position_map.go @@ -6,15 +6,17 @@ import ( type PositionMap map[string]*types.Position -func NewPositionMap(markets []types.Market) PositionMap { - m := make(PositionMap) - +func (m PositionMap) createPositions(markets []types.Market) PositionMap { for _, market := range markets { + if _, ok := m[market.Symbol]; ok { + continue + } + + log.Infof("creating position for symbol %s", market.Symbol) position := types.NewPositionFromMarket(market) position.Strategy = ID position.StrategyInstanceID = instanceID(market.Symbol) m[market.Symbol] = position } - return m } diff --git a/pkg/strategy/rebalance/profit_stats_map.go b/pkg/strategy/rebalance/profit_stats_map.go index eba460be0..b7db6c2fb 100644 --- a/pkg/strategy/rebalance/profit_stats_map.go +++ b/pkg/strategy/rebalance/profit_stats_map.go @@ -4,12 +4,14 @@ import "github.com/c9s/bbgo/pkg/types" type ProfitStatsMap map[string]*types.ProfitStats -func NewProfitStatsMap(markets []types.Market) ProfitStatsMap { - m := make(ProfitStatsMap) - +func (m ProfitStatsMap) createProfitStats(markets []types.Market) ProfitStatsMap { for _, market := range markets { + if _, ok := m[market.Symbol]; ok { + continue + } + + log.Infof("creating profit stats for symbol %s", market.Symbol) m[market.Symbol] = types.NewProfitStats(market) } - return m } diff --git a/pkg/strategy/rebalance/strategy.go b/pkg/strategy/rebalance/strategy.go index 1774fc7d3..e9650b704 100644 --- a/pkg/strategy/rebalance/strategy.go +++ b/pkg/strategy/rebalance/strategy.go @@ -99,12 +99,14 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo. } if s.PositionMap == nil { - s.PositionMap = NewPositionMap(markets) + s.PositionMap = make(PositionMap) } + s.PositionMap.createPositions(markets) if s.ProfitStatsMap == nil { - s.ProfitStatsMap = NewProfitStatsMap(markets) + s.ProfitStatsMap = make(ProfitStatsMap) } + s.ProfitStatsMap.createProfitStats(markets) s.orderExecutorMap = NewGeneralOrderExecutorMap(session, s.PositionMap) s.orderExecutorMap.BindEnvironment(s.Environment)