mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-13 02:23:51 +00:00
bbgo.Sync profit stats
This commit is contained in:
parent
faaaaabce3
commit
468b73abb6
|
@ -23,9 +23,8 @@ exchangeStrategies:
|
||||||
dca2:
|
dca2:
|
||||||
symbol: ETHUSDT
|
symbol: ETHUSDT
|
||||||
short: false
|
short: false
|
||||||
budget: 200
|
quoteInvestment: "200"
|
||||||
maxOrderNum: 5
|
maxOrderCount: 5
|
||||||
priceDeviation: 1%
|
priceDeviation: "0.01"
|
||||||
takeProfitRatio: 0.2%
|
takeProfitRatio: "0.002"
|
||||||
coolDownInterval: 3m
|
coolDownInterval: 180
|
||||||
circuitBreakLossThreshold: -0.9
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ package dca2
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/c9s/bbgo/pkg/bbgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type State int64
|
type State int64
|
||||||
|
@ -177,12 +179,13 @@ func (s *Strategy) runOpenPositionOrdersCancelled(ctx context.Context, next Stat
|
||||||
s.logger.Info("[State] OpenPositionOrdersCancelled -> TakeProfitReady")
|
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
|
// wait 3 seconds to avoid position not update
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
|
|
||||||
s.logger.Info("[State] TakeProfitReady - start reseting position and calculate quote investment for next round")
|
s.logger.Info("[State] TakeProfitReady - start reseting position and calculate quote investment for next round")
|
||||||
s.QuoteInvestment = s.QuoteInvestment.Add(s.Position.Quote)
|
s.QuoteInvestment = s.QuoteInvestment.Add(s.Position.Quote)
|
||||||
|
s.ProfitStats.QuoteInvestment = s.QuoteInvestment
|
||||||
|
|
||||||
// reset position
|
// reset position
|
||||||
s.Position.Reset()
|
s.Position.Reset()
|
||||||
|
@ -191,6 +194,8 @@ func (s *Strategy) runTakeProfitReady(_ context.Context, next State) {
|
||||||
s.EmitProfit(s.ProfitStats)
|
s.EmitProfit(s.ProfitStats)
|
||||||
s.ProfitStats.FinishRound()
|
s.ProfitStats.FinishRound()
|
||||||
|
|
||||||
|
bbgo.Sync(ctx, s)
|
||||||
|
|
||||||
// set the start time of the next round
|
// set the start time of the next round
|
||||||
s.startTimeOfNextRound = time.Now().Add(s.CoolDownInterval.Duration())
|
s.startTimeOfNextRound = time.Now().Add(s.CoolDownInterval.Duration())
|
||||||
s.state = WaitToOpenPosition
|
s.state = WaitToOpenPosition
|
||||||
|
|
|
@ -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.OrderExecutor.TradeCollector().OnTrade(func(trade types.Trade, profit, netProfit fixedpoint.Value) {
|
||||||
s.ProfitStats.AddTrade(trade)
|
s.ProfitStats.AddTrade(trade)
|
||||||
|
bbgo.Sync(ctx, s)
|
||||||
})
|
})
|
||||||
|
|
||||||
s.OrderExecutor.ActiveMakerOrders().OnFilled(func(o types.Order) {
|
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 position %s", s.Position.String())
|
||||||
s.logger.Infof("[DCA] recovered quote investment %s", s.QuoteInvestment)
|
s.logger.Infof("[DCA] recovered quote investment %s", s.QuoteInvestment)
|
||||||
s.logger.Infof("[DCA] recovered startTimeOfNextRound %s", s.startTimeOfNextRound)
|
s.logger.Infof("[DCA] recovered startTimeOfNextRound %s", s.startTimeOfNextRound)
|
||||||
|
|
||||||
|
bbgo.Sync(ctx, s)
|
||||||
} else {
|
} else {
|
||||||
s.state = WaitToOpenPosition
|
s.state = WaitToOpenPosition
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user