diff --git a/examples/kucoin-accounts/main.go b/examples/kucoin-accounts/main.go index 3afee7dd6..5cd29c267 100644 --- a/examples/kucoin-accounts/main.go +++ b/examples/kucoin-accounts/main.go @@ -5,11 +5,12 @@ import ( "os" "strings" - "github.com/c9s/bbgo/pkg/exchange/kucoin/kucoinapi" "github.com/joho/godotenv" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" + + "github.com/c9s/bbgo/pkg/exchange/kucoin/kucoinapi" ) func init() { @@ -26,7 +27,7 @@ var rootCmd = &cobra.Command{ SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { - accounts, err := client.AccountService.ListAccounts() + accounts, err := client.AccountService.ListAccounts(context.Background()) if err != nil { return err } diff --git a/examples/kucoin/accounts.go b/examples/kucoin/accounts.go index bbd8d39cb..5e8ec6d4e 100644 --- a/examples/kucoin/accounts.go +++ b/examples/kucoin/accounts.go @@ -1,6 +1,8 @@ package main import ( + "context" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -26,7 +28,7 @@ var accountsCmd = &cobra.Command{ return nil } - accounts, err := client.AccountService.ListAccounts() + accounts, err := client.AccountService.ListAccounts(context.Background()) if err != nil { return err } diff --git a/pkg/exchange/kucoin/exchange.go b/pkg/exchange/kucoin/exchange.go index d8eb9340e..7a413f685 100644 --- a/pkg/exchange/kucoin/exchange.go +++ b/pkg/exchange/kucoin/exchange.go @@ -14,6 +14,8 @@ import ( "github.com/c9s/bbgo/pkg/types" ) +var marketDataLimiter = rate.NewLimiter(rate.Every(500*time.Millisecond), 1) + var ErrMissingSequence = errors.New("sequence is missing") // OKB is the platform currency of OKEx, pre-allocate static string here @@ -53,7 +55,7 @@ func (e *Exchange) PlatformFeeCurrency() string { } func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error) { - accounts, err := e.client.AccountService.ListAccounts() + accounts, err := e.client.AccountService.ListAccounts(ctx) if err != nil { return nil, err } @@ -66,7 +68,7 @@ func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error) { } func (e *Exchange) QueryAccountBalances(ctx context.Context) (types.BalanceMap, error) { - accounts, err := e.client.AccountService.ListAccounts() + accounts, err := e.client.AccountService.ListAccounts(ctx) if err != nil { return nil, err } @@ -150,7 +152,6 @@ func (e *Exchange) IsSupportedInterval(interval types.Interval) bool { return ok } -var marketDataLimiter = rate.NewLimiter(rate.Every(200*time.Millisecond), 1) func (e *Exchange) QueryKLines(ctx context.Context, symbol string, interval types.Interval, options types.KLineQueryOptions) ([]types.KLine, error) { _ = marketDataLimiter.Wait(ctx) diff --git a/pkg/exchange/kucoin/kucoinapi/account.go b/pkg/exchange/kucoin/kucoinapi/account.go index 1cd084fd8..a6dbb3f9a 100644 --- a/pkg/exchange/kucoin/kucoinapi/account.go +++ b/pkg/exchange/kucoin/kucoinapi/account.go @@ -50,8 +50,8 @@ type Account struct { Holds fixedpoint.Value `json:"holds"` } -func (s *AccountService) ListAccounts() ([]Account, error) { - req, err := s.client.NewAuthenticatedRequest(context.Background(), "GET", "/api/v1/accounts", nil, nil) +func (s *AccountService) ListAccounts(ctx context.Context) ([]Account, error) { + req, err := s.client.NewAuthenticatedRequest(ctx, "GET", "/api/v1/accounts", nil, nil) if err != nil { return nil, err } diff --git a/pkg/exchange/kucoin/stream.go b/pkg/exchange/kucoin/stream.go index 62bf4aa1c..5339d0973 100644 --- a/pkg/exchange/kucoin/stream.go +++ b/pkg/exchange/kucoin/stream.go @@ -260,9 +260,9 @@ func (s *Stream) getEndpoint() (string, error) { var bullet *kucoinapi.Bullet var err error if s.PublicOnly { - bullet, err = s.client.BulletService.NewGetPublicBulletRequest().Do(nil) + bullet, err = s.client.BulletService.NewGetPublicBulletRequest().Do(context.Background()) } else { - bullet, err = s.client.BulletService.NewGetPrivateBulletRequest().Do(nil) + bullet, err = s.client.BulletService.NewGetPrivateBulletRequest().Do(context.Background()) } if err != nil {