Socket
Book a DemoInstallSign in
Socket

@coinbase-sample/advanced-trade-sdk-ts

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coinbase-sample/advanced-trade-sdk-ts

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).

latest
npmnpm
Version
0.2.0
Version published
Weekly downloads
492
140%
Maintainers
1
Weekly downloads
 
Created
Source

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.

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.

Installation

npm install @coinbase-samples/advanced-trade-sdk-ts

Build and Use

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

Coinbase Developer Platform (CDP) API Keys

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.

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

const accountService = new AccountsService(client);
accountService
    .listAccounts({})
    .then((result) => {
        console.log(result);
    })
    .catch((error) => {
        console.error(error.message);
    });

Get Product

productService = new ProductsService(client);
productService
    .getProduct({productId: "BTC-USD"})
    .then((result) => {
        console.log(result);
    })
    .catch((error) => {
        console.error(error.message);
    });

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);
    });

FAQs

Package last updated on 29 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts