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.
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.
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("ADV_CREDENTIALS")), credentials); err != nil {
return nil, fmt.Errorf("unable to deserialize advanced trade credentials JSON: %w", err)
}
httpClient, err := client.DefaultHttpClient()
if err != nil {
panic(fmt.Sprintf("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.
service := portfolios.NewPortfoliosService(restClient)
response, err := service.ListPortfolios(ctx, &portfolios.ListPortfoliosRequest{})
To build the sample library, ensure that Go 1.19+ is installed and then run:
go build ./...