Coinbase.Net

Coinbase.Net is a client library for accessing the Coinbase Advanced Trade REST and Websocket API and Coinbase App REST API.

Features

  • Response data is mapped to descriptive models
  • Input parameters and response values are mapped to discriptive enum values where possible
  • Automatic websocket (re)connection management
  • Client side rate limiting
  • Cient side order book implementation
  • Extensive logging
  • Support for different environments
  • Easy integration with other exchange client based on the CryptoExchange.Net base library
This library is based on the CryptoExchange.Net base package and can be used in combination with other exchange packages!

Supported Frameworks

The library is targeting both .NET Standard 2.0 and .NET Standard 2.1 for optimal compatibility

.NET implementation Version Support
.NET Core2.0 and higher
.NET Framework4.6.1 and higher
Mono5.4 and higher
Xamarin.iOS10.14 and higher
Xamarin.Android8.0 and higher
UWP10.0.16299 and higher
Unity2018.1 and higher

Discord

A Discord server is available here. Feel free to join for discussion and/or questions around the CryptoExchange.Net and implementation libraries.

Support the project

Donate

Make a one time donation in a crypto currency of your choice. If you prefer to donate a currency not listed here please contact me.

Btc: bc1q277a5n54s2l2mzlu778ef7lpkwhjhyvghuv8qf
Eth: 0xcb1b63aCF9fef2755eBf4a0506250074496Ad5b7
USDT (TRX): TKigKeJPXZYyMVDgMyXxMf17MWYia92Rjd

Sponsor

Alternatively, sponsor me on Github using Github Sponsors.

Any support is greatly appreciated.

Getting Started

The package is available on Nuget. After installing the package the Coinbase API is available by using the CoinbaseRestClient and CoinbaseSocketClient.

More information and usage documentation is available at the CryptoExchange.Net documentation page

Installation

Nuget

dotnet add package Jkorf.Coinbase.Net
GitHub packages

Coinbase.Net is available on GitHub packages. You'll need to add https://nuget.pkg.github.com/JKorf/index.json as a NuGet package source.

Download release

The NuGet package files are added along side the source with the latest GitHub release which can found here.


API Access

Coinbase.Net can be configured using Dotnet dependency injection, after which the clients can be injected into your services. It also correctly configures logging and HttpClient usage.

// Configure options from config file
// see https://github.com/JKorf/CryptoExchange.Net/tree/master/Examples/example-config.json for an example
builder.Services.AddCoinbase(builder.Configuration.GetSection("Coinbase"));
		  
// OR
		  
 builder.Services.AddCoinbase(options => {
  // Configure options in code
  options.ApiCredentials = new ApiCredentials("APIKEY", "APISECRET");
});

The ICoinbaseRestClient and ICoinbaseSocketClient can then be injected.

Alternatively the rest and socket client can be constructed directly

var restClient = new CoinbaseRestClient(options => {
  // Options can be configured here, for example:
  options.ApiCredentials = new ApiCredentials("KEYNAME", "PRIVATEKEY");
});
var socketClient = new CoinbaseSocketClient();

Examples

Get Symbols

Get a list of supported symbols on Coinbase

var coinbaseClient = new CoinbaseRestClient();
await coinbaseClient.AdvancedTradeApi.ExchangeData.GetSymbolsAsync();
Get Recent Trades

Get the most recent trades for a spot symbol

var coinbaseClient = new CoinbaseRestClient();
var result = await coinbaseClient.AdvancedTradeApi.ExchangeData.GetTradeHistoryAsync("ETHUSDT");
Get Balances

Get asset balances of the spot account

var coinbaseClient = new CoinbaseRestClient(options => {
    options.ApiCredentials = new ApiCredentials("KEYNAME", "PRIVATEKEY");
});

var result = await coinbaseClient.AdvancedTradeApi.Account.GetAccountsAsync();
Place Limit Order

Place a new limit order for buying 0.1 ETH at a price of 2000 USDT

var coinbaseClient = new CoinbaseRestClient(options => {
    options.ApiCredentials = new ApiCredentials("KEYNAME", "PRIVATEKEY");
});

var result = await coinbaseClient.AdvancedTradeApi.Trading.PlaceOrderAsync(
    "ETH-USDT",
    OrderSide.Buy,
    NewOrderType.Limit,
    0.1m,
    price: 2000);
Place Market Order

Place a new market order for buying 50 USDT worth of ETH at the best available price

var coinbaseClient = new CoinbaseRestClient(options => {
    options.ApiCredentials = new ApiCredentials("KEYNAME", "PRIVATEKEY");
});

var result = await coinbaseClient.AdvancedTradeApi.Trading.PlaceOrderAsync(
    "ETH-USDT",
    OrderSide.Buy,
    NewOrderType.Market,
    quoteQuantity: 50);
Get Order Info

Retrieve order information for a specific order

var coinbaseClient = new CoinbaseRestClient(options => {
    options.ApiCredentials = new ApiCredentials("KEYNAME", "PRIVATEKEY");
});

var result = await coinbaseClient.AdvancedTradeApi.Trading.GetOrderAsync("123");
Cancel an order

Cancel a currently active order

var coinbaseClient = new CoinbaseRestClient(options => {
    options.ApiCredentials = new ApiCredentials("KEYNAME", "PRIVATEKEY");
});

var result = await coinbaseClient.AdvancedTradeApi.Trading.CancelOrderAsync("123");
Get Expiring Futures Balances

Get balance of the expiring futures account

var coinbaseClient = new CoinbaseRestClient(options => {
    options.ApiCredentials = new ApiCredentials("KEYNAME", "PRIVATEKEY");
});

var result = await coinbaseClient.AdvancedTradeApi.Account.GetFuturesBalanceSummaryAsync();
Get Perpetual Futures Balances

Get balance of the expiring futures account

var coinbaseClient = new CoinbaseRestClient(options => {
    options.ApiCredentials = new ApiCredentials("KEYNAME", "PRIVATEKEY");
});

var result = await coinbaseClient.AdvancedTradeApi.Account.GetPerpetualBalancesAsync("PORTFOLIO_ID");
Get Expiring Futures Positions

Get open positions

var coinbaseClient = new CoinbaseRestClient(options => {
    options.ApiCredentials = new ApiCredentials("KEYNAME", "PRIVATEKEY");
});

var result = await binanceClient.AdvancedTradeApi.Trading.GetFuturesPositionsAsync();
Get Perpetual Futures Positions

Get open positions

var coinbaseClient = new CoinbaseRestClient(options => {
    options.ApiCredentials = new ApiCredentials("KEYNAME", "PRIVATEKEY");
});

var result = await binanceClient.AdvancedTradeApi.Trading.GetPerpetualPositionsAsync("PORTFOLIO_ID");
Place Expiring Futures Order

Place a new limit order for expiring futures for going long on 0.1 ETH at a price of 2000 USDT with a leverage of 3x

var coinbaseClient = new CoinbaseRestClient(options => {
    options.ApiCredentials = new ApiCredentials("KEYNAME", "PRIVATEKEY");
});

var result = await coinbaseClient.AdvancedTradeApi.Trading.PlaceOrderAsync(
    "BIT-25OCT24-CDE",
    OrderSide.Buy,
    NewOrderType.Limit,
    0.1m,
    price: 2000,
    leverage: 3
    );
Place Perpetual Futures Order

Place a new limit order for perpetual futures for going short on 0.1 ETH at a price of 2000 USDT with a leverage of 3x

var coinbaseClient = new CoinbaseRestClient(options => {
    options.ApiCredentials = new ApiCredentials("KEYNAME", "PRIVATEKEY");
});

var result = await coinbaseClient.AdvancedTradeApi.Trading.PlaceOrderAsync(
    "ETH-PERP-INTX",
    OrderSide.Sell,
    NewOrderType.Limit,
    0.1m,
    price: 2000,
    leverage: 3
    );