MCPcopy Index your code
hub / github.com/coinbase-samples/advanced-trade-sdk-go

github.com/coinbase-samples/advanced-trade-sdk-go @v0.4.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.4.0 ↗ · + Follow
331 symbols 614 edges 73 files 0 documented · 0% updated 5d agov0.4.0 · 2026-01-22★ 375 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Advanced Trade Go SDK README

GoDoc Go Report Card

Overview

The Advanced Trade Go SDK is a sample library that demonstrates the structure of a Coinbase Advanced Trade driver for the REST APIs.

Coinbase Advanced Trade offers a comprehensive API for traders, providing access to real-time market data, order management, and execution. Elevate your trading strategies and develop sophisticated solutions using our powerful tools and features.

License

The Advanced Trade Go SDK sample library is free and open source and released under the Apache License, Version 2.0.

The application and code are only available for demonstration purposes.

Usage

To use the Advanced Trade Go SDK, initialize the Credentials struct and create a new client. The Credentials struct is JSON enabled. Ensure that Advanced Trade API credentials are stored in a secure manner.

credentials := &credentials.Credentials{}
if err := json.Unmarshal([]byte(os.Getenv("ADVANCED_CREDENTIALS")), credentials); err != nil {
    log.Fatalf("unable to deserialize advanced trade credentials JSON: %v", err)
}

httpClient, err := client.DefaultHttpClient()
if err != nil {
    log.Fatalf("unable to load default http client: %v", err)
}

restClient := client.NewRestClient(credentials, httpClient)

There are convenience functions to read the credentials as an environment variable (credentials.ReadEnvCredentials) and to deserialize the JSON structure (credentials.UnmarshalCredentials) if pulled from a different source. The JSON format expected by both is:

{
  "accessKey": "",
  "privatePemKey": ""
}

Coinbase Advanced Trade API credentials can be created in the CDP web portal.

Once the client is initialized, initialize a service to make the desired call. For example, to list portfolios, create the service, pass in the request object, check for an error, and if nil, process the response.

portfoliosService := portfolios.NewPortfoliosService(restClient)

resp, err := portfoliosService.ListPortfolios(context.Background(), &portfolios.ListPortfoliosRequest{})
if err != nil {
    log.Fatalf("error listing portfolios: %v", err)
}

jsonResponse, err := json.MarshalIndent(resp, "", "  ")
if err != nil {
    panic(fmt.Sprintf("error marshaling response to JSON: %v", err))
}

fmt.Println(string(jsonResponse))

Build

To build the sample library, ensure that Go 1.19+ is installed and then run:

go build ./...

Extension points exported contracts — how you extend this code

PublicService (Interface)
(no doc) [1 implementers]
public/public.go
RestClient (Interface)
(no doc) [1 implementers]
client/rest.go
FeesService (Interface)
(no doc) [1 implementers]
fees/fees.go
AccountsService (Interface)
(no doc) [1 implementers]
accounts/accounts.go
DataApisService (Interface)
(no doc) [1 implementers]
dataapis/dataapis.go
OrdersService (Interface)
(no doc) [1 implementers]
orders/orders.go
PortfoliosService (Interface)
(no doc) [1 implementers]
portfolios/portfolios.go
PaymentMethodsService (Interface)
(no doc) [1 implementers]
paymentmethods/paymentmethods.go

Core symbols most depended-on inside this repo

HeadersFunc
called by 51
client/rest.go
setupClient
called by 4
test/utils.go
AppendPaginationParams
called by 3
utils/pagination.go
NewPortfoliosService
called by 3
portfolios/portfolios.go
Credentials
called by 2
client/rest.go
NewRestClient
called by 2
client/rest.go
DefaultHttpClient
called by 2
client/rest.go
NewOrdersService
called by 2
orders/orders.go

Shape

Struct 191
Method 103
Function 25
Interface 12

Languages

Go100%

Modules by API surface

model/model.go76 symbols
client/rest.go18 symbols
orders/orders.go12 symbols
public/public.go9 symbols
products/products.go9 symbols
portfolios/portfolios.go9 symbols
perpetuals/perpetuals.go7 symbols
converts/converts.go6 symbols
paymentmethods/paymentmethods.go5 symbols
accounts/accounts.go5 symbols
fees/fees.go4 symbols
dataapis/dataapis.go4 symbols

For agents

$ claude mcp add advanced-trade-sdk-go \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page