Skip to content

coinbase-samples/intx-sdk-go

Repository files navigation

Coinbase International Exchange (INTX) Go SDK

GoDoc Go Report Card

Overview

The INTX Go SDK is a sample library that demonstrates the structure of a Coinbase International Exchange (INTX) driver for the REST APIs.

License

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

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

httpClient, err := client.DefaultHttpClient()
if err != nil {
    log.Fatalf("unable to create the 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": "",
  "passphrase": "",
  "signingKey": "",
  "portfolioId": "",
}

Coinbase INTX API credentials can be created in the INTX web console under API on the left-hand panel.

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

portfoliosSvc := portfolios.NewPortfoliosService(restClient)
response, err := portfoliosSvc.ListPortfolios(ctx, &portfolios.ListPortfoliosRequest{})

Build

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

go build ./...