Coinbase Advanced Trade API
Coinbase Advanced Trade WebSocket and REST client — public market data plus authenticated trading on Coinbase Exchange.
Coinbase Advanced Trade WebSocket and REST client — public market data plus authenticated trading on Coinbase Exchange.
The WebSocket feed is publicly available and provides real-time market data updates for orders and trades. Two endpoints are supported in production:
TsgcWSAPI_Coinbase| Standards & specs | Coinbase Advanced Trade API |
| Component class | TsgcWSAPI_Coinbase (unit sgcWebSocket_API_Coinbase) |
| Frameworks | VCL, FireMonkey, Lazarus / FPC, .NET |
| Platforms | Windows, macOS, Linux, iOS, Android |
The principal published / public properties used to configure and drive the component. Consult the online help for the full list.
Client | Published or public property used to configure or query the component. |
OnCoinbaseSubscriptions | Published or public property used to configure or query the component. |
OnCoinbaseHeartbeats | Published or public property used to configure or query the component. |
OnConnect | Published or public property used to configure or query the component. |
OnCoinbaseMessage | Published or public property used to configure or query the component. |
OnCoinbaseError | Published or public property used to configure or query the component. |
OnCoinbaseHTTPException | Published or public property used to configure or query the component. |
OnDisconnect | Published or public property used to configure or query the component. |
Coinbase | Published or public property used to configure or query the component. |
RawMessages | Published or public property used to configure or query the component. |
The principal public methods exposed by the component.
SubscribeMarketTrades() | Public procedure exposed by the component. |
UnSubscribeMarketTrades() | Public procedure exposed by the component. |
SubscribeTickerBatch() | Public procedure exposed by the component. |
UnSubscribeTickerBatch() | Public procedure exposed by the component. |
SubscribeHeartBeat() | Public procedure exposed by the component. |
UnSubscribeHeartBeat() | Public procedure exposed by the component. |
SubscribeStatus() | Public procedure exposed by the component. |
UnSubscribeStatus() | Public procedure exposed by the component. |
SubscribeCandles() | Public procedure exposed by the component. |
UnSubscribeCandles() | Public procedure exposed by the component. |
Drop the component on a form, configure the properties below and activate it. The snippet that follows shows the typical Coinbase | Connect WebSocket API configuration sourced from the online help.
oClient := TsgcWebSocketClient.Create(nil); oCoinbase := TsgcWSAPI_Coinbase.Create(nil); oCoinbase.Client := oClient; oClient.Active := True;
TsgcWebSocketClient oClient = new TsgcWebSocketClient(); TsgcWSAPI_Coinbase oCoinbase = new TsgcWSAPI_Coinbase(); oCoinbase->Client = oClient; oClient->Active = true;
TsgcWebSocketClient oClient = new TsgcWebSocketClient(); TsgcWSAPI_Coinbase oCoinbase = new TsgcWSAPI_Coinbase(); oCoinbase.Client = oClient; oClient.Active = true;
The following scenarios are lifted verbatim from the online help. Each shows the configuration and method calls needed to drive the component through a specific real-world flow.
Coinbase offers a variety of channels where you can subscribe to get real-time updates of market data, orders... Find below a sample of how subscribe to a Ticker:
oClient := TsgcWebSocketClient.Create(nil); oCoinbase := TsgcWSAPI_Coinbase.Create(nil); oCoinbase.Client := oClient; oCoinbase.SubscribeTicker('ETH-USD'); procedure OnCoinbaseMessage(Sender: TObject; aType, aRawMessage: string); begin // here you will receive the ticker updates end;
TsgcWebSocketClient oClient = new TsgcWebSocketClient(); TsgcWSAPI_Coinbase oCoinbase = new TsgcWSAPI_Coinbase(); oCoinbase->Client = oClient; oCoinbase->SubscribeTicker("ETH-USD"); void OnCoinbaseMessage(TObject *Sender, string aType, string aRawMessage) { // here you will receive the ticker updates }
TsgcWebSocketClient oClient = new TsgcWebSocketClient(); TsgcWSAPI_Coinbase oCoinbase = new TsgcWSAPI_Coinbase(); oCoinbase.Client = oClient; oCoinbase.SubscribeTicker("ETH-USD"); void OnCoinbaseMessage(TObject Sender, string aType, string aRawMessage) { // here you will receive the ticker updates }
Coinbase allows you to use a SandBox account where you can trade without real funds. This account requires creating API keys different from the production account.
oCoinbase := TsgcWSAPI_Coinbase.Create(nil); oCoinbase.Coinbase.ApiKey := 'your api key'; oCoinbase.Coinbase.ApiSecret := 'your api secret'; oCoinbase.Coinbase.SandBox := True; ShowMessage(oCoinbase.REST_API.ListAccounts);
TsgcWSAPI_Coinbase oCoinbase = new TsgcWSAPI_Coinbase(this); oCoinbase->Coinbase->ApiKey = "your api key"; oCoinbase->Coinbase->ApiSecret = "your api secret"; oCoinbase->Coinbase->SandBox = true; ShowMessage(oCoinbase->REST_API>ListAccounts);
TsgcWSAPI_Coinbase oCoinbase = new TsgcWSAPI_Coinbase(); oCoinbase.Coinbase.ApiKey = "your api key"; oCoinbase.Coinbase.ApiSecret = "your api secret"; oCoinbase.Coinbase.SandBox = true; MessageBox.Show(oCoinbase.REST_API.ListAccounts);
Coinbase offers public Market Data through REST Endpoints, when you call one of these endpoints, you will get a snapshot of the market data requested.
oCoinbase := TsgcWSAPI_Coinbase.Create(nil); ShowMessage(oCoinbase.REST_API.GetPublicProductBook('BTC-USD'));
TsgcWSAPI_Coinbase oCoinbase = new TsgcWSAPI_Coinbase(this); ShowMessage(oCoinbase->REST_API->GetPublicProductBook("BTC-USD"));
TsgcWSAPI_Coinbase oCoinbase = new TsgcWSAPI_Coinbase(); MessageBox.Show(oCoinbase.REST_API.GetPublicProductBook("BTC-USD"));
In order to place new orders in Coinbase, you first need your API keys to access your private data. Check the following article: How to Use Private REST API.
oCoinbase := TsgcWSAPI_Coinbase.Create(nil); oCoinbase.Coinbase.ApiKey := 'your api key'; oCoinbase.Coinbase.ApiSecret := 'your api secret'; oCoinbase.Coinbase.ApiPassphrase := 'your passphrase'; ShowMessage(oCoinbase.REST_API.PlaceMarketOrder(coisBuy, 'BTC-USD', 0.002, 0));
TsgcWSAPI_Coinbase oCoinbase = new TsgcWSAPI_Coinbase(this); oCoinbase->Coinbase->ApiKey = "your api key"; oCoinbase->Coinbase->ApiSecret = "your api secret"; oCoinbase->Coinbase->ApiPassphrase = "your passphrase"; ShowMessage(oCoinbase->REST_API>PlaceMarketOrder(coisBuy, "BTC-USD", 0.002</code><code class="delphi">, 0</code><code class="cpp">));
TsgcWSAPI_Coinbase oCoinbase = new TsgcWSAPI_Coinbase(); oCoinbase.Coinbase.ApiKey = "your api key"; oCoinbase.Coinbase.ApiSecret = "your api secret"; oCoinbase.Coinbase.ApiPassphrase = "your passphrase"; MessageBox.Show(oCoinbase.REST_API.PlaceMarketOrder(coisBuy, "BTC-USD", 0.002</code><code class="delphi">, 0</code><code class="csharp">));
The Coinbase REST API offers public and private endpoints. The Private endpoints require that messages are signed to increase the security of transactions.
oCoinbase := TsgcWSAPI_Coinbase.Create(nil); oCoinbase.Coinbase.ApiKey := '<your api key>'; oCoinbase.Coinbase.ApiSecret := '<your api secret>'; ShowMessage(oCoinbase.REST_API.ListAccounts);
TsgcWSAPI_Coinbase oCoinbase = new TsgcWSAPI_Coinbase(this); oCoinbase->Coinbase->ApiKey = "<your api key>"; oCoinbase->Coinbase->ApiSecret = "<your api secret>"; ShowMessage(oCoinbase->REST_API->ListAccounts);
TsgcWSAPI_Coinbase oCoinbase = new TsgcWSAPI_Coinbase(); oCoinbase.Coinbase.ApiKey = "<your api key>"; oCoinbase.Coinbase.ApiSecret = "<your api secret>"; MessageBox.Show(oCoinbase.REST_API.ListAccounts);
Every external claim links back to a primary source. The online-help references decode the canonical deep-link the company maintains for this component.
Demos\05.Crypto\09.Coinbase
.net\demos\05.Crypto\09.Coinbase