diff --git a/examples/kucoin/main.go b/examples/kucoin/main.go index e963d4968..ad13e3315 100644 --- a/examples/kucoin/main.go +++ b/examples/kucoin/main.go @@ -19,6 +19,7 @@ func init() { rootCmd.AddCommand(accountsCmd) rootCmd.AddCommand(subAccountsCmd) + rootCmd.AddCommand(symbolsCmd) } var rootCmd = &cobra.Command{ diff --git a/examples/kucoin/symbols.go b/examples/kucoin/symbols.go new file mode 100644 index 000000000..c08b4dda2 --- /dev/null +++ b/examples/kucoin/symbols.go @@ -0,0 +1,24 @@ +package main + +import ( + "github.com/sirupsen/logrus" + "github.com/spf13/cobra" +) + +var symbolsCmd = &cobra.Command{ + Use: "symbols", + + // SilenceUsage is an option to silence usage when an error occurs. + SilenceUsage: true, + + RunE: func(cmd *cobra.Command, args []string) error { + symbols, err := client.MarketDataService.ListSymbols(args...) + if err != nil { + return err + } + + logrus.Infof("symbols: %+v", symbols) + return nil + }, +} + diff --git a/pkg/exchange/kucoin/kucoinapi/client.go b/pkg/exchange/kucoin/kucoinapi/client.go index 7bad17884..419d1e40d 100644 --- a/pkg/exchange/kucoin/kucoinapi/client.go +++ b/pkg/exchange/kucoin/kucoinapi/client.go @@ -68,9 +68,9 @@ type RestClient struct { KeyVersion string AccountService *AccountService + MarketDataService *MarketDataService // TradeService *TradeService // PublicDataService *PublicDataService - // MarketDataService *MarketDataService } func NewClient() *RestClient { @@ -88,9 +88,9 @@ func NewClient() *RestClient { } client.AccountService = &AccountService{ client: client } + client.MarketDataService = &MarketDataService{client: client} // client.TradeService = &TradeService{client: client} // client.PublicDataService = &PublicDataService{client: client} - // client.MarketDataService = &MarketDataService{client: client} return client } diff --git a/pkg/exchange/kucoin/kucoinapi/marketdata.go b/pkg/exchange/kucoin/kucoinapi/marketdata.go new file mode 100644 index 000000000..a03539a9f --- /dev/null +++ b/pkg/exchange/kucoin/kucoinapi/marketdata.go @@ -0,0 +1,61 @@ +package kucoinapi + +import ( + "net/url" + + "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/pkg/errors" +) + +type MarketDataService struct { + client *RestClient +} + +type Symbol struct { + Symbol string `json:"symbol"` + Name string `json:"name"` + BaseCurrency string `json:"baseCurrency"` + QuoteCurrency string `json:"quoteCurrency"` + FeeCurrency string `json:"feeCurrency"` + Market string `json:"market"` + BaseMinSize fixedpoint.Value `json:"baseMinSize"` + QuoteMinSize fixedpoint.Value `json:"quoteMinSize"` + BaseIncrement fixedpoint.Value `json:"baseIncrement"` + QuoteIncrement fixedpoint.Value `json:"quoteIncrement"` + PriceIncrement fixedpoint.Value `json:"priceIncrement"` + PriceLimitRate fixedpoint.Value `json:"priceLimitRate"` + IsMarginEnabled bool `json:"isMarginEnabled"` + EnableTrading bool `json:"enableTrading"` +} + +func (s *MarketDataService) ListSymbols(market ...string) ([]Symbol, error) { + var params = url.Values{} + + if len(market) == 1 { + params["market"] = []string{market[0]} + } else if len(market) > 1 { + return nil, errors.New("symbols api only supports one market parameter") + } + + req, err := s.client.newRequest("GET", "/api/v1/symbols", nil, nil) + if err != nil { + return nil, err + } + + response, err := s.client.sendRequest(req) + if err != nil { + return nil, err + } + + var apiResponse struct { + Code string `json:"code"` + Message string `json:"msg"` + Data []Symbol `json:"data"` + } + + if err := response.DecodeJSON(&apiResponse); err != nil { + return nil, err + } + + return apiResponse.Data, nil +}