Merge pull request #1143 from c9s/refactor/max-client

FIX: maxapi: pass context object to the requests
This commit is contained in:
Yo-An Lin 2023-04-13 16:57:19 +08:00 committed by GitHub
commit 7da5c8361e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 12 deletions

View File

@ -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
}

View File

@ -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) {

View File

@ -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
}