maxapi: add kline api test

This commit is contained in:
c9s 2023-04-12 22:43:32 +08:00
parent 3e41c1fb15
commit cbbe6e286d
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
3 changed files with 13 additions and 3 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

@ -153,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

@ -35,6 +35,16 @@ func TestPublicService(t *testing.T) {
}
})
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)