From d27fee57addf5a1927978e127cb8bdd7be9cce39 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 2 Jun 2022 20:02:32 +0800 Subject: [PATCH] fix: do not load all trades into memory --- pkg/bbgo/session.go | 3 +++ pkg/service/trade.go | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/bbgo/session.go b/pkg/bbgo/session.go index 7daf377da..48631002e 100644 --- a/pkg/bbgo/session.go +++ b/pkg/bbgo/session.go @@ -448,6 +448,8 @@ func (session *ExchangeSession) initSymbol(ctx context.Context, environ *Environ trades, err = environ.TradeService.Query(service.QueryTradesOptions{ Exchange: session.Exchange.Name(), Symbol: symbol, + Ordering: "DESC", + Limit: 100, }) } @@ -455,6 +457,7 @@ func (session *ExchangeSession) initSymbol(ctx context.Context, environ *Environ return err } + trades = types.SortTradesAscending(trades) log.Infof("symbol %s: %d trades loaded", symbol, len(trades)) } diff --git a/pkg/service/trade.go b/pkg/service/trade.go index 6449c7d75..eabd1ccdf 100644 --- a/pkg/service/trade.go +++ b/pkg/service/trade.go @@ -295,13 +295,11 @@ func (s *TradeService) QueryForTradingFeeCurrency(ex types.ExchangeName, symbol func (s *TradeService) Query(options QueryTradesOptions) ([]types.Trade, error) { sql := queryTradesSQL(options) - - log.Debug(sql) - args := map[string]interface{}{ "exchange": options.Exchange, "symbol": options.Symbol, } + rows, err := s.DB.NamedQuery(sql, args) if err != nil { return nil, err