The Coinbase Prime .NET SDK is a sample library that demonstrates the structure of a Coinbase Prime driver for the REST APIs.
The Coinbase Prime .NET 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.
The Coinbase Prime .NET SDK is vended through NuGet and available for installation via the dotnet
CLI.
dotnet add package CoinbaseSdk.Prime --version x.y.z
or if using paket:
paket add CoinbaseSdk.Prime --version x.y.z
To use the Coinbase Prime .NET SDK, initialize the Credentials class and create a new client. The Credentials struct is JSON enabled. Ensure that Prime API credentials are stored in a secure manner.
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 portfolio = portfoliosService.GetPortfolioById(
new GetPortfolioByIdRequest(portfolioId)).Portfolio!;
Console.WriteLine($"Portfolio: {serializer.Serialize(portfolio)}");
}
}
}
The JSON format expected for COINBASE_PRIME_CREDENTIALS
is:
{
"accessKey": "",
"passphrase": "",
"signingKey": ""
}
For an example of how to use the client, see the Example
file. To execute the example, run the following command:
dotnet run --project src/CoinbaseSdk.PrimeExample/CoinbaseSdk.PrimeExample.csproj
Warning: this does place a limit order for a very small amount of ADA. Please ensure that you have the necessary funds in your account before running this code. The example code should cancel the order, however if something breaks you may need to go manually cancel the order.