The following code snippet demonstrates how to initialize the Prime client:
Copy
Ask AI
namespace CoinbaseSdk.PrimeExample.Example{ using CoinbaseSdk.Core.Credentials; using CoinbaseSdk.Core.Serialization; using CoinbaseSdk.Prime.Client; class Example { static void Main() { string? credentialsBlob = Environment.GetEnvironmentVariable("COINBASE_PRIME_CREDENTIALS"); if (credentialsBlob == null) { Console.WriteLine("COINBASE_PRIME_CREDENTIALS environment variable not set"); return; } var serializer = new JsonUtility(); var credentials = serializer.Deserialize<CoinbaseCredentials>(credentialsBlob); if (credentials == null) { Console.WriteLine("Failed to parse COINBASE_PRIME_CREDENTIALS environment variable"); return; } var client = new CoinbasePrimeClient(credentials!); } }}
Update the code snippet with the service invocation and call to make your first API call with Prime to List Portfolios.
Copy
Ask AI
namespace CoinbaseSdk.PrimeExample.Example{ using CoinbaseSdk.Core.Credentials; using CoinbaseSdk.Core.Serialization; using CoinbaseSdk.Prime.Client; using CoinbaseSdk.Prime.Model; using CoinbaseSdk.Prime.Orders; using CoinbaseSdk.Prime.Portfolios; class Example { static void Main() { string? credentialsBlob = Environment.GetEnvironmentVariable("COINBASE_PRIME_CREDENTIALS"); if (credentialsBlob == null) { Console.WriteLine("COINBASE_PRIME_CREDENTIALS environment variable not set"); return; } string? portfolioId = Environment.GetEnvironmentVariable("COINBASE_PRIME_PORTFOLIO_ID"); if (portfolioId == null) { Console.WriteLine("COINBASE_PRIME_PORTFOLIO_ID environment variable not set"); return; } var serializer = new JsonUtility(); var credentials = serializer.Deserialize<CoinbaseCredentials>(credentialsBlob); if (credentials == null) { Console.WriteLine("Failed to parse COINBASE_PRIME_CREDENTIALS environment variable"); return; } var client = new CoinbasePrimeClient(credentials!); var portfoliosService = new PortfoliosService(client); var listPortfoliosResponse = portfoliosService.ListPortfolios(); Console.WriteLine($"Portfolio: {serializer.Serialize(portfolio)}"); } }}
Initialize a new Go module and tidy dependencies. Run the following commands in your project directory, replacing example.com/test with a proper project directory:
Copy
Ask AI
go mod init example.com/testgo mod tidygo build
Install the Golang SDK:
Copy
Ask AI
go get github.com/coinbase-samples/prime-sdk-go
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.
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 for running this SDK is:
These should be stored in ~/.zshrc or ~/.bashrc. You may proceed initially without knowing your Portfolio ID or Entity ID. The SDK will return these values in the response when you make your first API call below.