From 8c02b5e64ecbccfccacc432ab414452cbf8a67c9 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 13 Apr 2023 16:40:07 +0800 Subject: [PATCH] maxapi: pass context object to the requests --- pkg/exchange/max/exchange.go | 9 ++++----- pkg/exchange/max/maxapi/public.go | 12 ++++++------ pkg/exchange/max/maxapi/restapi.go | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/pkg/exchange/max/exchange.go b/pkg/exchange/max/exchange.go index 5e53089c9..98cf73936 100644 --- a/pkg/exchange/max/exchange.go +++ b/pkg/exchange/max/exchange.go @@ -96,8 +96,8 @@ func (e *Exchange) QueryTickers(ctx context.Context, symbol ...string) (map[stri tickers[toGlobalSymbol(symbol[0])] = *ticker } else { - - maxTickers, err := e.client.PublicService.Tickers() + req := e.client.NewGetTickersRequest() + maxTickers, err := req.Do(ctx) if err != nil { return nil, err } @@ -130,9 +130,8 @@ func (e *Exchange) QueryTickers(ctx context.Context, symbol ...string) (map[stri } func (e *Exchange) QueryMarkets(ctx context.Context) (types.MarketMap, error) { - log.Info("querying market info...") - - remoteMarkets, err := e.client.PublicService.Markets() + req := e.client.NewGetMarketsRequest() + remoteMarkets, err := req.Do(ctx) if err != nil { return nil, err } diff --git a/pkg/exchange/max/maxapi/public.go b/pkg/exchange/max/maxapi/public.go index 22d5e695d..e4d3aac82 100644 --- a/pkg/exchange/max/maxapi/public.go +++ b/pkg/exchange/max/maxapi/public.go @@ -41,9 +41,9 @@ type Ticker struct { VolumeInBTC fixedpoint.Value `json:"vol_in_btc"` } -func (s *PublicService) Timestamp() (int64, error) { +func (s *PublicService) Timestamp(ctx context.Context) (int64, error) { req := s.client.NewGetTimestampRequest() - ts, err := req.Do(context.Background()) + ts, err := req.Do(ctx) if err != nil || ts == nil { return 0, nil } @@ -51,14 +51,14 @@ func (s *PublicService) Timestamp() (int64, error) { return int64(*ts), nil } -func (s *PublicService) Markets() ([]Market, error) { +func (s *PublicService) Markets(ctx context.Context) ([]Market, error) { req := s.client.NewGetMarketsRequest() - return req.Do(context.Background()) + return req.Do(ctx) } -func (s *PublicService) Tickers() (TickerMap, error) { +func (s *PublicService) Tickers(ctx context.Context) (TickerMap, error) { req := s.client.NewGetTickersRequest() - return req.Do(context.Background()) + return req.Do(ctx) } func (s *PublicService) Ticker(market string) (*Ticker, error) { diff --git a/pkg/exchange/max/maxapi/restapi.go b/pkg/exchange/max/maxapi/restapi.go index 7dc554a9b..3b45af1df 100644 --- a/pkg/exchange/max/maxapi/restapi.go +++ b/pkg/exchange/max/maxapi/restapi.go @@ -161,7 +161,7 @@ func (c *RestClient) queryAndUpdateServerTimestamp(ctx context.Context) { default: op := func() error { - serverTs, err := c.PublicService.Timestamp() + serverTs, err := c.PublicService.Timestamp(ctx) if err != nil { return err }