The Coinbase .NET Core Library (CoinbaseSdk.Core) is the foundational building block for Coinbase .NET SDKs. It provides a standardized, robust, and thread-safe infrastructure for building API clients, handling authentication, HTTP communication, and serialization.
This library is primarily intended for internal use by Coinbase SDKs but is also available for advanced users building custom integrations requiring a standardized base.
- Base Client Architecture: Abstract
CoinbaseClientmanaging request lifecycles with extensible hooks (BuildRequest,ConfigureRequest,ValidateResponse). - Resilient HTTP Communication: Wrapper around
System.Net.Http.HttpClientwith built-in Polly retry policies for transient failure handling. - Robust Serialization:
JsonUtilitywrapper aroundSystem.Text.Jsonfeaturing:NullOnUnknownEnumConverter: Graceful handling of new/unknown enum members.UtcIso8601DateTimeOffsetConverter: Standardized ISO-8601 date/time processing.- Thread-safe initialization using
Lazy<T>.
- Centralized Configuration:
HttpClientDefaultsandRetryPolicyDefaultsensuring consistent default behavior across SDKs. - Standardized Error Handling: Hierarchy of exceptions (
CoinbaseException,CoinbaseClientException) for uniform error reporting.
The library uses SystemNetHttpClient to execute requests. By default, it performs a single attempt. You can enable retries using CallOptions, which leverages Polly's decorrelated jitter backoff strategy to handle transient failures (like rate limits or 5xx errors) without causing retry storms.
Retries can be configured at two levels:
- Per-Client: Set default behavior for all requests made by a client instance.
- Per-Request: Override behavior for a specific API call.
Per-Request Configuration:
var callOptions = new CallOptions
{
MaxRetries = 2,
ShouldRetryOnStatusCodes = true,
RetryableStatusCodes = new HashSet<HttpStatusCode> { HttpStatusCode.TooManyRequests }
};
// options are passed to the SendRequestAsync method
var response = await client.SendRequestAsync<MyResponse>(..., callOptions);Per-Client Configuration:
var httpClient = new SystemNetHttpClient(
defaultCallOptions: new CallOptions
{
MaxRetries = 3,
ShouldRetryOnStatusCodes = true,
RetryableStatusCodes = new HashSet<HttpStatusCode> { HttpStatusCode.TooManyRequests }
});
var client = new MyCoinbaseClient(credentials, httpClient: httpClient);| Option | Default | Description |
|---|---|---|
MaxRetries |
0 |
Maximum number of retry attempts (0 disables retries). |
MedianFirstRetryDelay |
500ms | Target median delay for the first retry (subject to jitter). |
MaxRetryDelay |
1s | Maximum delay cap for any retry attempt. |
ShouldRetryOnStatusCodes |
false |
Whether to retry on specific HTTP status codes. |
RetryableStatusCodes |
empty | Set of status codes to retry (e.g., 429, 503). |
Note: Retry attempts honor the
CancellationTokenprovided to the request. If canceled, pending retries are aborted.
dotnet add package CoinbaseSdk.CoreThis project is licensed under the Apache License, Version 2.0.