mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
kucoin: implement all ticker and get ticker api
This commit is contained in:
parent
50b79cb742
commit
18653aca7e
|
@ -20,6 +20,7 @@ func init() {
|
|||
rootCmd.AddCommand(accountsCmd)
|
||||
rootCmd.AddCommand(subAccountsCmd)
|
||||
rootCmd.AddCommand(symbolsCmd)
|
||||
rootCmd.AddCommand(tickersCmd)
|
||||
}
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
|
|
35
examples/kucoin/tickers.go
Normal file
35
examples/kucoin/tickers.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var tickersCmd = &cobra.Command{
|
||||
Use: "tickers",
|
||||
|
||||
// SilenceUsage is an option to silence usage when an error occurs.
|
||||
SilenceUsage: true,
|
||||
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if len(args) == 0 {
|
||||
allTickers, err := client.MarketDataService.ListTickers()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Infof("allTickers: %+v", allTickers)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
ticker, err := client.MarketDataService.GetTicker(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Infof("ticker: %+v", ticker)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"net/url"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
@ -37,7 +38,7 @@ func (s *MarketDataService) ListSymbols(market ...string) ([]Symbol, error) {
|
|||
return nil, errors.New("symbols api only supports one market parameter")
|
||||
}
|
||||
|
||||
req, err := s.client.newRequest("GET", "/api/v1/symbols", nil, nil)
|
||||
req, err := s.client.newRequest("GET", "/api/v1/symbols", params, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -59,3 +60,131 @@ func (s *MarketDataService) ListSymbols(market ...string) ([]Symbol, error) {
|
|||
|
||||
return apiResponse.Data, nil
|
||||
}
|
||||
|
||||
/*
|
||||
//Get Ticker
|
||||
{
|
||||
"sequence": "1550467636704",
|
||||
"bestAsk": "0.03715004",
|
||||
"size": "0.17",
|
||||
"price": "0.03715005",
|
||||
"bestBidSize": "3.803",
|
||||
"bestBid": "0.03710768",
|
||||
"bestAskSize": "1.788",
|
||||
"time": 1550653727731
|
||||
}
|
||||
*/
|
||||
type Ticker struct {
|
||||
Sequence string `json:"sequence"`
|
||||
Size fixedpoint.Value `json:"size"`
|
||||
Price fixedpoint.Value `json:"price"`
|
||||
BestAsk fixedpoint.Value `json:"bestAsk"`
|
||||
BestBid fixedpoint.Value `json:"bestBid"`
|
||||
BestBidSize fixedpoint.Value `json:"bestBidSize"`
|
||||
Time types.MillisecondTimestamp `json:"time"`
|
||||
}
|
||||
|
||||
func (s *MarketDataService) GetTicker(symbol string) (*Ticker, error) {
|
||||
var params = url.Values{}
|
||||
params["symbol"] = []string{symbol}
|
||||
|
||||
req, err := s.client.newRequest("GET", "/api/v1/market/orderbook/level1", params, 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 *Ticker `json:"data"`
|
||||
}
|
||||
|
||||
if err := response.DecodeJSON(&apiResponse); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return apiResponse.Data, nil
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
"time":1602832092060,
|
||||
"ticker":[
|
||||
{
|
||||
"symbol": "BTC-USDT", // symbol
|
||||
"symbolName":"BTC-USDT", // Name of trading pairs, it would change after renaming
|
||||
"buy": "11328.9", // bestAsk
|
||||
"sell": "11329", // bestBid
|
||||
"changeRate": "-0.0055", // 24h change rate
|
||||
"changePrice": "-63.6", // 24h change price
|
||||
"high": "11610", // 24h highest price
|
||||
"low": "11200", // 24h lowest price
|
||||
"vol": "2282.70993217", // 24h volume,the aggregated trading volume in BTC
|
||||
"volValue": "25984946.157790431", // 24h total, the trading volume in quote currency of last 24 hours
|
||||
"last": "11328.9", // last price
|
||||
"averagePrice": "11360.66065903", // 24h average transaction price yesterday
|
||||
"takerFeeRate": "0.001", // Basic Taker Fee
|
||||
"makerFeeRate": "0.001", // Basic Maker Fee
|
||||
"takerCoefficient": "1", // Taker Fee Coefficient
|
||||
"makerCoefficient": "1" // Maker Fee Coefficient
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
type Ticker24H struct {
|
||||
Symbol string `json:"symbol"`
|
||||
Name string `json:"symbolName"`
|
||||
Buy fixedpoint.Value `json:"buy"`
|
||||
Sell fixedpoint.Value `json:"sell"`
|
||||
ChangeRate fixedpoint.Value `json:"changeRate"`
|
||||
ChangePrice fixedpoint.Value `json:"changePrice"`
|
||||
High fixedpoint.Value `json:"high"`
|
||||
Low fixedpoint.Value `json:"low"`
|
||||
Last fixedpoint.Value `json:"last"`
|
||||
AveragePrice fixedpoint.Value `json:"averagePrice"`
|
||||
Volume fixedpoint.Value `json:"vol"` // base volume
|
||||
VolumeValue fixedpoint.Value `json:"volValue"` // quote volume
|
||||
|
||||
TakerFeeRate fixedpoint.Value `json:"takerFeeRate"`
|
||||
MakerFeeRate fixedpoint.Value `json:"makerFeeRate"`
|
||||
|
||||
TakerCoefficient fixedpoint.Value `json:"takerCoefficient"`
|
||||
MakerCoefficient fixedpoint.Value `json:"makerCoefficient"`
|
||||
}
|
||||
|
||||
type AllTickers struct {
|
||||
Time types.MillisecondTimestamp `json:"time"`
|
||||
Ticker []Ticker24H `json:"ticker"`
|
||||
}
|
||||
|
||||
|
||||
func (s *MarketDataService) ListTickers() (*AllTickers, error) {
|
||||
req, err := s.client.newRequest("GET", "/api/v1/market/allTickers", 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 *AllTickers `json:"data"`
|
||||
}
|
||||
|
||||
if err := response.DecodeJSON(&apiResponse); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return apiResponse.Data, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user