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 @coinbase-sample/advanced-trade-sdk-ts
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 { CoinbaseAdvTradeClient } from '@coinbase-samples/advanced-trade-sdk-ts';
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);
Here are a few examples requests:
const accountService = new AccountsService(client);
accountService
.listAccounts({})
.then((result) => {
console.log(result);
})
.catch((error) => {
console.error(error.message);
});
productService = new ProductsService(client);
productService
.getProduct({productId: "BTC-USD"})
.then((result) => {
console.log(result);
})
.catch((error) => {
console.error(error.message);
});
$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);
});