fix kucoin context issue

This commit is contained in:
c9s 2021-12-30 15:58:58 +08:00
parent fb9ece2341
commit 844b3c2e8e
5 changed files with 14 additions and 10 deletions

View File

@ -5,11 +5,12 @@ import (
"os" "os"
"strings" "strings"
"github.com/c9s/bbgo/pkg/exchange/kucoin/kucoinapi"
"github.com/joho/godotenv" "github.com/joho/godotenv"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
"github.com/c9s/bbgo/pkg/exchange/kucoin/kucoinapi"
) )
func init() { func init() {
@ -26,7 +27,7 @@ var rootCmd = &cobra.Command{
SilenceUsage: true, SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
accounts, err := client.AccountService.ListAccounts() accounts, err := client.AccountService.ListAccounts(context.Background())
if err != nil { if err != nil {
return err return err
} }

View File

@ -1,6 +1,8 @@
package main package main
import ( import (
"context"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -26,7 +28,7 @@ var accountsCmd = &cobra.Command{
return nil return nil
} }
accounts, err := client.AccountService.ListAccounts() accounts, err := client.AccountService.ListAccounts(context.Background())
if err != nil { if err != nil {
return err return err
} }

View File

@ -14,6 +14,8 @@ import (
"github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/types"
) )
var marketDataLimiter = rate.NewLimiter(rate.Every(500*time.Millisecond), 1)
var ErrMissingSequence = errors.New("sequence is missing") var ErrMissingSequence = errors.New("sequence is missing")
// OKB is the platform currency of OKEx, pre-allocate static string here // 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) { 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 { if err != nil {
return nil, err 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) { 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 { if err != nil {
return nil, err return nil, err
} }
@ -150,7 +152,6 @@ func (e *Exchange) IsSupportedInterval(interval types.Interval) bool {
return ok 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) { func (e *Exchange) QueryKLines(ctx context.Context, symbol string, interval types.Interval, options types.KLineQueryOptions) ([]types.KLine, error) {
_ = marketDataLimiter.Wait(ctx) _ = marketDataLimiter.Wait(ctx)

View File

@ -50,8 +50,8 @@ type Account struct {
Holds fixedpoint.Value `json:"holds"` Holds fixedpoint.Value `json:"holds"`
} }
func (s *AccountService) ListAccounts() ([]Account, error) { func (s *AccountService) ListAccounts(ctx context.Context) ([]Account, error) {
req, err := s.client.NewAuthenticatedRequest(context.Background(), "GET", "/api/v1/accounts", nil, nil) req, err := s.client.NewAuthenticatedRequest(ctx, "GET", "/api/v1/accounts", nil, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -260,9 +260,9 @@ func (s *Stream) getEndpoint() (string, error) {
var bullet *kucoinapi.Bullet var bullet *kucoinapi.Bullet
var err error var err error
if s.PublicOnly { if s.PublicOnly {
bullet, err = s.client.BulletService.NewGetPublicBulletRequest().Do(nil) bullet, err = s.client.BulletService.NewGetPublicBulletRequest().Do(context.Background())
} else { } else {
bullet, err = s.client.BulletService.NewGetPrivateBulletRequest().Do(nil) bullet, err = s.client.BulletService.NewGetPrivateBulletRequest().Do(context.Background())
} }
if err != nil { if err != nil {