Go
This guide explains how to set up a development environment for calling the Upbit API using the Upbit SDK in a Go environment.
Get Started
The Upbit Go SDK is an official library that enables the use of the Upbit REST API in Go applications.
It provides type definitions for request parameters and response fields, allowing you to handle authentication setup, request construction, and response processing required for API calls in a consistent manner within Go code.
Upbit SDK Documentation
You can find documentation for the Upbit Go SDK below:
- Getting Started Guide — Installation and basic usage of the Upbit Go SDK
- Upbit SDK API Reference — Full list of APIs supported by the SDK
- SDK Example Code — Sample Code and Detailed Usage
Prerequisites
To use the Upbit Go SDK, you need the following:
- Go 1.25 or higher
- Upbit Open API Key
- An Access Key and Secret Key (required for calling authenticated APIs)
Verify Go Installation
Run the following command in your terminal to check if Go is installed.
go versionIf Go is not installed or the version is outdated, refer to the official Go documentation for installation instructions.
https://go.dev/doc/install
Create a Project
Create a project directory and initialize a Go module.
mkdir <project-name>
cd <project-name>
go mod init <module-path>Example:
mkdir upbit-go-example
cd upbit-go-example
go mod init github.com/username/upbit-go-exampleInstall the SDK
Install the Upbit Go SDK.
go get github.com/upbit-official/upbit-sdk-goTo install a specific version, use the following command.
go get github.com/upbit-official/[email protected]Configure Authentication
To use APIs that require authentication, set your API Key as an environment variable.
macOS / Linux
export UPBIT_ACCESS_KEY=<your-access-key>
export UPBIT_SECRET_KEY=<your-secret-key>
Windows PowerShell
$env:UPBIT_ACCESS_KEY="your-access-key"
$env:UPBIT_SECRET_KEY="your-secret-key"
Windows CMD
set UPBIT_ACCESS_KEY=your-access-key
set UPBIT_SECRET_KEY=your-secret-key
Basic Usage Example
The following example demonstrates how to retrieve account information using the Upbit Go SDK.
■ Supported Environments
- Singapore (SG):
WithEnvironmentSg() - Indonesia (ID):
WithEnvironmentId() - Thailand (TH):
WithEnvironmentTh()
package main
import (
"context"
"fmt"
"os"
"github.com/upbit-official/upbit-sdk-go"
"github.com/upbit-official/upbit-sdk-go/option"
)
func main() {
client := upbit.NewClient(
option.WithAccessKey(os.Getenv("UPBIT_ACCESS_KEY")),
option.WithSecretKey(os.Getenv("UPBIT_SECRET_KEY")),
// option.WithEnvironmentSg() | WithEnvironmentId() | WithEnvironmentTh();
)
accounts, err := client.Accounts.List(context.TODO())
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", accounts)
}
Save the code as main.goand run it.
go run main.go
If executed successfully, your account information will be displayed.
Run Example Code
The Upbit Go SDK provides example code organized by common use cases.
Each example is an independently executable package main program and can be run as follows.
go run examples/<file>.go
Examples Without Authentication
The following examples can be executed without an API Key.
| Examples | Description |
|---|---|
quotation.go | Market Data: Ticker, Candles, Trades, and Order Book |
indicators.go | Calculating Indicators Using Quotation Data |
go run examples/quotation.go
go run examples/indicators.go
Examples Requiring Authentication
The following examples require an Upbit API Key.
| Examples | Description |
|---|---|
orders.go | Order creation, retrieval, and cancellation flow |
orders_validate.go | Order type validation using the test order API |
deposits.go | Deposit address and deposit history management |
withdrawals.go | Withdrawal availability and withdrawal flow |
dca.go | Periodic market buy (DCA) example |
tp_sl.go | Take-profit / stop-loss automated sell example |
UPBIT_ACCESS_KEY=<key>
UPBIT_SECRET_KEY=<secret>
go run examples/orders.go
Dry run Mode
Some examples run in dry run mode by default.
In dry run mode, operations are limited to read-only actions, and write operations such as placing orders or withdrawals are not executed.
If you want to perform actual operations, set DRY_RUN=false.
DRY_RUN=false UPBIT_ACCESS_KEY=<key>
UPBIT_SECRET_KEY=<secret>
go run examples/orders.go
Since real execution may result in asset changes (e.g., orders or withdrawals), be sure to review the details carefully before running.
Key Features
The Upbit Go SDK provides the following features:
- Market Data (Quotation) API
- Account and asset inquiries
- Order creation, retrieval, and cancellation
- Deposit address and deposit history inquiries
- Withdrawal availability and withdrawal history inquiries
- Paginated list retrieval Request option configuration
- Error handling and debugging
Advanced Features
The following features are available as needed.
Pagination
For list retrieval APIs, automatic page iteration is supported.
iter := client.Orders.ListOpenAutoPaging(context.TODO(), upbit.OrderListOpenParams{})
for iter.Next() {
order := iter.Current()
fmt.Printf("%+v\n", order)
}
if err := iter.Err(); err != nil {
panic(err.Error())
}
Request Options
You can configure headers, timeouts, retry settings, and more for each request.
client.Accounts.List(
context.TODO(),
option.WithRequestTimeout(20*time.Second),
)
Error Handling
If an error occurs during an API call, you can inspect the status code and response details using the upbit.Error type.
accounts, err := client.Accounts.List(context.TODO())
if err != nil {
var apierr *upbit.Error
if errors.As(err, &apierr) {
fmt.Println(apierr.StatusCode)
}
panic(err.Error())
}
fmt.Printf("%+v\n", accounts)
Access to Raw Response Data
You can use this when you need raw HTTP response information such as headers or status codes.
var response *http.Response
accounts, err := client.Accounts.List(
context.TODO(),
option.WithResponseInto(&response),
)
if err != nil {
panic(err.Error())
}
fmt.Println(response.StatusCode)
fmt.Printf("%+v\n", accounts)Updated 2 days ago
