coinbase-samples / prime-sdk-go

Sample Go SDK for the Coinbase Prime REST APIs

Home Page:https://docs.cdp.coinbase.com/prime/docs/rest-requests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Prime Go SDK README

GoDoc Go Report Card

Overview

The Prime Go SDK is a sample libary that demonstrates the structure of a Coinbase Prime driver for the REST APIs.

License

The Prime 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 Prime Go SDK, initialize the Credentials struct and create a new client. The Credentials struct is JSON enabled. Ensure that Prime API credentials are stored in a secure manner.

credentials := &prime.Credentials{}
if err := json.Unmarshal([]byte(os.Getenv("PRIME_CREDENTIALS")), credentials); err != nil {
    return nil, fmt.Errorf("unable to deserialize prime credentials JSON: %w", err)
}

client := prime.NewClient(credentials, http.Client{})

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

{
  "accessKey": "",
  "passphrase": "",
  "signingKey": "",
  "portfolioId": "",
  "svcAccountId": "",
  "entityId": ""
}

Coinbase Prime API credentials can be created in the Prime web console under Settings -> APIs. Entity ID can be retrieved by calling Get Portfolio.

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, &prime.ListPortfoliosRequest{})

Build

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

go build *.go

About

Sample Go SDK for the Coinbase Prime REST APIs

https://docs.cdp.coinbase.com/prime/docs/rest-requests

License:Apache License 2.0


Languages

Language:Go 100.0%