Welcome to the Coinbase Advanced API TypeScript SDK. This TypeScript project was created to allow developers to easily plug into the Coinbase Advanced API.
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.
npm install
To build the project, run the following command:
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:
node dist/main.js
This SDK uses Cloud Developer Platform (CDP) API keys. To use this SDK, you will need to create a CDP API key and secret by following the instructions here. Make sure to save your API key and secret in a safe place. You will not be able to retrieve your secret again.
All the REST endpoints are available directly from the client, therefore it's all you need to import.
import { RESTClient } from './rest';
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 client = new RESTClient(API_KEY, API_SECRET);
Here are a few examples requests:
client
.listAccounts({})
.then((result) => {
console.log(result);
})
.catch((error) => {
console.error(error.message);
});
client
.getProduct({productId: "BTC-USD"})
.then((result) => {
console.log(result);
})
.catch((error) => {
console.error(error.message);
});
$10 Market Buy on BTC-USD
client
.createOrder({
clientOrderId: "00000001",
productId: "BTC-USD",
side: OrderSide.BUY,
orderConfiguration:{
market_market_ioc: {
quote_size: "10"
}
}
})
.then((result) => {
console.log(result);
})
.catch((error) => {
console.error(error.message);
});