The Advanced Trade Go SDK is a sample library that demonstrates the structure of a Coinbase Advanced Trade driver for the REST APIs.
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 := &adv.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)
}
client := adv.NewClient(credentials, http.Client{})
There are convenience functions to read the credentials as an environment variable (adv.ReadEnvCredentials) and to deserialize the JSON structure (adv.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, make the desired call. For example, to list portfolios, pass in the request object, check for an error, and if nil, process the response.
response, err := client.ListPortfolios(ctx, &adv.ListPortfoliosRequest{})
To build the sample library, ensure that Go 1.19+ is installed and then run:
go build *.go