https://github.com/coinbase-samples/advanced-sdk-ts
Sample TypeScript SDK for the Coinbase Advanced APIs
https://github.com/coinbase-samples/advanced-sdk-ts
Last synced: 5 months ago
JSON representation
Sample TypeScript SDK for the Coinbase Advanced APIs
- Host: GitHub
- URL: https://github.com/coinbase-samples/advanced-sdk-ts
- Owner: coinbase-samples
- Created: 2024-07-22T22:45:30.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-23T14:40:12.000Z (about 1 year ago)
- Last Synced: 2025-04-23T15:46:56.086Z (about 1 year ago)
- Language: TypeScript
- Homepage: https://docs.cdp.coinbase.com/advanced-trade/docs/welcome
- Size: 291 KB
- Stars: 32
- Watchers: 5
- Forks: 16
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Coinbase Advanced API TypeScript SDK
Welcome to the Coinbase Advanced API TypeScript SDK. This TypeScript project was created to allow developers to easily plug into the [Coinbase Advanced API](https://docs.cdp.coinbase.com/advanced-trade/docs/welcome).
Coinbase Advanced Trade offers a comprehensive API for traders, providing access to real-time market data, order management, and execution. Elevate your trading strategies and develop sophisticated solutions using our powerful tools and features.
For more information on all the available REST endpoints, see the [API Reference](https://docs.cdp.coinbase.com/api-reference/advanced-trade-api/rest-api/introduction).
---
## Installation
```bash
npm install @coinbase-sample/advanced-trade-sdk-ts
```
---
## Build and Use
To build the project, run the following command:
```bash
npm run build
```
_Note: To avoid potential issues, do not forget to build your project again after making any changes to it._
After building the project, each `.ts` file will have its `.js` counterpart generated.
To run a file, use the following command:
```
node dist/{INSERT-FILENAME}.js
```
For example, a `main.ts` file would be run like:
```bash
node dist/main.js
```
---
## Coinbase Developer Platform (CDP) API Keys
This SDK uses Coinbase Developer Platform (CDP) API keys. To use this SDK, you will need to create a [CDP API key and secret](https://portal.cdp.coinbase.com/projects/api-keys).
Make sure to save your API key and secret in a safe place. You will not be able to retrieve your secret again.
---
## Importing the RESTClient
All the REST endpoints are available directly from the client, therefore it's all you need to import.
```
import { CoinbaseAdvTradeClient } from '@coinbase-samples/advanced-trade-sdk-ts';
```
---
## Authentication
Authentication of CDP API Keys is handled automatically by the SDK when making a REST request.
After creating your CDP API keys, store them using your desired method and simply pass them into the client during initialization like:
```
const credentials = new CoinbaseAdvTradeCredentials(
process.env.KEY_NAME,
process.env.PRIVATE_KEY
);
const client = new CoinbaseAdvTradeClient(credentials);
```
---
## Making Requests
Here are a few examples requests:
**[List Accounts](https://docs.cdp.coinbase.com/api-reference/advanced-trade-api/rest-api/accounts/list-accounts)**
```
const accountService = new AccountsService(client);
accountService
.listAccounts({})
.then((result) => {
console.log(result);
})
.catch((error) => {
console.error(error.message);
});
```
**[Get Product](https://docs.cdp.coinbase.com/api-reference/advanced-trade-api/rest-api/products/get-product)**
```
productService = new ProductsService(client);
productService
.getProduct({productId: "BTC-USD"})
.then((result) => {
console.log(result);
})
.catch((error) => {
console.error(error.message);
});
```
**[Create Order](https://docs.cdp.coinbase.com/api-reference/advanced-trade-api/rest-api/orders/create-order)**
_$10 Market Buy on BTC-USD_
```
const orderService = new OrdersService(client);
orderService
.createOrder({
clientOrderId: "00000001",
productId: "BTC-USD",
side: OrderSide.BUY,
orderConfiguration:{
marketMarketIoc: {
quoteSize: "10"
}
}
})
.then((result) => {
console.log(result);
})
.catch((error) => {
console.error(error.message);
});
```