bbgo: remove local trade snapshot from db

This commit is contained in:
c9s 2023-11-17 17:05:44 +08:00
parent e5033c093a
commit c248b2a323
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"strings"
"sync" "sync"
"time" "time"
@ -20,7 +19,6 @@ import (
exchange2 "github.com/c9s/bbgo/pkg/exchange" exchange2 "github.com/c9s/bbgo/pkg/exchange"
"github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/service"
"github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/util" "github.com/c9s/bbgo/pkg/util"
) )
@ -398,30 +396,7 @@ func (session *ExchangeSession) initSymbol(ctx context.Context, environ *Environ
return fmt.Errorf("market %s is not defined", symbol) return fmt.Errorf("market %s is not defined", symbol)
} }
var err error session.Trades[symbol] = &types.TradeSlice{Trades: nil}
var trades []types.Trade
if environ.SyncService != nil && environ.BacktestService == nil {
tradingFeeCurrency := session.Exchange.PlatformFeeCurrency()
if strings.HasPrefix(symbol, tradingFeeCurrency) {
trades, err = environ.TradeService.QueryForTradingFeeCurrency(session.Exchange.Name(), symbol, tradingFeeCurrency)
} else {
trades, err = environ.TradeService.Query(service.QueryTradesOptions{
Exchange: session.Exchange.Name(),
Symbol: symbol,
Ordering: "DESC",
Limit: 100,
})
}
if err != nil {
return err
}
trades = types.SortTradesAscending(trades)
log.Infof("symbol %s: %d trades loaded", symbol, len(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 {
return return
@ -430,12 +405,12 @@ func (session *ExchangeSession) initSymbol(ctx context.Context, environ *Environ
session.Trades[symbol].Append(trade) session.Trades[symbol].Append(trade)
}) })
// session wide position
position := &types.Position{ position := &types.Position{
Symbol: symbol, Symbol: symbol,
BaseCurrency: market.BaseCurrency, BaseCurrency: market.BaseCurrency,
QuoteCurrency: market.QuoteCurrency, QuoteCurrency: market.QuoteCurrency,
} }
position.AddTrades(trades)
position.BindStream(session.UserDataStream) position.BindStream(session.UserDataStream)
session.positions[symbol] = position session.positions[symbol] = position