npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

coinbase-at-api

v1.0.10

Published

A lightweight, event-driven Node.js SDK for Coinbase Advanced Trade API with paper trading and real-time balance tracking.

Readme

coinbase-at-api

A lightweight, event-driven Node.js SDK for Coinbase Advanced Trade API with paper trading and real-time balance tracking.

npm version License: MIT

Features

  • 🔐 JWT Authentication (ES256) for Coinbase Advanced Trade API
  • 📡 Real-time WebSocket market data (public feed)
  • 💰 Live Balance Tracking via private WebSocket + REST polling
  • 📊 Paper Trading Engine with configurable fees, slippage, and P&L tracking
  • 🚀 Event-Driven Architecture for building trading bots
  • 🛡️ Production-ready and battle-tested

Installation

npm install coinbase-at-api

Quick Start

Paper Trading

import { CoinbaseAT } from 'coinbase-at-api';

const bot = new CoinbaseAT({
  apiKey: process.env.COINBASE_API_KEY,
  privateKey: process.env.COINBASE_API_SECRET,
  mode: 'paper',
  paper: {
    startingCash: 10000,
    feeBps: 60,
    slippageBps: 5
  }
});

bot.ws.connect();
bot.ws.on('open', () => bot.ws.subscribe(['BTC-USD']));

bot.ws.on('ticker', async (data) => {
  console.log(`${data.product_id}: $${data.price}`);
  if (parseFloat(data.price) < 95000) {
    await bot.orders.marketBuy('BTC-USD', { quoteSize: 1000 });
  }
});

bot.paper.on('fill', (order) => {
  console.log(`Filled: ${order.side} ${order.amount} @ $${order.price}`);
});

bot.paper.on('pnl', (snap) => {
  console.log(`Equity: $${snap.equity.toFixed(2)} | P&L: ${snap.returnPct.toFixed(2)}%`);
});

Live Trading

import { CoinbaseAT } from 'coinbase-at-api';

const bot = new CoinbaseAT({
  apiKey: process.env.COINBASE_API_KEY,
  privateKey: process.env.COINBASE_API_SECRET,
  mode: 'live'
});

await bot.initialize();

bot.balances.on('balances', (balances) => {
  console.log('Balances:', balances);
});

const accounts = await bot.rest.getAccounts();
console.log(accounts);

Configuration

Constructor Options

new CoinbaseAT({
  apiKey: string,              // Required: Your Coinbase API key
  privateKey: string,          // Required: Your EC private key (PEM format)
  mode: 'paper' | 'live',      // Default: 'paper'
  paper: {
    startingCash: number,      // Default: 10000
    feeBps: number,            // Default: 60 (0.6%)
    slippageBps: number        // Default: 5 (0.05%)
  }
})

API Reference

WebSocket (Market Data)

bot.ws.connect()                    // Connect to public feed
bot.ws.subscribe(['BTC-USD'])       // Subscribe to products
bot.ws.on('ticker', (data) => {})   // Listen to price updates
bot.ws.close()                      // Close connection

Paper Trading

// Market Buy
await bot.orders.marketBuy('BTC-USD', { quoteSize: 1000 })
await bot.orders.marketBuy('BTC-USD', { baseSize: 0.01 })

// Market Sell
await bot.orders.marketSell('BTC-USD', { baseSize: 0.01 })

// Get portfolio
const portfolio = bot.paper.getPortfolio()
// Returns: { cash, positions, lastPrices }

Paper Trading Events

bot.paper.on('fill', (order) => {
  // order: { side, product_id, amount, price, fee, timestamp }
})

bot.paper.on('pnl', (snapshot) => {
  // snapshot: { cash, positions, unrealizedValue, equity, totalPnL, returnPct }
})

Balance Manager (Live Mode)

await bot.initialize()  // Must call first in live mode

bot.balances.on('balances', (balances) => {
  // balances: { USD: { available, hold, uuid }, BTC: {...}, ... }
})

bot.balances.on('balance_update', (event) => {
  // Real-time WebSocket updates
})

await bot.balances.refreshBalances()
const usdBalance = bot.balances.getBalance('USD')

REST API

const accounts = await bot.rest.getAccounts()
const product = await bot.rest.getProduct('BTC-USD')
const orders = await bot.rest.getOrders()
await bot.rest.cancelOrder(orderId)

Environment Variables

Create a .env file:

COINBASE_API_KEY=organizations/YOUR_ORG/apiKeys/YOUR_KEY_ID
COINBASE_API_SECRET="-----BEGIN EC PRIVATE KEY-----\nYOUR_PRIVATE_KEY\n-----END EC PRIVATE KEY-----"

Architecture

coinbase-at-api/
├── src/
│   ├── index.js              # Main entry point
│   ├── balanceManager.js     # Real-time balance tracking
│   ├── client/
│   │   ├── auth.js           # JWT signer (ES256)
│   │   ├── rest.js           # REST API client
│   │   ├── ws.js             # Public WebSocket
│   │   └── wsPrivate.js      # Private WebSocket
│   └── brokers/
│       ├── paper.js          # Paper trading engine
│       └── live.js           # Live trading
├── .env                      # Your API credentials
└── package.json

Security Best Practices

  1. Never commit .env to version control
  2. Use API keys with minimal permissions
  3. Rotate keys regularly if exposed
  4. Test with paper trading first before going live
  5. Store private keys securely in environment variables

Roadmap

  • Live order execution (LiveBroker)
  • Limit orders support
  • Stop-loss / take-profit helpers
  • Backtesting engine
  • TypeScript definitions
  • More exchange integrations

Disclaimer

This software is for educational purposes only. Trading cryptocurrencies involves substantial risk of loss. The authors are not responsible for any financial losses incurred while using this library.

Always test with paper trading before using real funds.

License

MIT © 2026 Zephirex Technologies LLC

Support


Built with ❤️ for algorithmic traders