kucoin

package
v0.0.0-...-41d977e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChannelSpotOrderBook   = "/spotMarket/level2Depth5:"
	ChannelSpotTicker      = "/market/snapshot:"
	ChannelSpotBestTicker  = "/market/ticker:"
	ChannelSpotPublicTrade = "/market/match:"
	ChannelSpotUserOrder   = "/spotMarket/tradeOrdersV2" // 现货订单变动
	ChannelSpotUserBalance = "/account/balance"          // 现货余额变动
)

spot channels

View Source
const (
	Subscribe   = "subscribe"
	UnSubscribe = "unsubscribe"
)

Variables

This section is empty.

Functions

func GenSignBody

func GenSignBody(method, requestURI, body string) string

Types

type AccountModel

type AccountModel struct {
	Id        string `json:"id"`
	Currency  string `json:"currency"`
	Type      string `json:"type"`
	Balance   string `json:"balance"`
	Available string `json:"available"`
	Holds     string `json:"holds"`
}

An AccountModel represents an account.

type AccountsModel

type AccountsModel []*AccountModel

An AccountsModel is the set of *AccountModel.

type ApiResponse

type ApiResponse struct {
	Code    string          `json:"code"`
	RawData json.RawMessage `json:"data"` // delay parsing
	Message string          `json:"msg"`
}

返回的数据结构

type CancelOrderResultModel

type CancelOrderResultModel struct {
	CancelledOrderIds []string `json:"cancelledOrderIds"`
}

A CancelOrderResultModel represents the result of CancelOrder().

type CreateOrderModel

type CreateOrderModel struct {
	// BASE PARAMETERS
	ClientOid string `json:"clientOid"`
	Side      string `json:"side"`
	Symbol    string `json:"symbol,omitempty"`
	Type      string `json:"type,omitempty"`
	Remark    string `json:"remark,omitempty"`
	Stop      string `json:"stop,omitempty"`
	StopPrice string `json:"stopPrice,omitempty"`
	STP       string `json:"stp,omitempty"`
	TradeType string `json:"tradeType,omitempty"`

	// LIMIT ORDER PARAMETERS
	Price       string `json:"price,omitempty"`
	Size        string `json:"size,omitempty"`
	TimeInForce string `json:"timeInForce,omitempty"`
	CancelAfter int64  `json:"cancelAfter,omitempty"`
	PostOnly    bool   `json:"postOnly,omitempty"`
	Hidden      bool   `json:"hidden,omitempty"`
	IceBerg     bool   `json:"iceberg,omitempty"`
	VisibleSize string `json:"visibleSize,omitempty"`

	// MARKET ORDER PARAMETERS
	// Size  string `json:"size"`
	Funds string `json:"funds,omitempty"`

	// MARGIN ORDER PARAMETERS
	MarginMode string `json:"marginMode,omitempty"`
	AutoBorrow bool   `json:"autoBorrow,omitempty"`
}

A CreateOrderModel is the input parameter of CreateOrder().

type KLineModel

type KLineModel []string

KLineModel represents the k lines for a symbol. Rates are returned in grouped buckets based on requested type.

type KLinesModel

type KLinesModel []*KLineModel

A KLinesModel is the set of *KLineModel.

type KcSigner

type KcSigner struct {
	Sha256Signer
	// contains filtered or unexported fields
}

KcSigner is the implement of Signer for KuCoin.

func NewKcSignerV2

func NewKcSignerV2(key, secret, passPhrase string) *KcSigner

NewKcSignerV2 creates a instance of KcSigner.

func (*KcSigner) Headers

func (ks *KcSigner) Headers(plain string) map[string]string

Headers returns a map of signature header.

func (*KcSigner) Sign

func (ks *KcSigner) Sign(plain []byte) []byte

Sign makes a signature by sha256 with `apiKey` `apiSecret` `apiPassPhrase`.

type KuCoin

type KuCoin struct {
	Accesskey,
	Secretkey,
	Passphrase string
	KcSigner *KcSigner
	// contains filtered or unexported fields
}

func New

func New(client *http.Client, accesskey, secretkey, passphrase string) *KuCoin

func (*KuCoin) CancelOrder

func (k *KuCoin) CancelOrder(orderId string, currencyPair CurrencyPair) (bool, error)

func (*KuCoin) GetAccount

func (k *KuCoin) GetAccount() (*Account, error)

func (*KuCoin) GetBestTicker

func (k *KuCoin) GetBestTicker(currencyPair CurrencyPair) (*BestTicker, error)

func (*KuCoin) GetCurrencyPairs

func (k *KuCoin) GetCurrencyPairs() ([]CurrencyPair, error)

获取所有交易对

func (*KuCoin) GetDepth

func (k *KuCoin) GetDepth(size int, currencyPair CurrencyPair) (*Depth, error)

func (*KuCoin) GetExchangeName

func (k *KuCoin) GetExchangeName() string

func (*KuCoin) GetKlineRecords

func (k *KuCoin) GetKlineRecords(currencyPair CurrencyPair, period KlinePeriod, size int, optional ...OptionalParameter) ([]Kline, error)

func (*KuCoin) GetOneOrder

func (k *KuCoin) GetOneOrder(orderId string, currencyPair CurrencyPair) (*Order, error)

func (*KuCoin) GetOrderHistorys

func (k *KuCoin) GetOrderHistorys(currencyPair CurrencyPair, optional ...OptionalParameter) ([]Order, error)

func (*KuCoin) GetPrivateToken

func (kc *KuCoin) GetPrivateToken() (*WebSocketTokenModel, error)

func (*KuCoin) GetPublicToken

func (kc *KuCoin) GetPublicToken() (*WebSocketTokenModel, error)

func (*KuCoin) GetSubAccount

func (k *KuCoin) GetSubAccount(coin Currency) (*SubAccount, error)

func (*KuCoin) GetSubAccounts

func (k *KuCoin) GetSubAccounts() ([]SubAccount, error)

func (*KuCoin) GetTicker

func (k *KuCoin) GetTicker(currencyPair CurrencyPair) (*Ticker, error)

func (*KuCoin) GetTradeFee

func (k *KuCoin) GetTradeFee(currencyPair CurrencyPair) (*TradeFee, error)

私有权限

func (*KuCoin) GetTrades

func (k *KuCoin) GetTrades(currencyPair CurrencyPair, since int64) ([]Trade, error)

非个人,整个交易所的交易记录,最近100条

func (*KuCoin) GetUnfinishOrders

func (k *KuCoin) GetUnfinishOrders(currencyPair CurrencyPair) ([]Order, error)

查询指定交易对所有挂单

func (*KuCoin) LimitBuy

func (k *KuCoin) LimitBuy(amount, price string, currencyPair CurrencyPair, optional ...LimitOrderOptionalParameter) (*Order, error)

限价买单

func (*KuCoin) LimitSell

func (k *KuCoin) LimitSell(amount, price string, currencyPair CurrencyPair, optional ...LimitOrderOptionalParameter) (*Order, error)

func (*KuCoin) MarketBuy

func (k *KuCoin) MarketBuy(amount, price string, currencyPair CurrencyPair) (*Order, error)

func (*KuCoin) MarketSell

func (k *KuCoin) MarketSell(amount, price string, currencyPair CurrencyPair) (*Order, error)

func (*KuCoin) PlaceOrder

func (k *KuCoin) PlaceOrder(amount, price string, currencyPair CurrencyPair, orderType, orderSide string) (*Order, error)

限价买单

type OrderModel

type OrderModel struct {
	Id            string `json:"id"`
	Symbol        string `json:"symbol"`
	OpType        string `json:"opType"`
	Type          string `json:"type"`
	Side          string `json:"side"`
	Price         string `json:"price"`
	Size          string `json:"size"`
	Funds         string `json:"funds"`
	DealFunds     string `json:"dealFunds"`
	DealSize      string `json:"dealSize"`
	Fee           string `json:"fee"`
	FeeCurrency   string `json:"feeCurrency"`
	Stp           string `json:"stp"`
	Stop          string `json:"stop"`
	StopTriggered bool   `json:"stopTriggered"`
	StopPrice     string `json:"stopPrice"`
	TimeInForce   string `json:"timeInForce"`
	PostOnly      bool   `json:"postOnly"`
	Hidden        bool   `json:"hidden"`
	IceBerg       bool   `json:"iceberg"`
	VisibleSize   string `json:"visibleSize"`
	CancelAfter   int64  `json:"cancelAfter"`
	Channel       string `json:"channel"`
	ClientOid     string `json:"clientOid"`
	Remark        string `json:"remark"`
	Tags          string `json:"tags"`
	IsActive      bool   `json:"isActive"`
	CancelExist   bool   `json:"cancelExist"`
	CreatedAt     int64  `json:"createdAt"`
	TradeType     string `json:"tradeType"`
}

An OrderModel represents an order.

type OrderPageModel

type OrderPageModel struct {
	CurrentPage int         `json:"currentPage"`
	PageSize    int         `json:"pageSize"`
	TotalNum    int         `json:"totalNum"`
	TotalPage   int         `json:"totalPage"`
	Items       OrdersModel `json:"items"`
}

type OrdersModel

type OrdersModel []*OrderModel

type PartOrderBookModel

type PartOrderBookModel struct {
	Sequence string     `json:"sequence"`
	Time     int64      `json:"time"`
	Bids     [][]string `json:"bids"`
	Asks     [][]string `json:"asks"`
}

A PartOrderBookModel represents a list of open orders for a symbol, a part of Order Book within 100 depth for each side(ask or bid).

type ServiceError

type ServiceError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type Sha256Signer

type Sha256Signer struct {
	// contains filtered or unexported fields
}

Sha256Signer is the sha256 Signer.

func (*Sha256Signer) Sign

func (ss *Sha256Signer) Sign(plain []byte) []byte

Sign makes a signature by sha256.

type Signer

type Signer interface {
	Sign(plain []byte) []byte
}

Signer interface contains Sign() method.

type SpotWs

type SpotWs struct {
	// contains filtered or unexported fields
}

func NewSpotWs

func NewSpotWs(kc *KuCoin, accesskey, secretkey, passphrase, proxy string) *SpotWs

func (*SpotWs) BestTickerCallback

func (s *SpotWs) BestTickerCallback(f func(ticker *gocoinex.BestTicker, exchange string))

func (*SpotWs) DepthCallback

func (s *SpotWs) DepthCallback(f func(depth *gocoinex.Depth, exchange string))

func (*SpotWs) HeartbeatData

func (s *SpotWs) HeartbeatData() []byte

func (*SpotWs) SubscribeBestTicker

func (s *SpotWs) SubscribeBestTicker(pair gocoinex.CurrencyPair) error

func (*SpotWs) SubscribeDepth

func (s *SpotWs) SubscribeDepth(pair gocoinex.CurrencyPair) error

func (*SpotWs) SubscribeTicker

func (s *SpotWs) SubscribeTicker(pair gocoinex.CurrencyPair) error

func (*SpotWs) SubscribeTrade

func (s *SpotWs) SubscribeTrade(pair gocoinex.CurrencyPair) error

func (*SpotWs) SubscribeUserBalance

func (s *SpotWs) SubscribeUserBalance() error

func (*SpotWs) SubscribeUserOrder

func (s *SpotWs) SubscribeUserOrder() error

func (*SpotWs) TickerCallback

func (s *SpotWs) TickerCallback(f func(ticker *gocoinex.Ticker, exchange string))

func (*SpotWs) TradeCallback

func (s *SpotWs) TradeCallback(f func(trade *gocoinex.Trade, exchange string))

func (*SpotWs) UnSubscribeBestTicker

func (s *SpotWs) UnSubscribeBestTicker(pair gocoinex.CurrencyPair) error

func (*SpotWs) UnSubscribeDepth

func (s *SpotWs) UnSubscribeDepth(pair gocoinex.CurrencyPair) error

func (*SpotWs) UnSubscribeTicker

func (s *SpotWs) UnSubscribeTicker(pair gocoinex.CurrencyPair) error

func (*SpotWs) UnSubscribeTrade

func (s *SpotWs) UnSubscribeTrade(pair gocoinex.CurrencyPair) error

func (*SpotWs) UnSubscribeUserBalance

func (s *SpotWs) UnSubscribeUserBalance() error

func (*SpotWs) UnSubscribeUserOrder

func (s *SpotWs) UnSubscribeUserOrder() error

func (*SpotWs) UserBalanceCallback

func (s *SpotWs) UserBalanceCallback(f func(trade *gocoinex.SubAccount, exchange string))

func (*SpotWs) UserOrderCallback

func (s *SpotWs) UserOrderCallback(f func(ticker *gocoinex.Order, exchange string))

type SymbolModel

type SymbolModel struct {
	Symbol          string `json:"symbol"`
	Name            string `json:"name"`
	BaseCurrency    string `json:"baseCurrency"`
	QuoteCurrency   string `json:"quoteCurrency"`
	Market          string `json:"market"`
	BaseMinSize     string `json:"baseMinSize"`
	QuoteMinSize    string `json:"quoteMinSize"`
	BaseMaxSize     string `json:"baseMaxSize"`
	QuoteMaxSize    string `json:"quoteMaxSize"`
	BaseIncrement   string `json:"baseIncrement"`
	QuoteIncrement  string `json:"quoteIncrement"`
	PriceIncrement  string `json:"priceIncrement"`
	FeeCurrency     string `json:"feeCurrency"`
	EnableTrading   bool   `json:"enableTrading"`
	IsMarginEnabled bool   `json:"isMarginEnabled"`
	PriceLimitRate  string `json:"priceLimitRate"`
}

A SymbolModel represents an available currency pairs for trading.

type SymbolsModel

type SymbolsModel []*SymbolModel

type TickerLevel1Model

type TickerLevel1Model struct {
	Sequence    string `json:"sequence"`
	Price       string `json:"price"`
	Size        string `json:"size"`
	BestBid     string `json:"bestBid"`
	BestBidSize string `json:"bestBidSize"`
	BestAsk     string `json:"bestAsk"`
	BestAskSize string `json:"bestAskSize"`
	Time        int64  `json:"time"`
}

A TickerLevel1Model represents ticker include only the inside (i.e. best) bid and ask data, last price and last trade size.

type TickerModel

type TickerModel struct {
	Time             int64  `json:"time"`
	Symbol           string `json:"symbol"`
	SymbolName       string `json:"symbolName"`
	Buy              string `json:"buy"`
	Sell             string `json:"sell"`
	ChangeRate       string `json:"changeRate"`
	ChangePrice      string `json:"changePrice"`
	High             string `json:"high"`
	Low              string `json:"low"`
	Vol              string `json:"vol"`
	VolValue         string `json:"volValue"`
	Last             string `json:"last"`
	AveragePrice     string `json:"averagePrice"`
	TakerFeeRate     string `json:"takerFeeRate"`
	MakerFeeRate     string `json:"makerFeeRate"`
	TakerCoefficient string `json:"takerCoefficient"`
	MakerCoefficient string `json:"makerCoefficient"`
}

A TickerModel represents a market ticker for all trading pairs in the market (including 24h volume).

type TickersModel

type TickersModel []*TickerModel

A TickersModel is the set of *MarketTickerModel.

type TradeFeesResultModel

type TradeFeesResultModel []struct {
	Symbol       string `json:"symbol"`
	TakerFeeRate string `json:"takerFeeRate"`
	MakerFeeRate string `json:"makerFeeRate"`
}

交易手续费

type TradeHistoriesModel

type TradeHistoriesModel []*TradeHistoryModel

A TradeHistoriesModel is the set of *TradeHistoryModel.

type TradeHistoryModel

type TradeHistoryModel struct {
	Sequence string `json:"sequence"`
	Price    string `json:"price"`
	Size     string `json:"size"`
	Side     string `json:"side"`
	Time     int64  `json:"time"`
}

A TradeHistoryModel represents a the latest trades for a symbol.

type WebSocketDownstreamMessage

type WebSocketDownstreamMessage struct {
	*WebSocketMessage
	Sn      string          `json:"sn"`
	Topic   string          `json:"topic"`
	Subject string          `json:"subject"`
	RawData json.RawMessage `json:"data"`
}

A WebSocketDownstreamMessage represents a message from the WebSocket server to client.

func (*WebSocketDownstreamMessage) ReadData

func (m *WebSocketDownstreamMessage) ReadData(v interface{}) error

ReadData read the data in channel.

type WebSocketMessage

type WebSocketMessage struct {
	Id   string `json:"id"`
	Type string `json:"type"`
}

A WebSocketMessage represents a message between the WebSocket client and server.

type WebSocketServerModel

type WebSocketServerModel struct {
	PingInterval int64  `json:"pingInterval"`
	Endpoint     string `json:"endpoint"`
	Protocol     string `json:"protocol"`
	Encrypt      bool   `json:"encrypt"`
	PingTimeout  int64  `json:"pingTimeout"`
}

A WebSocketServerModel contains some servers for WebSocket feed.

type WebSocketServersModel

type WebSocketServersModel []*WebSocketServerModel

A WebSocketServersModel is the set of *WebSocketServerModel.

func (WebSocketServersModel) RandomServer

func (s WebSocketServersModel) RandomServer() (*WebSocketServerModel, error)

RandomServer returns a server randomly.

type WebSocketSubscribeMessage

type WebSocketSubscribeMessage struct {
	*WebSocketMessage
	Topic          string `json:"topic"`
	PrivateChannel bool   `json:"privateChannel"`
	Response       bool   `json:"response"`
}

A WebSocketSubscribeMessage represents a message to subscribe the public/private channel.

type WebSocketTokenModel

type WebSocketTokenModel struct {
	Token             string                `json:"token"`
	Servers           WebSocketServersModel `json:"instanceServers"`
	AcceptUserMessage bool                  `json:"accept_user_message"`
}

A WebSocketTokenModel contains a token and some servers for WebSocket feed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL