mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
remove unused log
remove running field
This commit is contained in:
parent
1b33308450
commit
d13d882fc4
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/c9s/bbgo/pkg/bbgo"
|
|
||||||
"github.com/c9s/bbgo/pkg/exchange/retry"
|
"github.com/c9s/bbgo/pkg/exchange/retry"
|
||||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||||
"github.com/c9s/bbgo/pkg/types"
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
|
@ -33,18 +32,6 @@ func (s *Strategy) placeOpenPositionOrders(ctx context.Context) error {
|
||||||
|
|
||||||
s.debugOrders(createdOrders)
|
s.debugOrders(createdOrders)
|
||||||
|
|
||||||
// Running is false means this is new bot (no matter it has trades or not) in persistence
|
|
||||||
if !s.ProfitStats.Running {
|
|
||||||
for _, createdOrder := range createdOrders {
|
|
||||||
if s.ProfitStats.FromOrderID == 0 || s.ProfitStats.FromOrderID > createdOrder.OrderID {
|
|
||||||
s.ProfitStats.FromOrderID = createdOrder.OrderID
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s.ProfitStats.Running = true
|
|
||||||
|
|
||||||
bbgo.Sync(ctx, s)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,11 +21,6 @@ type ProfitStats struct {
|
||||||
TotalProfit fixedpoint.Value `json:"totalProfit,omitempty"`
|
TotalProfit fixedpoint.Value `json:"totalProfit,omitempty"`
|
||||||
TotalFee map[string]fixedpoint.Value `json:"totalFee,omitempty"`
|
TotalFee map[string]fixedpoint.Value `json:"totalFee,omitempty"`
|
||||||
|
|
||||||
// Running is used for testing by the same account
|
|
||||||
// Running is true -> this bot is still working, we need to use the values in persistence
|
|
||||||
// Running is false -> this bot is closed, we can reset all the values in persistence
|
|
||||||
Running bool `json:"running,omitempty"`
|
|
||||||
|
|
||||||
types.PersistenceTTL
|
types.PersistenceTTL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,11 +133,11 @@ func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
|
||||||
func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
|
func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
|
||||||
instanceID := s.InstanceID()
|
instanceID := s.InstanceID()
|
||||||
s.Session = session
|
s.Session = session
|
||||||
if s.ProfitStats == nil || !s.ProfitStats.Running {
|
if s.ProfitStats == nil {
|
||||||
s.ProfitStats = newProfitStats(s.Market, s.QuoteInvestment)
|
s.ProfitStats = newProfitStats(s.Market, s.QuoteInvestment)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Position == nil || !s.ProfitStats.Running {
|
if s.Position == nil {
|
||||||
s.Position = types.NewPositionFromMarket(s.Market)
|
s.Position = types.NewPositionFromMarket(s.Market)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +161,6 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
|
||||||
|
|
||||||
// order executor
|
// order executor
|
||||||
s.OrderExecutor.TradeCollector().OnPositionUpdate(func(position *types.Position) {
|
s.OrderExecutor.TradeCollector().OnPositionUpdate(func(position *types.Position) {
|
||||||
s.logger.Infof("[DCA] POSITION CHANGE: %s", position.String())
|
|
||||||
s.logger.Infof("[DCA] POSITION UPDATE: %s", s.Position.String())
|
s.logger.Infof("[DCA] POSITION UPDATE: %s", s.Position.String())
|
||||||
bbgo.Sync(ctx, s)
|
bbgo.Sync(ctx, s)
|
||||||
|
|
||||||
|
@ -203,7 +202,7 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
|
||||||
s.logger.Info("[DCA] user data stream authenticated")
|
s.logger.Info("[DCA] user data stream authenticated")
|
||||||
time.AfterFunc(3*time.Second, func() {
|
time.AfterFunc(3*time.Second, func() {
|
||||||
if isInitialize := s.initializeNextStateC(); !isInitialize {
|
if isInitialize := s.initializeNextStateC(); !isInitialize {
|
||||||
if s.RecoverWhenStart && s.ProfitStats.Running {
|
if s.RecoverWhenStart {
|
||||||
// recover
|
// recover
|
||||||
if err := s.recover(ctx); err != nil {
|
if err := s.recover(ctx); err != nil {
|
||||||
s.logger.WithError(err).Error("[DCA] something wrong when state recovering")
|
s.logger.WithError(err).Error("[DCA] something wrong when state recovering")
|
||||||
|
@ -264,8 +263,6 @@ func (s *Strategy) Close(ctx context.Context) error {
|
||||||
s.logger.WithError(err).Errorf("[DCA] there are errors when cancelling orders at close")
|
s.logger.WithError(err).Errorf("[DCA] there are errors when cancelling orders at close")
|
||||||
}
|
}
|
||||||
|
|
||||||
s.ProfitStats.Running = false
|
|
||||||
|
|
||||||
bbgo.Sync(ctx, s)
|
bbgo.Sync(ctx, s)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user