bbgo.Sync profit stats

This commit is contained in:
chiahung.lin 2024-01-03 13:54:38 +08:00
parent faaaaabce3
commit 468b73abb6
3 changed files with 14 additions and 7 deletions

View File

@ -23,9 +23,8 @@ exchangeStrategies:
dca2:
symbol: ETHUSDT
short: false
budget: 200
maxOrderNum: 5
priceDeviation: 1%
takeProfitRatio: 0.2%
coolDownInterval: 3m
circuitBreakLossThreshold: -0.9
quoteInvestment: "200"
maxOrderCount: 5
priceDeviation: "0.01"
takeProfitRatio: "0.002"
coolDownInterval: 180

View File

@ -3,6 +3,8 @@ package dca2
import (
"context"
"time"
"github.com/c9s/bbgo/pkg/bbgo"
)
type State int64
@ -177,12 +179,13 @@ func (s *Strategy) runOpenPositionOrdersCancelled(ctx context.Context, next Stat
s.logger.Info("[State] OpenPositionOrdersCancelled -> TakeProfitReady")
}
func (s *Strategy) runTakeProfitReady(_ context.Context, next State) {
func (s *Strategy) runTakeProfitReady(ctx context.Context, next State) {
// wait 3 seconds to avoid position not update
time.Sleep(3 * time.Second)
s.logger.Info("[State] TakeProfitReady - start reseting position and calculate quote investment for next round")
s.QuoteInvestment = s.QuoteInvestment.Add(s.Position.Quote)
s.ProfitStats.QuoteInvestment = s.QuoteInvestment
// reset position
s.Position.Reset()
@ -191,6 +194,8 @@ func (s *Strategy) runTakeProfitReady(_ context.Context, next State) {
s.EmitProfit(s.ProfitStats)
s.ProfitStats.FinishRound()
bbgo.Sync(ctx, s)
// set the start time of the next round
s.startTimeOfNextRound = time.Now().Add(s.CoolDownInterval.Duration())
s.state = WaitToOpenPosition

View File

@ -159,6 +159,7 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
s.OrderExecutor.TradeCollector().OnTrade(func(trade types.Trade, profit, netProfit fixedpoint.Value) {
s.ProfitStats.AddTrade(trade)
bbgo.Sync(ctx, s)
})
s.OrderExecutor.ActiveMakerOrders().OnFilled(func(o types.Order) {
@ -206,6 +207,8 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
s.logger.Infof("[DCA] recovered position %s", s.Position.String())
s.logger.Infof("[DCA] recovered quote investment %s", s.QuoteInvestment)
s.logger.Infof("[DCA] recovered startTimeOfNextRound %s", s.startTimeOfNextRound)
bbgo.Sync(ctx, s)
} else {
s.state = WaitToOpenPosition
}