add TradeCollector.Process() log message

This commit is contained in:
c9s 2023-07-12 17:16:46 +08:00
parent 885c58f77e
commit b9616a0805
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
4 changed files with 9 additions and 4 deletions

View File

@ -203,9 +203,10 @@ func (e *GeneralOrderExecutor) SubmitOrders(ctx context.Context, submitOrders ..
orderCreateCallback := func(createdOrder types.Order) { orderCreateCallback := func(createdOrder types.Order) {
e.orderStore.Add(createdOrder) e.orderStore.Add(createdOrder)
e.activeMakerOrders.Add(createdOrder) e.activeMakerOrders.Add(createdOrder)
e.tradeCollector.Process()
} }
defer e.tradeCollector.Process()
if e.maxRetries == 0 { if e.maxRetries == 0 {
createdOrders, _, err := BatchPlaceOrder(ctx, e.session.Exchange, orderCreateCallback, formattedOrders...) createdOrders, _, err := BatchPlaceOrder(ctx, e.session.Exchange, orderCreateCallback, formattedOrders...)
return createdOrders, err return createdOrders, err

View File

@ -385,9 +385,11 @@ func (session *ExchangeSession) initSymbol(ctx context.Context, environ *Environ
session.Trades[symbol] = &types.TradeSlice{Trades: trades} session.Trades[symbol] = &types.TradeSlice{Trades: trades}
session.UserDataStream.OnTradeUpdate(func(trade types.Trade) { session.UserDataStream.OnTradeUpdate(func(trade types.Trade) {
if trade.Symbol == symbol { if trade.Symbol != symbol {
session.Trades[symbol].Append(trade) return
} }
session.Trades[symbol].Append(trade)
}) })
position := &types.Position{ position := &types.Position{

View File

@ -529,7 +529,8 @@ var BacktestCmd = &cobra.Command{
profitFactor := tradeState.ProfitFactor profitFactor := tradeState.ProfitFactor
winningRatio := tradeState.WinningRatio winningRatio := tradeState.WinningRatio
intervalProfits := tradeState.IntervalProfits[types.Interval1d] intervalProfits := tradeState.IntervalProfits[types.Interval1d]
symbolReport, err := createSymbolReport(userConfig, session, symbol, trades.Trades, intervalProfits, profitFactor, winningRatio)
symbolReport, err := createSymbolReport(userConfig, session, symbol, trades.Copy(), intervalProfits, profitFactor, winningRatio)
if err != nil { if err != nil {
return err return err
} }

View File

@ -117,6 +117,7 @@ func (c *TradeCollector) setDone(key types.TradeKey) {
// if we have the order in the order store, then the trade will be considered for the position. // if we have the order in the order store, then the trade will be considered for the position.
// profit will also be calculated. // profit will also be calculated.
func (c *TradeCollector) Process() bool { func (c *TradeCollector) Process() bool {
logrus.Debugf("TradeCollector.Process()")
positionChanged := false positionChanged := false
c.tradeStore.Filter(func(trade types.Trade) bool { c.tradeStore.Filter(func(trade types.Trade) bool {