mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
Merge pull request #1141 from c9s/refactor/max-client
REFACTOR: maxapi: refactor and add max v2 markets api test
This commit is contained in:
commit
a5ecfd15cc
|
@ -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}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user