Documentation
¶
Overview ¶
Package kucoin is an idiomatic Go client for KuCoin's UTA (Unified Trading Account) and Classic (Spot/Margin/Futures) REST and WebSocket APIs.
UTA and Classic are exposed as explicit, separate service roots (Client.UTA / Client.Classic) rather than a merged type — they are different account models with different permissions and data shapes, and treating them as interchangeable would be misleading.
Index ¶
- Constants
- Variables
- type ClassicServices
- type Client
- type ClientConfig
- type Clock
- type Credentials
- type FuturesServices
- type Logger
- type MarginServices
- type Option
- func WithClassicBaseURL(url string) Option
- func WithClassicFuturesBaseURL(url string) Option
- func WithClock(clock Clock) Option
- func WithCredentials(creds Credentials) Option
- func WithEnableNS(enabled bool) Option
- func WithHTTPClient(hc *http.Client) Option
- func WithLogger(logger Logger) Option
- func WithRetryPolicy(policy *RetryPolicy) Option
- func WithSiteType(siteType SiteType) Option
- func WithStreamOptions(opts ...stream.Option) Option
- func WithTimeout(d time.Duration) Option
- func WithUTABaseURL(url string) Option
- func WithUTAWebSocketHosts(hosts utav2streaming.Hosts) Option
- type RetryPolicy
- type SiteType
- type SpotServices
- type UTAServices
- type UTAV2Services
Constants ¶
const ( DefaultUTABaseURL = "https://api.kucoin.com" DefaultClassicBaseURL = "https://api.kucoin.com" DefaultClassicFuturesBaseURL = "https://api-futures.kucoin.com" )
Default production REST hosts. UTA and Classic Spot currently share a host; kept as separate options so they can diverge without a breaking change. Classic Futures has always used a distinct host, confirmed across every Futures endpoint.
Docs: https://www.kucoin.com/docs-new/rest/ua/introduction Docs: https://www.kucoin.com/docs-new/rest/spot-trading/introduction Docs: https://www.kucoin.com/docs-new/rest/futures-trading/introduction
const ( SiteTypeGlobal = transport.SiteTypeGlobal SiteTypeAustralia = transport.SiteTypeAustralia )
SiteTypeGlobal and SiteTypeAustralia re-export KuCoin's supported regional site types.
Variables ¶
var NewDefaultRetryPolicy = transport.NewDefaultRetryPolicy
NewDefaultRetryPolicy re-exports transport.NewDefaultRetryPolicy.
var NoRetry = transport.NoRetry
NoRetry re-exports transport.NoRetry.
Functions ¶
This section is empty.
Types ¶
type ClassicServices ¶ added in v1.1.6
type ClassicServices struct {
Spot SpotServices
Futures FuturesServices
Margin MarginServices
}
ClassicServices groups every implemented Classic (pre-UTA) account-mode service.
type Client ¶
type Client struct {
// UTA groups every implemented UTA (Unified Trading Account) service.
UTA UTAServices
// Classic groups every implemented Classic account-mode service.
Classic ClassicServices
// contains filtered or unexported fields
}
Client is the SDK entry point. Construct with NewClient. Public endpoints (e.g. Client.UTA.Market) work with zero-value Credentials; private endpoints return ErrCredentialsRequired locally if none are configured.
type ClientConfig ¶
type ClientConfig struct {
Credentials Credentials
UTABaseURL string
ClassicBaseURL string
ClassicFuturesBaseURL string
HTTPClient *http.Client
Timeout time.Duration
SiteType SiteType
EnableNS bool
Clock Clock
Logger Logger
RetryPolicy *RetryPolicy
// StreamOptions are the default connection options of every WebSocket
// session dialled from the client (reconnect policy, buffer sizes,
// lifecycle-event handler, ...). Options passed to an individual Dial call
// are applied after them.
StreamOptions []stream.Option
// UTAWebSocketHosts overrides the WebSocket endpoints of the UTA v2 streaming
// service (a proxy, a test server). An empty field keeps KuCoin's documented
// host. Classic services need no override: their endpoint comes from the
// connection token that the REST host (see ClassicBaseURL) returns.
UTAWebSocketHosts utav2streaming.Hosts
}
ClientConfig holds every configurable knob of a Client. Zero value is usable; NewClient fills in defaults for unset fields.
type Credentials ¶
type Credentials = transport.Credentials
Credentials re-exports transport.Credentials for callers of package kucoin.
type FuturesServices ¶ added in v1.1.6
type FuturesServices struct {
// Market is the public market-data REST group: contracts, tickers, order
// books, trades, klines, mark/index prices, funding rates and service
// status.
Market *classicfuturesmarket.Client
Orders *classicfuturesorders.Client
Positions *classicfuturespositions.Client
// Ws fetches public/private WebSocket bullet-tokens
// (POST /api/v1/bullet-public, /api/v1/bullet-private). It does not
// open a socket itself; Stream does, and fetches the tokens for you.
Ws *classicfuturesws.Client
// Stream opens typed WebSocket sessions (DialPublic, DialPrivate) with
// every Classic Futures channel and a managed local order book. See
// docs/STREAMING.md.
Stream *classicfuturesstreaming.Service
}
FuturesServices groups Classic Futures' implemented services: the complete public market-data REST group, the seed orders/positions services, the WebSocket token calls and the typed WebSocket streaming service. See docs/ENDPOINTS.md and docs/CHANNELS.md for exactly what is covered.
Docs: https://www.kucoin.com/docs-new/rest/futures-trading/introduction
type MarginServices ¶ added in v1.1.6
type MarginServices struct {
Market *classicmarginmarket.Client
Orders *classicmarginorders.Client
Debit *classicmargindebit.Client
// Stream opens typed WebSocket sessions (DialPublic, DialPrivate) with every
// Classic Margin channel; its sessions also carry the Spot channels, which
// share the WebSocket host and tokens. See docs/STREAMING.md.
Stream *classicmarginstreaming.Service
}
MarginServices groups Classic Margin's implemented services (a seed set covering symbols/mark-price/config/risk-limit market data, core order management, and borrow/repay/interest — not the full Margin API; see docs/ENDPOINTS.md for exactly what's covered). Margin shares Classic Spot's host (api.kucoin.com).
Docs: https://www.kucoin.com/docs-new/rest/margin-trading/introduction
type Option ¶
type Option func(*ClientConfig)
Option configures a ClientConfig at construction time.
func WithClassicBaseURL ¶
WithClassicBaseURL overrides the base URL used for Classic Spot and Margin REST requests.
func WithClassicFuturesBaseURL ¶ added in v1.1.6
WithClassicFuturesBaseURL overrides the base URL used for Classic Futures REST requests.
func WithCredentials ¶
func WithCredentials(creds Credentials) Option
WithCredentials sets API credentials used for private endpoints.
func WithEnableNS ¶
WithEnableNS sends "kc-enable-ns: true", requesting nanosecond-precision x-in-time/x-out-time response headers.
func WithHTTPClient ¶
WithHTTPClient sets the HTTP client used for REST requests.
func WithLogger ¶
WithLogger sets the logger used by REST transport.
func WithRetryPolicy ¶
func WithRetryPolicy(policy *RetryPolicy) Option
WithRetryPolicy overrides the default conservative retry policy (GET requests only; see transport.RetryPolicy).
func WithSiteType ¶
WithSiteType sets the X-SITE-TYPE header sent with requests.
func WithStreamOptions ¶ added in v1.3.0
WithStreamOptions sets default connection options for every WebSocket session the client dials: the reconnect policy, subscription buffer size and overflow policy, heartbeat overrides, a lifecycle-event handler and so on. The client's Logger is used for stream diagnostics unless stream.WithLogger is among the options. Options given to an individual Dial call override these.
func WithTimeout ¶
WithTimeout sets the timeout of the default HTTP client.
func WithUTABaseURL ¶
WithUTABaseURL overrides the base URL used for UTA REST requests.
func WithUTAWebSocketHosts ¶ added in v1.3.0
func WithUTAWebSocketHosts(hosts utav2streaming.Hosts) Option
WithUTAWebSocketHosts overrides the WebSocket endpoints the UTA v2 streaming service dials (see utav2streaming.Hosts); empty fields keep KuCoin's documented hosts. Use it to reach KuCoin through a proxy or to point tests at a fake server.
type RetryPolicy ¶
type RetryPolicy = transport.RetryPolicy
RetryPolicy re-exports transport.RetryPolicy for callers of package kucoin.
type SpotServices ¶ added in v1.1.6
type SpotServices struct {
Market *classicspotmarket.Client
Orders *classicspotorders.Client
// Ws fetches public/private WebSocket bullet-tokens
// (POST /api/v1/bullet-public, /api/v1/bullet-private). It does not
// open a socket itself; Stream does, and fetches the tokens for you.
Ws *classicspotws.Client
// Stream opens typed WebSocket sessions (DialPublic, DialPrivate) with every
// Classic Spot channel and a managed local order book (which needs API
// credentials for its REST snapshot). See docs/STREAMING.md.
Stream *classicspotstreaming.Service
}
SpotServices groups Classic Spot's implemented services.
Docs: https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-all-symbols
type UTAServices ¶
type UTAServices struct {
Market *market.Client
Account *account.Client
Orders *orders.Client
Positions *positions.Client
Leverage *leverage.Client
// Ws fetches a legacy private WebSocket bullet-token. The current UTA v2
// WebSocket flow uses websocket/uta.WithCredentials after welcome; this
// service remains available only for source compatibility.
Ws *utaws.Client
// V2 contains current UTA REST v2 services. Existing UTA v1 services
// remain in place for source compatibility; do not mix v1 and v2 data
// models in one workflow without consulting KuCoin's migration notes.
V2 UTAV2Services
}
UTAServices groups every implemented UTA (Unified Trading Account) service.
type UTAV2Services ¶ added in v1.2.0
type UTAV2Services struct {
Market *utav2market.Client
// Stream opens typed UTA WebSocket v2 sessions (DialFutures, DialSpot,
// DialPrivate) with every channel of the current documentation and a managed
// local order book. See docs/STREAMING.md.
Stream *utav2streaming.Service
}
UTAV2Services groups current UTA REST v2 services. It is intentionally nested below UTA so Classic and UTA account semantics remain explicit.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package auth implements KuCoin's HMAC-SHA256 request-signing scheme.
|
Package auth implements KuCoin's HMAC-SHA256 request-signing scheme. |
|
classic
|
|
|
futures/market
Package market implements KuCoin Classic Futures' public market-data REST endpoints (contracts, tickers, order books, trades, klines, mark/index prices, interest-rate and premium indices, server time and service status) and the two public funding-rate endpoints.
|
Package market implements KuCoin Classic Futures' public market-data REST endpoints (contracts, tickers, order books, trades, klines, mark/index prices, interest-rate and premium indices, server time and service status) and the two public funding-rate endpoints. |
|
futures/orders
Package orders implements a seed set of KuCoin Classic Futures' private order-management endpoints (place/test/query — Phase 1 scope; cancel and the broader stop/OCO order family are not yet implemented).
|
Package orders implements a seed set of KuCoin Classic Futures' private order-management endpoints (place/test/query — Phase 1 scope; cancel and the broader stop/OCO order family are not yet implemented). |
|
futures/positions
Package positions implements a seed set of KuCoin Classic Futures' private position-related endpoints.
|
Package positions implements a seed set of KuCoin Classic Futures' private position-related endpoints. |
|
futures/streaming
Package streaming is the typed WebSocket API for KuCoin Classic Futures.
|
Package streaming is the typed WebSocket API for KuCoin Classic Futures. |
|
futures/ws
Package ws implements KuCoin Classic Futures' WebSocket token-acquisition endpoints.
|
Package ws implements KuCoin Classic Futures' WebSocket token-acquisition endpoints. |
|
margin/debit
Package debit implements KuCoin Classic Margin's borrow/repay/interest endpoints (the "Debit" sub-domain) plus leverage modification.
|
Package debit implements KuCoin Classic Margin's borrow/repay/interest endpoints (the "Debit" sub-domain) plus leverage modification. |
|
margin/market
Package market implements a seed set of KuCoin Classic Margin's public market-data endpoints: symbol specs (cross + isolated), mark price, margin config, and risk limits (cross + isolated).
|
Package market implements a seed set of KuCoin Classic Margin's public market-data endpoints: symbol specs (cross + isolated), mark price, margin config, and risk limits (cross + isolated). |
|
margin/orders
Package orders implements KuCoin Classic Margin's private order-management endpoints, all under the /api/v3/hf/margin/...
|
Package orders implements KuCoin Classic Margin's private order-management endpoints, all under the /api/v3/hf/margin/... |
|
margin/streaming
Package streaming is the typed WebSocket API for KuCoin Classic Margin.
|
Package streaming is the typed WebSocket API for KuCoin Classic Margin. |
|
spot/market
Package market implements KuCoin Classic Spot's market-data endpoints.
|
Package market implements KuCoin Classic Spot's market-data endpoints. |
|
spot/orders
Package orders implements KuCoin Classic Spot's private order-management endpoints.
|
Package orders implements KuCoin Classic Spot's private order-management endpoints. |
|
spot/streaming
Package streaming is the typed WebSocket API for KuCoin Classic Spot.
|
Package streaming is the typed WebSocket API for KuCoin Classic Spot. |
|
spot/ws
Package ws implements KuCoin Classic Spot/Margin's WebSocket token-acquisition endpoints.
|
Package ws implements KuCoin Classic Spot/Margin's WebSocket token-acquisition endpoints. |
|
ws
Package ws holds the token response shape shared by Classic Spot and Classic Futures' WebSocket token-acquisition endpoints.
|
Package ws holds the token response shape shared by Classic Spot and Classic Futures' WebSocket token-acquisition endpoints. |
|
examples
|
|
|
futures_market
command
futures_market is a tour of KuCoin Classic Futures' public market-data REST endpoints: contract specification, ticker, order books, trades, candles, mark price and funding rates.
|
futures_market is a tour of KuCoin Classic Futures' public market-data REST endpoints: contract specification, ticker, order books, trades, candles, mark price and funding rates. |
|
futures_orderbook
command
futures_orderbook keeps an exact local order book of a Classic Futures contract and prints its best levels once a second.
|
futures_orderbook keeps an exact local order book of a Classic Futures contract and prints its best levels once a second. |
|
futures_stream
command
futures_stream streams KuCoin Classic Futures market data as typed Go values: best bid/offer, trades, one-minute candles and mark/index price, for any number of symbols over one connection.
|
futures_stream streams KuCoin Classic Futures market data as typed Go values: best bid/offer, trades, one-minute candles and mark/index price, for any number of symbols over one connection. |
|
spot_stream
command
spot_stream streams KuCoin Classic Spot market data as typed Go values: best bid/offer, the best five levels of the order book, trades and one-minute candles for any number of symbols over one connection.
|
spot_stream streams KuCoin Classic Spot market data as typed Go values: best bid/offer, the best five levels of the order book, trades and one-minute candles for any number of symbols over one connection. |
|
uta_market
command
Command uta_market demonstrates KuCoin UTA public market data.
|
Command uta_market demonstrates KuCoin UTA public market data. |
|
uta_stream
command
uta_stream streams KuCoin's current UTA WebSocket v2 futures market data as typed Go values: ticker, trades, one-minute candles, mark price and funding rate for any number of symbols, plus a managed local order book built from the 10ms incremental feed (which pushes its own snapshot first, so no REST call or credentials are needed).
|
uta_stream streams KuCoin's current UTA WebSocket v2 futures market data as typed Go values: ticker, trades, one-minute candles, mark price and funding rate for any number of symbols, plus a managed local order book built from the 10ms incremental feed (which pushes its own snapshot first, so no REST call or credentials are needed). |
|
uta_trading
command
Command uta_trading demonstrates authenticated UTA account/order/ position endpoints.
|
Command uta_trading demonstrates authenticated UTA account/order/ position endpoints. |
|
uta_v2_market
command
uta_v2_market demonstrates current UTA REST v2 public market data.
|
uta_v2_market demonstrates current UTA REST v2 public market data. |
|
internal
|
|
|
gendocs
command
Command gendocs regenerates docs/ENDPOINTS.md and docs/CHANNELS.md from internal/endpoints.yaml and internal/channels.yaml, the single sources of truth for REST and WebSocket coverage.
|
Command gendocs regenerates docs/ENDPOINTS.md and docs/CHANNELS.md from internal/endpoints.yaml and internal/channels.yaml, the single sources of truth for REST and WebSocket coverage. |
|
wsengine
Package wsengine is the shared connection engine behind every KuCoin WebSocket client of this module.
|
Package wsengine is the shared connection engine behind every KuCoin WebSocket client of this module. |
|
wstest
Package wstest provides the test support shared by the WebSocket packages of this module: a scriptable WebSocket server that stands in for KuCoin, and a goroutine-leak checker.
|
Package wstest provides the test support shared by the WebSocket packages of this module: a scriptable WebSocket server that stands in for KuCoin, and a goroutine-leak checker. |
|
Package orderbook maintains exact-decimal local order books and the typed price levels, snapshots and deltas shared by every order-book source of this module (Classic Futures, Classic Spot and UTA, over REST and WebSocket).
|
Package orderbook maintains exact-decimal local order books and the typed price levels, snapshots and deltas shared by every order-book source of this module (Classic Futures, Classic Spot and UTA, over REST and WebSocket). |
|
Package stream defines the connection-lifecycle vocabulary shared by every KuCoin WebSocket client in this module: connection State and lifecycle Event values, typed errors, the generic Subscription handle that streaming packages return, the Handler interface for custom frame processing, and the Config used to tune reconnect, heartbeat and back-pressure behaviour.
|
Package stream defines the connection-lifecycle vocabulary shared by every KuCoin WebSocket client in this module: connection State and lifecycle Event values, typed errors, the generic Subscription handle that streaming packages return, the Handler interface for custom frame processing, and the Config used to tune reconnect, heartbeat and back-pressure behaviour. |
|
Package transport implements the shared HTTP request executor, response metadata capture, and error hierarchy used by every KuCoin service.
|
Package transport implements the shared HTTP request executor, response metadata capture, and error hierarchy used by every KuCoin service. |
|
Package types holds the wire-level value types shared by every typed REST model and WebSocket payload in this module.
|
Package types holds the wire-level value types shared by every typed REST model and WebSocket payload in this module. |
|
uta
|
|
|
account
Package account implements KuCoin UTA's private account endpoints.
|
Package account implements KuCoin UTA's private account endpoints. |
|
leverage
Package leverage implements KuCoin UTA's private leverage-management endpoints.
|
Package leverage implements KuCoin UTA's private leverage-management endpoints. |
|
market
Package market implements KuCoin UTA's public market-data endpoints.
|
Package market implements KuCoin UTA's public market-data endpoints. |
|
orders
Package orders implements KuCoin UTA's private order-management endpoints.
|
Package orders implements KuCoin UTA's private order-management endpoints. |
|
positions
Package positions implements KuCoin UTA's private position-management endpoints.
|
Package positions implements KuCoin UTA's private position-management endpoints. |
|
v2/market
Package market implements the current UTA REST v2 public market-data API.
|
Package market implements the current UTA REST v2 public market-data API. |
|
v2/streaming
Package streaming is the typed WebSocket API for KuCoin's current UTA WebSocket v2.
|
Package streaming is the typed WebSocket API for KuCoin's current UTA WebSocket v2. |
|
ws
Package ws preserves the legacy UTA WebSocket token-acquisition endpoint.
|
Package ws preserves the legacy UTA WebSocket token-acquisition endpoint. |
|
websocket
|
|
|
classic
Package classic implements a managed WebSocket client for KuCoin's Classic (Spot/Margin/Futures) WebSocket API: connection lifecycle, heartbeats, reconnection with a fresh token, resubscription and topic routing.
|
Package classic implements a managed WebSocket client for KuCoin's Classic (Spot/Margin/Futures) WebSocket API: connection lifecycle, heartbeats, reconnection with a fresh token, resubscription and topic routing. |
|
uta
Package uta implements a managed WebSocket client for KuCoin's current UTA WebSocket v2 push API: connection lifecycle, heartbeats, signed authentication of private connections, reconnection, resubscription and routing of pushes to subscriptions by channel, symbol, depth and interval.
|
Package uta implements a managed WebSocket client for KuCoin's current UTA WebSocket v2 push API: connection lifecycle, heartbeats, signed authentication of private connections, reconnection, resubscription and routing of pushes to subscriptions by channel, symbol, depth and interval. |
