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 🙏

© 2024 – Pkg Stats / Ryan Hefner

coinbase-pro-api

v1.0.2

Published

lightweight coinbase pro api implementation

Downloads

20

Readme

coinbase-pro-api

Lightweight Coinbase Pro API implementation.

travis dependencies coverage status linter

node version license minzip downloads

Donations

If you find value in what I do then feel free to make a donation, it will be really appreciated! Maintaining projects isn't effortless nor free and if you'd like to kick in and help me cover those expenses, that would be awesome. If you don't, no problem; You can use my software completely free of charge and without limitation for any purpose you want ;)

  • BTC 3BNL7UnYmByrdEguoEnA7S95WzdDYLmKuS
  • LTC MEgxjro7E6z8Mfy4Uy8xaJPrskdwmrCers
  • BCH qrtl83z594m7g4nv390xdg5mg7tywuwq5vzlsa82dp
  • ETH 0xeED2C60dd83e77F5650962E653b2a6F26A5c2f26
  • ETC 0x5B4224b376C0a32B70B0e25F6aEeCfc2d0131703
  • ZRX 0x345df25C52B81E045Bfb3C21b15343c4D114e43e
  • BAT 0xB23Bb1933bDF676502426AdcA2D7B3E0Ed18AfDF
  • ZEC t1h78dUWEY9hA2UZVyNazbgAfZNmicEK6qA
  • USDC 0x7fb93FfBcFa9A537ddFaC9678b1C27DF776eE626

Installation

npm install coinbase-pro-api

Usage

This library allows you to use both public and private endpoints as well as the sandbox environment for testing connectivity and trading. You can learn about query parameters and responses of each endpoint in the official documentation.

Public Endpoints

Public endpoints do not require authentication and can be used right away without further configuration.

.getProducts([query[, env[, parser=JSON[, stringifier=QS]]]])

const { getProducts } = require('coinbase-pro-api')
getProducts()

» query params and responses

.getProductOrderBook(productId[, query[, env[, parser=JSON[, stringifier=QS]]]])

const { getProductOrderBook } = require('coinbase-pro-api')
getProductOrderBook('BTC-EUR', { level: 3 })

» query params and responses

.getProductTicker(productId[, query[, env[, parser=JSON[, stringifier=QS]]]])

const { getProductTicker } = require('coinbase-pro-api')
getProductTicker('BTC-EUR')

» query params and responses

.getProductTrades(productId[, query[, env[, parser=JSON[, stringifier=QS]]]])

const { getProductTrades } = require('coinbase-pro-api')
getProductTrades('BTC-EUR', { after: 1000 })

» query params and responses

.getProductHistoricRates(productId[, query[, env[, parser=JSON[, stringifier=QS]]]])

const { getProductHistoricRates } = require('coinbase-pro-api')
getProductHistoricRates('BTC-EUR', { granularity: 3600 })

» query params and responses

.getProduct24HrStats(productId[, query[, env[, parser=JSON[, stringifier=QS]]]])

const { getProduct24HrStats } = require('coinbase-pro-api')
getProduct24HrStats('BTC-EUR')

» query params and responses

.getCurrencies([query[, env[, parser=JSON[, stringifier=QS]]]])

const { getCurrencies } = require('coinbase-pro-api')
getCurrencies()

» query params and responses

.getTime([query[, env[, parser=JSON[, stringifier=QS]]]])

const { getTime } = require('coinbase-pro-api')
getTime()

» query params and responses

Private Endpoints

The private endpoints require authentication. You will need to configure your coinbase-pro-api installation by providing a configuration.

.getCoinbaseAccounts([query[, env[, parser=JSON[, stringifier=QS]]]])

const { getCoinbaseAccounts } = require('coinbase-pro-api')
getCoinbaseAccounts()

» query params and responses

.getPaymentMethods([query[, env[, parser=JSON[, stringifier=QS]]]])

const { getPaymentMethods } = require('coinbase-pro-api')
getPaymentMethods()

» query params and responses

.getAccounts([query[, env[, parser=JSON[, stringifier=QS]]]])

const { getAccounts } = require('coinbase-pro-api')
getAccounts()

» query params and responses

.getAccount(accountId[, query[, env[, parser=JSON[, stringifier=QS]]]])

const { getAccount } = require('coinbase-pro-api')
getAccount('7d0f7d8e-dd34-4d9c-a846-06f431c381ba')

» query params and responses

.getAccountHistory(accountId[, query[, env[, parser=JSON[, stringifier=QS]]]])

const { getAccountHistory } = require('coinbase-pro-api')
getAccountHistory('7d0f7d8e-dd34-4d9c-a846-06f431c381ba', { before: 3000 })

» query params and responses

.getAccountTransfers(accountId[, query[, env[, parser=JSON[, stringifier=QS]]]])

const { getAccountTransfers } = require('coinbase-pro-api')
getAccountTransfers('7d0f7d8e-dd34-4d9c-a846-06f431c381ba', { before: 3000 })

» query params and responses

.getAccountHolds(accountId[, query[, env[, parser=JSON[, stringifier=QS]]]])

const { getAccountHolds } = require('coinbase-pro-api')
getAccountHolds('7d0f7d8e-dd34-4d9c-a846-06f431c381ba', { before: 3000 })

» query params and responses

.placeOrder(data[, env[, parser=JSON[, stringifier=JSON]]])

const { placeOrder } = require('coinbase-pro-api')

// Buy 1 LTC @ 20 EUR
placeOrder({ side: 'buy', size: '1', price: '20.00', product_id: 'LTC-EUR' })

// Sell 1 LTC @ 20 EUR
placeOrder({ side: 'sell', size: '1', price: '20.00', product_id: 'LTC-EUR' })

» query params and responses

.cancelOrder(orderId[, query[, env[, parser=JSON[, stringifier=QS]]]])

const { cancelOrder } = require('coinbase-pro-api')
cancelOrder('d50ec984-77a8-460a-b958-66f114b0de9b')

» query params and responses

.cancelOrders([query[, env[, parser=JSON[, stringifier=QS]]]])

const { cancelOrders } = require('coinbase-pro-api')
cancelOrders()

» query params and responses

.getOrders([query[, env[, parser=JSON[, stringifier=QS]]]])

const { getOrders } = require('coinbase-pro-api')
getOrders({ after: 3000, status: 'open' })

» query params and responses

.getOrder(orderId[, query[, env[, parser=JSON[, stringifier=QS]]]])

const { getOrder } = require('coinbase-pro-api')
getOrder('d50ec984-77a8-460a-b958-66f114b0de9b')

» query params and responses

.getFills([query[, env[, parser=JSON[, stringifier=QS]]]])

const { getFills } = require('coinbase-pro-api')
getFills({ product_id: 'LTC-EUR', before: 3000 })

» query params and responses

.convert([query[, env[, parser=JSON[, stringifier=QS]]]])

const { convert } = require('coinbase-pro-api')
convert({from: 'USD', to: 'USDC', amount: '100' })

» query params and responses

Configuration

Configurations such as credentials and environments follow the npm configuration guideline. Configurations can be set via command line, environment variables and npmrc files. To create an api key unique to your trading account refer to this guide.

  • sandbox (optional) can be set to either true, yes and 1 to switch to sandbox environment;
  • hostname (optional) allows to override default coinbase-pro hostname;
  • key (mandatory for private endpoints only) coinbase-pro api key unique to your trading account;
  • passphrase (mandatory for private endpoints only) coinbase-pro api passphrase unique to your trading account;
  • secret (mandatory for private endpoints only) coinbase-pro api secret unique to your trading account;

command line

npm config set coinbase-pro-api:sandbox false
npm config set coinbase-pro-api:hostname api.pro.coinbase.com
npm config set coinbase-pro-api:key key
npm config set coinbase-pro-api:passphrase passphrase
npm config set coinbase-pro-api:secret secret

environment variables

env npm_config_coinbase_pro_api_sandbox="false" \
    npm_config_coinbase_pro_api_hostname="api.pro.coinbase.com" \
    npm_config_coinbase_pro_api_key="key" \
    npm_config_coinbase_pro_api_passphrase="passphrase" \
    npm_config_coinbase_pro_api_secret="secret" \
    node script.js

npmrc

coinbase-pro-api:sandbox="false"
coinbase-pro-api:hostname="api.pro.coinbase.com"
coinbase-pro-api:key="key"
coinbase-pro-api:passphrase="passphrase"
coinbase-pro-api:secret="secret"

Submodule Util

The util submodule is primarily designed to support the needs of coinbase-pro-api own internal APIs. However, many of the utilities are useful for application and module developers as well. It can be accessed using:

const util = require('coinbase-pro-api/util')

.configurationFor(options)

This utility generates an npm-like configuration object that can be used to override the internal configuration management:

const { configurationFor } = require('coinbase-pro-api/util')

const env = configurationFor({
  sandbox: false,
  hostname: 'api.pro.coinbase.com',
  key: 'key',
  passphrase: 'passphrase',
  secret: 'secret'
})

getAccounts(query, env)
  .then(console.log)
  .catch(console.error)

.signatureFor(options[, env[, crypto]])

This utility generates a base64 encoded sha256 hmac signature compatible with coinbase-pro:

const timestamp = 1e-3 * Date.now()
const method = 'get'
const path = '/api/endpoint'
const body = '?query=string'

const signature = signatureFor({ timestamp, method, path, body}, configurationFor({ secret }))

» selecting a timestamp

## Document submodule coinbase-pro-api/client The client submodule is primarily designed to support the needs of coinbase-pro-api own internal APIs. However, many of the utilities are useful for application and module developers as well. It can be accessed using:

const util = require('coinbase-pro-api/client')

.request(options[, env])

This utility wraps https.request and returns a promise that resolves into https.ClientRequest.

const { request } = require('coinbase-pro-api/client')

request({ method: 'get', path: '/products' })
  .then(res => res.pipe(process.stdout))
  .catch(console.error)