From f284c35b819718f1c100ebf5fa283edbea0d40d2 Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 24 Jan 2022 23:54:58 +0800 Subject: [PATCH] max: ensure orders are sorted ascendingly --- pkg/exchange/max/exchange.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/exchange/max/exchange.go b/pkg/exchange/max/exchange.go index fcce2d155..42c7c642b 100644 --- a/pkg/exchange/max/exchange.go +++ b/pkg/exchange/max/exchange.go @@ -202,6 +202,11 @@ func (e *Exchange) QueryClosedOrders(ctx context.Context, symbol string, since, return orders, err } + // ensure everything is ascending ordered + sort.Slice(maxOrders, func(i, j int) bool { + return maxOrders[i].CreatedAtMs.Time().Before(maxOrders[j].CreatedAtMs.Time()) + }) + log.Infof("%d orders", len(maxOrders)) for _, maxOrder := range maxOrders { if maxOrder.CreatedAtMs.Time().Before(since) {