SkillAgentSearch skills...

Kucoin Go SDK

Go SDK for KuCoin API.

Install / Use

npx skills add Kucoin/kucoin-go-sdk

Installs into whichever agent you are using.

About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Notice: SDK Deprecation

Thank you for your support and usage of this SDK. We want to inform you that this project is no longer actively maintained or updated.

To ensure you have access to the latest features, improvements, and support, we recommend transitioning to our new SDK: KuCoin Universal SDK.

The KuCoin Universal SDK offers:

  • A unified architecture across multiple programming languages.
  • Enhanced performance and stability.
  • Continued support and updates.

👉 New SDK Repository: https://github.com/Kucoin/kucoin-universal-sdk

We appreciate your understanding and encourage you to migrate to the new SDK for a better development experience. Should you have any questions or require assistance, feel free to reach out to us.

Go SDK for KuCoin API

The detailed document https://docs.kucoin.com, in order to receive the latest API change notifications, please Watch this repository.

Latest Version GoDoc Build Status Go Report Card Sourcegraph

<!-- [![Total Lines](https://tokei.rs/b1/github/Kucoin/kucoin-go-sdk)](https://github.com/Kucoin/kucoin-go-sdk) -->

Install

go get github.com/Kucoin/kucoin-go-sdk

Usage

Choose environment

| Environment | BaseUri | | -------- | -------- | | Production | https://api.kucoin.com(DEFAULT) https://api.kucoin.cc | | Sandbox | https://openapi-sandbox.kucoin.com |

Create ApiService

Note

To reinforce the security of the APIS, KuCoin upgraded the API key to version 2.0, the validation logic has also been changed. It is recommended to create(https://www.kucoin.com/account/api) and update your API key to version 2.0. The API key of version 1.0 will be still valid until May 1, 2021.

// API key version 2.0
s :=  kucoin.NewApiService( 
	// kucoin.ApiBaseURIOption("https://api.kucoin.com"), 
	kucoin.ApiKeyOption("key"),
	kucoin.ApiSecretOption("secret"),
	kucoin.ApiPassPhraseOption("passphrase"),
	kucoin.ApiKeyVersionOption(ApiKeyVersionV2)
)

// API key version 1.0
s := kucoin.NewApiService( 
	// kucoin.ApiBaseURIOption("https://api.kucoin.com"), 
	kucoin.ApiKeyOption("key"),
	kucoin.ApiSecretOption("secret"),
	kucoin.ApiPassPhraseOption("passphrase"), 
)
// Or add these options into the environmental variable
// Bash: 
// export API_BASE_URI=https://api.kucoin.com
// export API_KEY=key
// export API_SECRET=secret
// export API_PASSPHRASE=passphrase
// export API_KEY_VERSION=2
// s := NewApiServiceFromEnv()

Debug mode & logging

// Require package github.com/sirupsen/logrus
// Debug mode will record the logs of API and WebSocket to files.
// Default values: LogLevel=logrus.DebugLevel, LogDirectory="/tmp"
kucoin.DebugMode = true
// Or export API_DEBUG_MODE=1

// Logging in your code
// kucoin.SetLoggerDirectory("/tmp")
// logrus.SetLevel(logrus.DebugLevel)
logrus.Debugln("I'm a debug message")

Examples

See the test case for more examples.

Example of API without authentication

rsp, err := s.ServerTime()
if err != nil {
    log.Printf("Error: %s", err.Error())
    // Handle error
    return
}

var ts int64
if err := rsp.ReadData(&ts); err != nil {
    // Handle error
    return
}
log.Printf("The server time: %d", ts)

Example of API with authentication

// Without pagination
rsp, err := s.Accounts("", "")
if err != nil {
    // Handle error
    return
}

as := kucoin.AccountsModel{}
if err := rsp.ReadData(&as); err != nil {
    // Handle error
    return
}

for _, a := range as {
    log.Printf("Available balance: %s %s => %s", a.Type, a.Currency, a.Available)
}
// Handle pagination
rsp, err := s.Orders(map[string]string{}, &kucoin.PaginationParam{CurrentPage: 1, PageSize: 10})
if err != nil {
    // Handle error
    return
}

os := kucoin.OrdersModel{}
pa, err := rsp.ReadPaginationData(&os)
if err != nil {
    // Handle error
    return
}
log.Printf("Total num: %d, total page: %d", pa.TotalNum, pa.TotalPage)
for _, o := range os {
    log.Printf("Order: %s, %s, %s", o.Id, o.Type, o.Price)
}

Example of WebSocket feed

Require package gorilla/websocket

go get github.com/gorilla/websocket github.com/pkg/errors
rsp, err := s.WebSocketPublicToken()
if err != nil {
    // Handle error
    return
}

tk := &kucoin.WebSocketTokenModel{}
if err := rsp.ReadData(tk); err != nil {
    // Handle error
    return
}

c := s.NewWebSocketClient(tk)

mc, ec, err := c.Connect()
if err != nil {
    // Handle error
    return
}

ch1 := kucoin.NewSubscribeMessage("/market/ticker:KCS-BTC", false)
ch2 := kucoin.NewSubscribeMessage("/market/ticker:ETH-BTC", false)
uch := kucoin.NewUnsubscribeMessage("/market/ticker:ETH-BTC", false)

if err := c.Subscribe(ch1, ch2); err != nil {
    // Handle error
    return
}

var i = 0
for {
    select {
    case err := <-ec:
        c.Stop() // Stop subscribing the WebSocket feed
        log.Printf("Error: %s", err.Error())
        // Handle error
        return
    case msg := <-mc:
        // log.Printf("Received: %s", kucoin.ToJsonString(m))
        t := &kucoin.TickerLevel1Model{}
        if err := msg.ReadData(t); err != nil {
            log.Printf("Failure to read: %s", err.Error())
            return
        }
        log.Printf("Ticker: %s, %s, %s, %s", msg.Topic, t.Sequence, t.Price, t.Size)
        i++
        if i == 5 {
            log.Println("Unsubscribe ETH-BTC")
            if err = c.Unsubscribe(uch); err != nil {
                log.Printf("Error: %s", err.Error())
                // Handle error
                return
            }
        }
        if i == 10 {
            log.Println("Subscribe ETH-BTC")
            if err = c.Subscribe(ch2); err != nil {
                log.Printf("Error: %s", err.Error())
                // Handle error
                return
            }
        }
        if i == 15 {
            log.Println("Exit subscription")
            c.Stop() // Stop subscribing the WebSocket feed
            return
        }
    }
}

API list

<details> <summary>Trade Fee</summary>

| API | Authentication | Description | | -------- | -------- | -------- | | ApiService.BaseFee() | YES | https://docs.kucoin.com/#basic-user-fee | | ApiService.ActualFee() | YES | https://docs.kucoin.com/#actual-fee-rate-of-the-trading-pair |

</details> <details> <summary>Stop Order</summary>

| API | Authentication | Description | | -------- | -------- | -------- | | ApiService.CreateStopOrder() | YES | https://docs.kucoin.com/#place-a-new-order-2 | | ApiService.CancelStopOrder() | YES | https://docs.kucoin.com/#cancel-an-order-2 | | ApiService.CancelStopOrderBy() | YES | https://docs.kucoin.com/#cancel-orders | | ApiService.StopOrder() | YES | https://docs.kucoin.com/#get-single-order-info | | ApiService.StopOrders() | YES | https://docs.kucoin.com/#list-stop-orders | | ApiService.StopOrderByClient() | YES | https://docs.kucoin.com/#get-single-order-by-clientoid | | ApiService.CancelStopOrderByClient() | YES | https://docs.kucoin.com/#cancel-single-order-by-clientoid-2 |

</details> <details> <summary>Account</summary>

| API | Authentication | Description | | -------- | -------- | -------- | | ApiService.CreateAccount() | YES | https://docs.kucoin.com/#create-an-account | | ApiService.Accounts() | YES | https://docs.kucoin.com/#list-accounts | | ApiService.Account() | YES | https://docs.kucoin.com/#get-an-account | | ApiService.SubAccountUsers() | YES | https://docs.kucoin.com/#get-user-info-of-all-sub-accounts | | ApiService.SubAccounts() | YES | https://docs.kucoin.com/#get-the-aggregated-balance-of-all-sub-accounts-of-the-current-user | | ApiService.SubAccount() | YES | https://docs.kucoin.com/#get-account-balance-of-a-sub-account | | ApiService.AccountLedgers() | YES | DEPRECATED https://docs.kucoin.com/#get-account-ledgers-deprecated | | ApiService.AccountHolds() | YES | https://docs.kucoin.com/#get-holds | | ApiService.InnerTransfer() | YES | DEPRECATED https://docs.kucoin.com/#inner-transfer | | ApiService.InnerTransferV2() | YES | https://docs.kucoin.com/#inner-transfer | | ApiService.SubTransfer() | YES | DEPRECATED | | ApiService.SubTransferV2() | YES | https://docs.kucoin.com/#transfer-between-master-user-and-sub-user | | ApiService.AccountLedgersV2() | YES | https://docs.kucoin.com/#get-account-ledgers |

</details> <details> <summary>Deposit</summary>

| API | Authentication | Description | | -------- | -------- | -------- | | ApiService.CreateDepositAddress() | YES | https://docs.kucoin.com/#create-deposit-address | | ApiService.DepositAddresses() | YES | https://docs.kucoin.com/#get-deposit-address | | ApiService.V1Deposits() | YES | https://docs.kucoin.com/#get-v1-historical-deposits-list | | ApiService.Deposits() | YES | https://docs.kucoin.com/#get-deposit-list |

</details> <details> <summary>Fill</summary>

| API | Authentication | Description | | -------- | -------- | -------- | | ApiService.Fills() | YES | https://docs.kucoin.com/#list-fills | | ApiService.RecentFills() | YES | https://docs.kucoin.com/#recent-fills |

</details> <details> <summary>Order</summary>

| API | Authentication | Description | | -------- | -------- | -------- | | ApiService.CreateOrder() |

Related Skills

View on GitHub
GitHub Stars115
CategoryDevelopment
Updated18d ago
Forks71

Languages

Go

Security Score

100/100

Audited on Jul 21, 2026

No findings