@@ -2,12 +2,14 @@ package common
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
5
6
"sync"
6
7
"time"
7
8
8
9
log "github.com/sirupsen/logrus"
9
10
"golang.org/x/sync/errgroup"
10
11
12
+ "github.com/c9s/bbgo/pkg/bbgo"
11
13
"github.com/c9s/bbgo/pkg/exchange/batch"
12
14
"github.com/c9s/bbgo/pkg/types"
13
15
)
@@ -101,3 +103,38 @@ func (f *ProfitFixer) FixFromTrades(allTrades []types.Trade, stats *types.Profit
101
103
log .Infof ("profitFixer fix finished: profitStats and position are updated from %d trades" , len (allTrades ))
102
104
return nil
103
105
}
106
+
107
+ type ProfitFixerBundle struct {
108
+ ProfitFixerConfig * ProfitFixerConfig `json:"profitFixer,omitempty"`
109
+ }
110
+
111
+ func (f * ProfitFixerBundle ) Fix (
112
+ ctx context.Context ,
113
+ symbol string ,
114
+ position * types.Position ,
115
+ profitStats * types.ProfitStats ,
116
+ sessions ... * bbgo.ExchangeSession ,
117
+ ) error {
118
+ bbgo .Notify ("Fixing %s profitStats and position..." , symbol )
119
+
120
+ log .Infof ("profitFixer is enabled, checking checkpoint: %+v" , f .ProfitFixerConfig .TradesSince )
121
+
122
+ if f .ProfitFixerConfig .TradesSince .Time ().IsZero () {
123
+ return fmt .Errorf ("tradesSince time can not be zero" )
124
+ }
125
+
126
+ fixer := NewProfitFixer ()
127
+ for _ , session := range sessions {
128
+ if ss , ok := session .Exchange .(types.ExchangeTradeHistoryService ); ok {
129
+ log .Infof ("adding makerSession %s to profitFixer" , session .Name )
130
+ fixer .AddExchange (session .Name , ss )
131
+ }
132
+ }
133
+
134
+ return fixer .Fix (ctx ,
135
+ symbol ,
136
+ f .ProfitFixerConfig .TradesSince .Time (),
137
+ time .Now (),
138
+ profitStats ,
139
+ position )
140
+ }
0 commit comments