fix: do not load all trades into memory

This commit is contained in:
c9s 2022-06-02 20:02:32 +08:00
parent d7c8b0b127
commit d27fee57ad
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 4 additions and 3 deletions

View File

@ -448,6 +448,8 @@ func (session *ExchangeSession) initSymbol(ctx context.Context, environ *Environ
trades, err = environ.TradeService.Query(service.QueryTradesOptions{ trades, err = environ.TradeService.Query(service.QueryTradesOptions{
Exchange: session.Exchange.Name(), Exchange: session.Exchange.Name(),
Symbol: symbol, Symbol: symbol,
Ordering: "DESC",
Limit: 100,
}) })
} }
@ -455,6 +457,7 @@ func (session *ExchangeSession) initSymbol(ctx context.Context, environ *Environ
return err return err
} }
trades = types.SortTradesAscending(trades)
log.Infof("symbol %s: %d trades loaded", symbol, len(trades)) log.Infof("symbol %s: %d trades loaded", symbol, len(trades))
} }

View File

@ -295,13 +295,11 @@ func (s *TradeService) QueryForTradingFeeCurrency(ex types.ExchangeName, symbol
func (s *TradeService) Query(options QueryTradesOptions) ([]types.Trade, error) { func (s *TradeService) Query(options QueryTradesOptions) ([]types.Trade, error) {
sql := queryTradesSQL(options) sql := queryTradesSQL(options)
log.Debug(sql)
args := map[string]interface{}{ args := map[string]interface{}{
"exchange": options.Exchange, "exchange": options.Exchange,
"symbol": options.Symbol, "symbol": options.Symbol,
} }
rows, err := s.DB.NamedQuery(sql, args) rows, err := s.DB.NamedQuery(sql, args)
if err != nil { if err != nil {
return nil, err return nil, err