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

REFACTOR: maxapi: refactor and add max v2 markets api test
This commit is contained in:
Yo-An Lin 2023-04-13 16:33:47 +08:00 committed by GitHub
commit a5ecfd15cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 9 deletions

View File

@ -22,6 +22,6 @@ type GetKLinesRequest struct {
timestamp time.Time `param:"timestamp,seconds"`
}
func (s *PublicService) NewGetKLinesRequest() *GetKLinesRequest {
return &GetKLinesRequest{client: s.client}
func (c *RestClient) NewGetKLinesRequest() *GetKLinesRequest {
return &GetKLinesRequest{client: c}
}

View File

@ -53,12 +53,7 @@ func (s *PublicService) Timestamp() (int64, error) {
func (s *PublicService) Markets() ([]Market, error) {
req := s.client.NewGetMarketsRequest()
markets, err := req.Do(context.Background())
if err != nil {
return nil, err
}
return markets, nil
return req.Do(context.Background())
}
func (s *PublicService) Tickers() (TickerMap, error) {
@ -158,7 +153,7 @@ func (s *PublicService) KLines(symbol string, resolution string, start time.Time
return nil, err
}
req := s.NewGetKLinesRequest()
req := s.client.NewGetKLinesRequest()
req.Market(symbol).Period(int(interval)).Timestamp(start).Limit(limit)
data, err := req.Do(context.Background())
if err != nil {

View File

@ -25,6 +25,31 @@ func TestPublicService(t *testing.T) {
assert.NotZero(t, serverTimestamp)
})
t.Run("v2/markets", func(t *testing.T) {
req := client.NewGetMarketsRequest()
markets, err := req.Do(context.Background())
assert.NoError(t, err)
if assert.NotEmpty(t, markets) {
assert.NotZero(t, markets[0].MinBaseAmount)
assert.NotZero(t, markets[0].MinQuoteAmount)
assert.NotEmpty(t, markets[0].Name)
assert.NotEmpty(t, markets[0].ID)
assert.NotEmpty(t, markets[0].BaseUnit)
assert.NotEmpty(t, markets[0].QuoteUnit)
t.Logf("%+v", markets[0])
}
})
t.Run("v2/k", func(t *testing.T) {
req := client.NewGetKLinesRequest()
data, err := req.Market("btcusdt").Period(int(60)).Limit(100).Do(ctx)
assert.NoError(t, err)
if assert.NotEmpty(t, data) {
assert.NotEmpty(t, data[0])
assert.Len(t, data[0], 6)
}
})
t.Run("v2/tickers", func(t *testing.T) {
req := client.NewGetTickersRequest()
tickers, err := req.Do(ctx)