mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
implement ListSymbols api
This commit is contained in:
parent
be7e9f551a
commit
50b79cb742
|
@ -19,6 +19,7 @@ func init() {
|
||||||
|
|
||||||
rootCmd.AddCommand(accountsCmd)
|
rootCmd.AddCommand(accountsCmd)
|
||||||
rootCmd.AddCommand(subAccountsCmd)
|
rootCmd.AddCommand(subAccountsCmd)
|
||||||
|
rootCmd.AddCommand(symbolsCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
|
|
24
examples/kucoin/symbols.go
Normal file
24
examples/kucoin/symbols.go
Normal file
|
@ -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
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
|
@ -68,9 +68,9 @@ type RestClient struct {
|
||||||
KeyVersion string
|
KeyVersion string
|
||||||
|
|
||||||
AccountService *AccountService
|
AccountService *AccountService
|
||||||
|
MarketDataService *MarketDataService
|
||||||
// TradeService *TradeService
|
// TradeService *TradeService
|
||||||
// PublicDataService *PublicDataService
|
// PublicDataService *PublicDataService
|
||||||
// MarketDataService *MarketDataService
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient() *RestClient {
|
func NewClient() *RestClient {
|
||||||
|
@ -88,9 +88,9 @@ func NewClient() *RestClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
client.AccountService = &AccountService{ client: client }
|
client.AccountService = &AccountService{ client: client }
|
||||||
|
client.MarketDataService = &MarketDataService{client: client}
|
||||||
// client.TradeService = &TradeService{client: client}
|
// client.TradeService = &TradeService{client: client}
|
||||||
// client.PublicDataService = &PublicDataService{client: client}
|
// client.PublicDataService = &PublicDataService{client: client}
|
||||||
// client.MarketDataService = &MarketDataService{client: client}
|
|
||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
61
pkg/exchange/kucoin/kucoinapi/marketdata.go
Normal file
61
pkg/exchange/kucoin/kucoinapi/marketdata.go
Normal file
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user