SkillAgentSearch skills...

Coinbase.Pro

:chart_with_upwards_trend: A .NET/C# implementation of the Coinbase Pro API.

Install / Use

/learn @bchavez/Coinbase.Pro

README

Build status Nuget Users <img src="https://raw.githubusercontent.com/bchavez/Coinbase.Pro/master/Docs/coinbase_pro.png" align='right' />

Coinbase.Pro for .NET/C# Library

Project Description

A .NET implementation for the Coinbase Pro API.

:loudspeaker: HEY! Be sure to checkout these other Coinbase API integrations:

  • Coinbase - For Coinbase wallet account integration.
  • Coinbase.Commerce - For e-commerce, merchants, and websites selling products or services looking to receive cryptocurrency as payment.

Minimum Requirements

  • .NET Standard 2.0 or later
  • .NET Framework 4.6.1 or later
  • TLS 1.2 or later

Note: If you are using .NET Framework 4.6.1 you will need to ensure your application is using TLS 1.2 or later. This can be configured via the registry (link 1, link 2) or configured at application startup by setting the following value in ServicePointManager:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

Crypto Tip Jar

<a href="https://commerce.coinbase.com/checkout/f1f0e303-cb53-4415-b720-4af1df473647"><img src="https://raw.githubusercontent.com/bchavez/Coinbase.Pro/master/Docs/tipjar.png" /></a>

Download & Install

Nuget Package Coinbase.Pro

Install-Package Coinbase.Pro

Getting Started

To get started, simply create a new CoinbaseProClient object as shown below:

<!-- snippet: CoinbaseProClient -->

<a id='snippet-coinbaseproclient'></a>

var client = new CoinbaseProClient(new Config
   {
      ApiKey = "my-api-key",
      Secret = "my-api-secret",
      Passphrase = "my-api-passphrase",
      //Override the ApiUrl property to use Sandbox.
      //ApiUrl = "https://api-public.sandbox.pro.coinbase.com"
   });

<sup><a href='/Source/Coinbase.Tests/Snippets/CoinbaseProClientSnippets.cs#L11-L22' title='Snippet source file'>snippet source</a> | <a href='#snippet-coinbaseproclient' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

By default, the ApiUrl property is set to use production. If you want to use the sandbox, set the ApiUrl property to https://api-public.sandbox.pro.coinbase.com as described in the documentation here. Setting the ApiUrl property will override the production REST API URL that is set by default.

Once you have a CoinbaseProClient object, you can call any one of the many API endpoints listed here. Extensive examples can be found here. For your reference, a link to the Coinbase Pro developer documentation can be found here.

As an example, to create a limit order on the buy side of the ETH-USD order book for 2 ETH at 100 USD each, do the following:

<!-- snippet: createOrder -->

<a id='snippet-createorder'></a>

var order = await client.Orders.PlaceLimitOrderAsync(
   OrderSide.Buy, "ETH-USD", size: 2, limitPrice: 100m);

order.Dump();

<sup><a href='/Source/Coinbase.Tests/Snippets/CoinbaseProClientSnippets.cs#L27-L34' title='Snippet source file'>snippet source</a> | <a href='#snippet-createorder' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

The order object returned by the trading engine will have similar values to the following JSON object:

{
  "id": "ba3d3318-d1f0-4f9d-ae6f-1bda6ff370fa",
  "price": 100.00000000,
  "size": 2.00000000,
  "product_id": "ETH-USD",
  "side": "buy",
  "stp": "dc",
  "type": "limit",
  "time_in_force": "GTC",
  "post_only": true,
  "created_at": "2018-11-30T05:11:54.000355+00:00",
  "fill_fees": 0.0000000000000000,
  "filled_size": 0.00000000,
  "executed_value": 0.0000000000000000,
  "status": "pending",
  "settled": false,
  "funds": 0.0,
  "specified_funds": 0.0
}

Full API Support

Private Endpoints
Market Data Endpoints
WebSocket Feed

Error Handling

When errors occur after calling an API, Coinbase Pro delivers error messages in the response body of a failed HTTP call. First wrap your call in a try/catch statement and handle the Exception ex. Next, get the error message of a failed API call by calling GetErrorMessageAsync() extension method on the exception. The GetErrorMessageAsync() extension method will read the response body of the failed HTTP call as shown below:

<!-- snippet: ErrorHandling -->

<a id='snippet-errorhandling'></a>

try
{
   var order = await client.Orders.PlaceLimitOrderAsync(
      OrderSide.Buy, "BTCX-USDX", size: 1, limitPrice: 5000m);
}
catch( Exception ex )
{
   var errorMsg = await ex.GetErrorMessageAsync();
   Console.WriteLine(errorMsg);
}
//OUTPUT: "Product not found"

<sup><a href='/Source/Coinbase.Tests/Snippets/CoinbaseProClientSnippets.cs#L39-L53' title='Snippet source file'>snippet source</a> | <a href='#snippet-errorhandling' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

Pagination

Some Coinbase Pro APIs are paginable. However, Coinbase Pro's paging can be a little confusing at first. So, let's review. Consider the following diagram below that illustrates the Current Point In Time over a paginable set of data with an item size of 5 items per page:

    Five Items Per Page (limit=5)
     
Past                         Future
Older                         Newer
11   15 16   20     21   25 26   30
[items] [items]     [items] [items]
              ^
      After <-|-> Before
              ^
              |
    Current Point In Time

Suppose you grabbed the most recent trades from var trades = client.MarketData.GetTradesAsync("ETH-USD", limit: 5). The data you captured in trades is the Current Point In Time with the most recent trade 20 as shown in the diagram above.

  • To enumerate older trades beyond the initial page:
<!-- snippet: EnumerateOlder -->

<a id='snippet-enumerateolder'></a>

//Get the initial page, items 16 through 20
var trades = await client.MarketData.GetTradesAsync("ETC-USD", limit: 5);

//Get the next batch of older trades after the current page.
while( trades.After is not null )
{
   trades = await client.MarketData.GetTradesAsync("ETC-USD", limit: 5, after: trades.After);
}

<sup><a href='/Source/Coinbase.Tests/Snippets/CoinbaseProClientSnippets.cs#L58-L67' title='Snippet source file'>snippet source</a> | <a href='#snippet-enumerateolder' title='Start of snippet'>anchor</a></sup>

<!-- endSnippet -->

Now suppose time advances, more trades happen in the market. Given the Current Point In Time with the initial page of items 16-20.

  • To en
View on GitHub
GitHub Stars70
CategoryDevelopment
Updated1mo ago
Forks27

Languages

C#

Security Score

85/100

Audited on Jan 26, 2026

No findings