Skip to content
Go SDK for KuCoin API.
Branch: master
Clone or download
Latest commit 4433475 Mar 8, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples fix ticker model Feb 21, 2019
.gitignore init sdk Jan 20, 2019
.travis.yml
LICENSE
README.md add watch notice Mar 8, 2019
account.go add comments for typo Feb 21, 2019
account_test.go rename AccountHistories to AccountLedgers Feb 21, 2019
api.go
currency.go
currency_test.go update ApiService.Prices() Feb 21, 2019
deposit.go
deposit_test.go skip test deposit address Feb 21, 2019
fill.go
fill_test.go
helper.go
helper_test.go
http.go Revert Jan 30, 2019
order.go
order_test.go fix recent fills Feb 18, 2019
pagination.go
signer.go
signer_test.go
symbol.go
symbol_test.go
time.go add more comments Jan 25, 2019
time_test.go add deposit api Jan 23, 2019
websocket.go optimize ticker of websocket Feb 11, 2019
websocket_test.go
withdrawal.go
withdrawal_test.go

README.md

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

Install

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

Usage

Choose environment

Environment BaseUri
Production DEFAULT https://openapi-v2.kucoin.com
Sandbox https://openapi-sandbox.kucoin.com

Create ApiService

s := kucoin.NewApiService( 
	// kucoin.ApiBaseURIOption("https://openapi-v2.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://openapi-v2.kucoin.com
// export API_KEY=key
// export API_SECRET=secret
// export API_PASSPHRASE=passphrase
// s := NewApiServiceFromEnv()

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
}

ch := kucoin.NewSubscribeMessage("/market/ticker:KCS-BTC", false, true)

c := s.NewWebSocketClient(tk, ch)

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

mc, ec := c.Subscribe()

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.TickerModel{}
        if err := msg.ReadData(t); err != nil {
            log.Printf("Failure to read: %s", err.Error())
            return
        }
        log.Printf("Ticker: %s, %s, %s", t.Sequence, t.Price, t.Size)
        i++
        if i == 3 {
            log.Println("Exit subscription")
            c.Stop() // Stop subscribing the WebSocket feed
            return
        }
    }
}

API list

Account
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.AccountLedgers() YES https://docs.kucoin.com/#get-account-ledgers
ApiService.AccountHolds() YES https://docs.kucoin.com/#get-holds
ApiService.InnerTransfer() YES https://docs.kucoin.com/#inner-transfer
Deposit
API Authentication Description
ApiService.CreateDepositAddress() YES https://docs.kucoin.com/#create-deposit-address
ApiService.DepositAddresses() YES https://docs.kucoin.com/#get-deposit-address
ApiService.Deposits() YES https://docs.kucoin.com/#get-deposit-list
Fill
API Authentication Description
ApiService.Fills() YES https://docs.kucoin.com/#list-fills
ApiService.RecentFills() YES https://docs.kucoin.com/#recent-fills
Order
API Authentication Description
ApiService.CreateOrder() YES https://docs.kucoin.com/#place-a-new-order
ApiService.CancelOrder() YES https://docs.kucoin.com/#cancel-an-order
ApiService.CancelOrders() YES https://docs.kucoin.com/#cancel-all-orders
ApiService.Orders() YES https://docs.kucoin.com/#list-orders
ApiService.Order() YES https://docs.kucoin.com/#get-an-order
ApiService.RecentOrders() YES https://docs.kucoin.com/#recent-orders
WebSocket Feed
API Authentication Description
ApiService.WebSocketPublicToken() NO https://docs.kucoin.com/#apply-connect-token
ApiService.WebSocketPrivateToken() YES https://docs.kucoin.com/#apply-connect-token
ApiService.NewWebSocketClient() - https://docs.kucoin.com/#websocket-feed
Withdrawal
API Authentication Description
ApiService.WithdrawalQuotas() YES https://docs.kucoin.com/#get-withdrawal-quotas
ApiService.Withdrawals() YES https://docs.kucoin.com/#get-withdrawals-list
ApiService.ApplyWithdrawal() YES https://docs.kucoin.com/#apply-withdraw
ApiService.CancelWithdrawal() YES https://docs.kucoin.com/#cancel-withdrawal
Currency
API Authentication Description
ApiService.Currencies() NO https://docs.kucoin.com/#get-currencies
ApiService.Currency() NO https://docs.kucoin.com/#get-currency-detail
ApiService.Prices() NO https://docs.kucoin.com/#get-fiat-price
Symbol
API Authentication Description
ApiService.Symbols() NO https://docs.kucoin.com/#get-symbols-list
ApiService.TickerLevel1() NO https://docs.kucoin.com/#get-ticker
ApiService.Tickers() NO https://docs.kucoin.com/#get-all-tickers
ApiService.AggregatedPartOrderBook() NO https://docs.kucoin.com/#get-part-order-book-aggregated
ApiService.AggregatedFullOrderBook() NO https://docs.kucoin.com/#get-full-order-book-aggregated
ApiService.AtomicFullOrderBook() NO https://docs.kucoin.com/#get-full-order-book-atomic
ApiService.TradeHistories() NO https://docs.kucoin.com/#get-trade-histories
ApiService.KLines() NO https://docs.kucoin.com/#get-klines
ApiService.Stats24hr() NO https://docs.kucoin.com/#get-24hr-stats
ApiService.Markets() NO https://docs.kucoin.com/#get-market-list
Time
API Authentication Description
ApiService.ServerTime() NO https://docs.kucoin.com/#server-time

Run tests

# Add your API configuration items into the environmental variable first
export API_BASE_URI=https://openapi-v2.kucoin.com
export API_KEY=key
export API_SECRET=secret
export API_PASSPHRASE=passphrase

# Run tests
go test -v

License

MIT

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.