kucoin

package
v0.0.202 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApiSuccess = "200000"
)

The predefined API codes

View Source
const ProductionApiBaseURI = "https://api.kucoin.com"

ProductionApiBaseURI is api base uri for production.

Variables

View Source
var (
	BeforeRequest func(client *ApiService, request *Request, rps float64) error = nil
	AfterRequest  func()                                                        = nil
)

Functions

func IntToString

func IntToString(i int64) string

IntToString converts int64 to string.

func ToJsonString

func ToJsonString(v interface{}) string

ToJsonString converts any value to JSON 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    interface{}     `json:"code"`
	RawData json.RawMessage `json:"data"` // delay parsing
	Message string          `json:"msg"`
	// contains filtered or unexported fields
}

An ApiResponse represents a API response wrapped Response.

func (*ApiResponse) ApiSuccessful

func (ar *ApiResponse) ApiSuccessful() bool

ApiSuccessful judges the success of API.

func (*ApiResponse) HttpSuccessful

func (ar *ApiResponse) HttpSuccessful() bool

HttpSuccessful judges the success of http.

func (*ApiResponse) ReadData

func (ar *ApiResponse) ReadData(v interface{}) error

ReadData read the api response `data` as JSON into v.

func (*ApiResponse) ReadPaginationData

func (ar *ApiResponse) ReadPaginationData(v interface{}) (*PaginationModel, error)

ReadPaginationData read the data `items` as JSON into v, and returns *PaginationModel.

type ApiService

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

An ApiService provides a HTTP client and a signer to make a HTTP request with the signature to KuCoin API.

func NewApiService

func NewApiService(opts ...ApiServiceOption) *ApiService

NewApiService creates a instance of ApiService by passing ApiServiceOptions, then you can call methods.

func (*ApiService) Accounts

func (as *ApiService) Accounts(currency, typo string) (*ApiResponse, error)

Accounts returns a list of accounts. See the Deposits section for documentation on how to deposit funds to begin trading.

func (*ApiService) AggregatedFullOrderBook

func (as *ApiService) AggregatedFullOrderBook(symbol string) (*ApiResponse, error)

AggregatedFullOrderBook returns a list of open orders(aggregated) for a symbol.

func (*ApiService) CancelOrder

func (as *ApiService) CancelOrder(orderId string) (*ApiResponse, error)

CancelOrder cancels a previously placed order.

func (*ApiService) CancelStopOrder

func (as *ApiService) CancelStopOrder(orderId string) (*ApiResponse, error)

CancelStopOrder cancels a previously placed stop-order.

func (*ApiService) CreateOrder

func (as *ApiService) CreateOrder(params map[string]string) (*ApiResponse, error)

CreateOrder places a new order.

func (*ApiService) CreateStopOrder

func (as *ApiService) CreateStopOrder(params map[string]string) (*ApiResponse, error)

CreateStopOrder places a new stop-order.

func (*ApiService) Fills

func (as *ApiService) Fills(params map[string]string, pagination *PaginationParam) (*ApiResponse, error)

Fills returns a list of recent fills.

func (*ApiService) Markets

func (as *ApiService) Markets() (*ApiResponse, error)

Markets returns the transaction currencies for the entire trading market.

func (*ApiService) Order

func (as *ApiService) Order(orderId string) (*ApiResponse, error)

Order returns a single order by order id.

func (*ApiService) Orders

func (as *ApiService) Orders(params map[string]string, pagination *PaginationParam) (*ApiResponse, error)

Orders returns a list your current orders.

func (*ApiService) RecentFills

func (as *ApiService) RecentFills() (*ApiResponse, error)

RecentFills returns the recent fills of the latest transactions within 24 hours.

func (*ApiService) RecentOrders

func (as *ApiService) RecentOrders() (*ApiResponse, error)

RecentOrders returns the recent orders of the latest transactions within 24 hours.

func (*ApiService) ServerTime

func (as *ApiService) ServerTime() (*ApiResponse, error)

ServerTime returns the API server time.

func (*ApiService) Stats24hr

func (as *ApiService) Stats24hr(symbol string) (*ApiResponse, error)

Stats24hr returns 24 hr stats for the symbol. volume is in base currency units. open, high, low are in quote currency units.

func (*ApiService) StopOrder

func (as *ApiService) StopOrder(orderId string) (*ApiResponse, error)

StopOrder returns a single order by stop-order id.

func (*ApiService) StopOrders

func (as *ApiService) StopOrders(params map[string]string, pagination *PaginationParam) (*ApiResponse, error)

StopOrders returns a list your current stop-orders.

func (*ApiService) Symbols

func (as *ApiService) Symbols(market string) (*ApiResponse, error)

Symbols returns a list of available currency pairs for trading.

func (*ApiService) TickerLevel1

func (as *ApiService) TickerLevel1(symbol string) (*ApiResponse, error)

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

func (*ApiService) Tickers

func (as *ApiService) Tickers() (*ApiResponse, error)

Tickers returns all tickers as TickersResponseModel for all trading pairs in the market (including 24h volume).

type ApiServiceOption

type ApiServiceOption func(service *ApiService)

An ApiServiceOption is a option parameter to create the instance of ApiService.

func ApiBaseURIOption

func ApiBaseURIOption(uri string) ApiServiceOption

ApiBaseURIOption creates a instance of ApiServiceOption about apiBaseURI.

func ApiKeyOption

func ApiKeyOption(key string) ApiServiceOption

ApiKeyOption creates a instance of ApiServiceOption about apiKey.

func ApiPartnerIdOption

func ApiPartnerIdOption(partnerID string) ApiServiceOption

func ApiPartnerSecretOption

func ApiPartnerSecretOption(partnerSecret string) ApiServiceOption

func ApiPassPhraseOption

func ApiPassPhraseOption(passPhrase string) ApiServiceOption

ApiPassPhraseOption creates a instance of ApiServiceOption about apiPassPhrase.

func ApiSecretOption

func ApiSecretOption(secret string) ApiServiceOption

ApiSecretOption creates a instance of ApiServiceOption about apiSecret.

type BasicRequester

type BasicRequester struct {
}

A BasicRequester represents a basic implement of Requester by http.Client.

func (*BasicRequester) Request

func (br *BasicRequester) Request(request *Request, timeout time.Duration) (*Response, error)

Request makes a http request.

type BookEntry

type BookEntry []string

BookEntry = bid or ask info with price and size

func (*BookEntry) Price

func (be *BookEntry) Price() float64

Price = bid or ask price

func (*BookEntry) Size

func (be *BookEntry) Size() float64

Size = bid or ask size

type CancelOrderResultModel

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

A CancelOrderResultModel represents the result of CancelOrder().

type CreateOrderResultModel

type CreateOrderResultModel struct {
	OrderId string `json:"orderId"`
}

A CreateOrderResultModel represents the result of CreateOrder().

type FillModel

type FillModel struct {
	Symbol         string `json:"symbol"`
	TradeId        string `json:"tradeId"`
	OrderId        string `json:"orderId"`
	CounterOrderId string `json:"counterOrderId"`
	Side           string `json:"side"`
	Liquidity      string `json:"liquidity"`
	ForceTaker     bool   `json:"forceTaker"`
	Price          string `json:"price"`
	Size           string `json:"size"`
	Funds          string `json:"funds"`
	Fee            string `json:"fee"`
	FeeRate        string `json:"feeRate"`
	FeeCurrency    string `json:"feeCurrency"`
	Stop           string `json:"stop"`
	Type           string `json:"type"`
	CreatedAt      int64  `json:"createdAt"`
}

A FillModel represents the structure of fill.

func (*FillModel) ParseCreatedAt

func (fill *FillModel) ParseCreatedAt() time.Time

ParseCreatedAt returns the creation time as time.Time

func (*FillModel) ParsePrice

func (fill *FillModel) ParsePrice() float64

ParsePrice returns the price as float64

func (*FillModel) ParseSize

func (fill *FillModel) ParseSize() float64

ParseSize returns the quantity as float64

type FillsModel

type FillsModel []*FillModel

A FillsModel is the set of *FillModel.

func (FillsModel) IndexOfOrderId

func (fills FillsModel) IndexOfOrderId(orderId string) int

type FullOrderBookModel

type FullOrderBookModel struct {
	Sequence string      `json:"sequence"`
	Bids     []BookEntry `json:"bids"`
	Asks     []BookEntry `json:"asks"`
}

A FullOrderBookModel represents a list of open orders for a symbol, with full depth.

type KcSigner

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

KcSigner is the implement of Signer for KuCoin.

func NewKcSigner

func NewKcSigner(key, secret, passPhrase, partnerID, partnerSecret string, version int) *KcSigner

NewKcSigner creates a instance of KcSigner.

func (*KcSigner) Headers

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

Headers returns a map of signature header.

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,omitempty"`
	DealFunds     string `json:"dealFunds,omitempty"`
	DealSize      string `json:"dealSize,omitempty"`
	Fee           string `json:"fee,omitempty"`
	FeeCurrency   string `json:"feeCurrency,omitempty"`
	Stp           string `json:"stp,omitempty"`
	Stop          string `json:"stop,omitempty"`
	StopTriggered bool   `json:"stopTriggered,omitempty"`
	StopPrice     string `json:"stopPrice,omitempty"`
	TimeInForce   string `json:"timeInForce,omitempty"`
	PostOnly      bool   `json:"postOnly,omitempty"`
	Hidden        bool   `json:"hidden,omitempty"`
	IceBerg       bool   `json:"iceberg,omitempty"`
	VisibleSize   string `json:"visibleSize,omitempty"`
	CancelAfter   int64  `json:"cancelAfter,omitempty"`
	Channel       string `json:"channel,omitempty"`
	ClientOid     string `json:"clientOid,omitempty"`
	Remark        string `json:"remark,omitempty"`
	Tags          string `json:"tags,omitempty"`
	IsActive      bool   `json:"isActive,omitempty"`
	CancelExist   bool   `json:"cancelExist,omitempty"`
	CreatedAt     int64  `json:"createdAt,omitempty"`
	TradeType     string `json:"tradeType,omitempty"`
	Status        string `json:"status,omitempty"`
	FailMsg       string `json:"failMsg,omitempty"`
}

An OrderModel represents an order.

func (*OrderModel) ParseCreatedAt

func (o *OrderModel) ParseCreatedAt() time.Time

ParseCreatedAt returns the creation time as time.Time

func (*OrderModel) ParsePrice

func (o *OrderModel) ParsePrice() float64

ParsePrice returns the Price as float64

func (*OrderModel) ParseSize

func (o *OrderModel) ParseSize() float64

ParseSize returns the Quantity as float64

func (*OrderModel) ParseStopPrice

func (o *OrderModel) ParseStopPrice() float64

ParseStopPrice returns the StopPrice as float64

type OrderPredicate

type OrderPredicate func(order *OrderModel) bool

A OrdersModel is the set of *OrderModel.

type OrdersModel

type OrdersModel []*OrderModel

A OrdersModel is the set of *OrderModel.

func (OrdersModel) Find

func (orders OrdersModel) Find(callback *OrderPredicate) int

func (OrdersModel) IndexOfId

func (orders OrdersModel) IndexOfId(Id string) int

type PaginationModel

type PaginationModel struct {
	CurrentPage int64           `json:"currentPage"`
	PageSize    int64           `json:"pageSize"`
	TotalNum    int64           `json:"totalNum"`
	TotalPage   int64           `json:"totalPage"`
	RawItems    json.RawMessage `json:"items"` // delay parsing
}

A PaginationModel represents the pagination in a response.

func (*PaginationModel) ReadItems

func (p *PaginationModel) ReadItems(v interface{}) error

ReadItems read the `items` into v.

type PaginationParam

type PaginationParam struct {
	CurrentPage int64
	PageSize    int64
}

A PaginationParam represents the pagination parameters `currentPage` `pageSize` in a request .

func (*PaginationParam) ReadParam

func (p *PaginationParam) ReadParam(params map[string]string)

ReadParam read pagination parameters into params.

type Request

type Request struct {
	BaseURI string
	Method  string
	Path    string
	Query   url.Values
	Body    []byte
	Header  http.Header
	Timeout time.Duration
	// contains filtered or unexported fields
}

A Request represents a HTTP request.

func NewRequest

func NewRequest(method, path string, params map[string]string) *Request

NewRequest creates a instance of Request.

func (*Request) FullURL

func (r *Request) FullURL() string

FullURL returns the full url.

func (*Request) HttpRequest

func (r *Request) HttpRequest() (*http.Request, error)

HttpRequest creates a instance of *http.Request.

func (*Request) RequestURI

func (r *Request) RequestURI() string

RequestURI returns the request uri.

type Requester

type Requester interface {
	Request(request *Request, timeout time.Duration) (*Response, error)
}

Requester contains Request() method, can launch a http request.

type Response

type Response struct {
	*http.Response
	// contains filtered or unexported fields
}

A Response represents a HTTP response.

func (*Response) ReadBody

func (r *Response) ReadBody() ([]byte, error)

ReadBody read the response data, then return it.

func (*Response) ReadJsonBody

func (r *Response) ReadJsonBody(v interface{}) error

ReadJsonBody read the response data as JSON into v.

type Stats24hrModel

type Stats24hrModel struct {
	Symbol      string `json:"symbol"`
	ChangeRate  string `json:"changeRate"`
	ChangePrice string `json:"changePrice"`
	Open        string `json:"open"`
	Close       string `json:"close"`
	High        string `json:"high"`
	Low         string `json:"low"`
	Vol         string `json:"vol"`
	VolValue    string `json:"volValue"`
}

A Stats24hrModel represents 24 hr stats for the symbol. Volume is in base currency units. Open, high, low are in quote currency units.

type SymbolModel

type SymbolModel struct {
	Symbol          string `json:"symbol"`
	Name            string `json:"name"`
	BaseCurrency    string `json:"baseCurrency"`
	QuoteCurrency   string `json:"quoteCurrency"`
	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

A SymbolsModel is the set of *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 {
	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 TickersResponseModel

type TickersResponseModel struct {
	Time    int64        `json:"time"`
	Tickers TickersModel `json:"ticker"`
}

TickersResponseModel represents the response model of MarketTickers().

Jump to

Keyboard shortcuts

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