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 WithTimeout(d time.Duration) Option
- func WithUTABaseURL(url string) Option
- type RetryPolicy
- type SiteType
- type SpotServices
- type UTAServices
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
}
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 {
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 — pass the returned token/instanceServers to
// websocket/classic.NewClient.
Ws *classicfuturesws.Client
}
FuturesServices groups Classic Futures' implemented services (a seed set — Phase 1 scope, not the full Futures API; see docs/ENDPOINTS.md for exactly what's 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
}
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 WithTimeout ¶
WithTimeout sets the timeout of the default HTTP client.
func WithUTABaseURL ¶
WithUTABaseURL overrides the base URL used for UTA REST requests.
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 — pass the returned token/instanceServers to
// websocket/classic.NewClient.
Ws *classicspotws.Client
}
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 the private WebSocket bullet-token
// (POST /api/v2/bullet-private). It does not open a socket itself —
// pass the returned token to websocket/uta.NewClient.
Ws *utaws.Client
}
UTAServices groups every implemented UTA (Unified Trading Account) service.
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/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/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/... |
|
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/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
|
|
|
uta_market
command
Command uta_market demonstrates KuCoin UTA public market data.
|
Command uta_market demonstrates KuCoin UTA public market data. |
|
uta_trading
command
Command uta_trading demonstrates authenticated UTA account/order/ position endpoints.
|
Command uta_trading demonstrates authenticated UTA account/order/ position endpoints. |
|
internal
|
|
|
gendocs
command
Command gendocs regenerates docs/ENDPOINTS.md from internal/endpoints.yaml, the single source of truth for endpoint coverage.
|
Command gendocs regenerates docs/ENDPOINTS.md from internal/endpoints.yaml, the single source of truth for endpoint coverage. |
|
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. |
|
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. |
|
ws
Package ws implements KuCoin UTA's WebSocket token-acquisition endpoint.
|
Package ws implements KuCoin UTA's WebSocket token-acquisition endpoint. |
|
websocket
|
|
|
classic
Package classic implements a reconnecting WebSocket client for KuCoin's Classic (Spot/Margin/Futures) WebSocket API.
|
Package classic implements a reconnecting WebSocket client for KuCoin's Classic (Spot/Margin/Futures) WebSocket API. |
|
uta
Package uta implements a reconnecting WebSocket client for KuCoin's UTA WebSocket API.
|
Package uta implements a reconnecting WebSocket client for KuCoin's UTA WebSocket API. |
