coinbase-pro-node-api

Node.js library for Coinbase Pro

Usage no npm install needed!

<script type="module">
  import coinbaseProNodeApi from 'https://cdn.skypack.dev/coinbase-pro-node-api';
</script>

README

coinbase-pro-node-api CI Status npm Coverage Status Known Vulnerabilities code style: prettier semantic-release Conventional Commits NPM license node version npm downloads GitHub top language

Node.js library for Coinbase Pro

Installation

npm install coinbase-pro-node-api

Usage

PublicClient

import { PublicClient } from "coinbase-pro-node-api";
const sandbox = true;
const client = new PublicClient({ sandbox });
const products = await client.getProducts();
const product_id = "ETH-BTC";
const product = await client.getProduct({ product_id });
const level = 2;
const book = await client.getOrderBook({ level });
const product_id = "ETH-BTC";
const ticker = await client.getTicker({ product_id });
const product_id = "ETH-BTC";
const limit = 10;
const after = 74;
const trades = await client.getTrades({ product_id, limit, after });
const product_id = "ETH-BTC";
const end = "2019-11-12T16:40:00-0500";
const start = "2019-11-12T16:37:00-0500";
const granularity = 60;
const candles = await client.getHistoricRates({
  product_id,
  end,
  start,
  granularity,
});
const product_id = "ETH-BTC";
const stats = await client.get24hrStats({ product_id });
const currencies = await client.getCurrencies();
const id = "BTC";
const currency = await client.getCurrency({ id });
const time = await client.getTime();

AuthenticatedClient

import { AuthenticatedClient } from "coinbase-pro-node-api";
const key = "CoinbaseProAPIKey";
const secret = "CoinbaseProAPISecret";
const passphrase = "CoinbaseProAPIPassphrase";
const client = new AuthenticatedClient({ key, secret, passphrase });
const accounts = await client.getAccounts();
const account_id = "71452118-efc7-4cc4-8780-a5e22d4baa53";
const account = await client.getAccount({ account_id });
const account_id = "71452118-efc7-4cc4-8780-a5e22d4baa53";
const after = "100";
const limit = 5;
const history = await client.getAccountHistory({ account_id, after, limit });
const account_id = "71452118-efc7-4cc4-8780-a5e22d4baa53";
const after = "2019-11-22T14:33:58.093436Z";
const before = "2019-11-21T14:33:58.093436Z";
const limit = 40;
const holds = await client.getHolds({ account_id, after, before, limit });
const client_oid = "71452118-efc7-4cc4-8780-a5e22d4baa53";
const type = "limit";
const side = "buy";
const product_id = "BTC-USD";
const stp = "cb";
const price = 10000;
const size = 1;
const post_only = true;
const cancel_after = "hour";
const order = await client.placeOrder({
  client_oid,
  type,
  side,
  product_id,
  stp,
  price,
  size,
  post_only,
  cancel_after,
});
const id = "71452118-efc7-4cc4-8780-a5e22d4baa53";
let result = await client.cancelOrder({ id });
// or by `client_oid`
const client_oid = "5523db2a-f6cb-4680-86a5-23ff21d9f514";
result = await client.cancelOrder({ client_oid });
const product_id = "BTC-USD";
const result = await client.cancelAll({ product_id });
const limit = 2;
const after = "2019-09-29T19:16:37.991967Z";
const status = ["done", "rejected"];
const product_id = "BTC-USD";
const orders = await client.getOrders({ after, product_id, limit, status });
const id = "71452118-efc7-4cc4-8780-a5e22d4baa53";
let order = await client.getOrder({ id });
// or by `client_oid`
const client_oid = "5523db2a-f6cb-4680-86a5-23ff21d9f514";
order = await client.getOrder({ client_oid });
const product_id = "BTC-ETH";
const before = 74;
const fills = await client.getFills({ product_id, before });
const amount = 10000;
const currency = "USD";
const payment_method_id = "bc677162-d934-5f1a-968c-a496b1c1270b";
const deposit = await client.deposit({ amount, currency, payment_method_id });
const amount = 10;
const currency = "BTC";
const coinbase_account_id = "c13cd0fc-72ca-55e9-843b-b84ef628c198";
const deposit = await client.depositCoinbase({
  amount,
  currency,
  coinbase_account_id,
});
const amount = 10000;
const currency = "USD";
const payment_method_id = "bc677162-d934-5f1a-968c-a496b1c1270b";
const withdraw = await client.withdraw({ amount, currency, payment_method_id });
const amount = 10;
const currency = "BTC";
const coinbase_account_id = "c13cd0fc-72ca-55e9-843b-b84ef628c198";
const withdraw = await client.withdrawCoinbase({
  amount,
  currency,
  coinbase_account_id,
});
const amount = 20000;
const currency = "XRP";
const crypto_address = "r4hzEbkVkAaFyK23ZkgED2LZDAyHTfnBJg";
const no_destination_tag = true;
const withdraw = await client.withdrawCrypto({
  amount,
  currency,
  crypto_address,
  no_destination_tag,
});
const currency = "ETH";
const crypto_address = "0x5ad5769cd04681FeD900BCE3DDc877B50E83d469";
const estimate = await client.feeEstimate({ currency, crypto_address });
const amount = 100;
const from = "USD";
const to = "USDC";
const conversion = await client.convert({ amount, from, to });
const methods = await client.getPaymentMethods();
const accounts = await client.getCoinbaseAccounts();
const fees = await client.getFees();
const type = "fills";
const start_date = "2019-01-01T00:00:00.000Z";
const end_date = "2019-11-30T23:59:59.000Z";
const report = await client.createReport({ type, start_date, end_date });
const id = "0428b97b-bec1-429e-a94c-59232926778d";
const report = await client.getReport({ id });
const profiles = await client.getProfiles();
const id = "86602c68-306a-4500-ac73-4ce56a91d83c";
const profile = await client.getProfile({ id });
const from = "86602c68-306a-4500-ac73-4ce56a91d83c";
const to = "e87429d3-f0a7-4f28-8dff-8dd93d383de1";
const currency = "ETH";
const amount = 100;
const result = await client.transfer({ from, to, currency, amount });
const volume = await client.getTrailingVolume();

WebsocketClient

import { WebsocketClient } from "coinbase-pro-node-api";
const sandbox = false;
const key = "CoinbaseProAPIKey";
const secret = "CoinbaseProAPISecret";
const passphrase = "CoinbaseProAPIPassphrase";
const channels = [
  { name: "status" },
  { name: "ticker", product_ids: ["BTC-USD"] },
];
const websocket = new WebsocketClient({
  key,
  secret,
  passphrase,
  channels,
  sandbox,
});
await websocket.connect();
await websocket.disconnect();
const channels = [
  { name: "heartbeat", product_ids: ["ETH-USD"] },
  { name: "ticker", product_ids: ["ETH-EUR"] },
  { name: "status" },
];
await websocket.subscribe({ channels });
const channels = [{ name: "ticker", product_ids: ["ETH-USD", "ETH-EUR"] }];
await websocket.unsubscribe({ channels });