Lightweight Coinbase Pro API implementation.
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
npm install coinbase-pro-api
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 do not require authentication and can be used right away without further configuration.
const { getProducts } = require('coinbase-pro-api')
getProducts()
const { getProductOrderBook } = require('coinbase-pro-api')
getProductOrderBook('BTC-EUR', { level: 3 })
const { getProductTicker } = require('coinbase-pro-api')
getProductTicker('BTC-EUR')
const { getProductTrades } = require('coinbase-pro-api')
getProductTrades('BTC-EUR', { after: 1000 })
const { getProductHistoricRates } = require('coinbase-pro-api')
getProductHistoricRates('BTC-EUR', { granularity: 3600 })
const { getProduct24HrStats } = require('coinbase-pro-api')
getProduct24HrStats('BTC-EUR')
const { getCurrencies } = require('coinbase-pro-api')
getCurrencies()
const { getTime } = require('coinbase-pro-api')
getTime()
The private endpoints require authentication. You will need to configure your coinbase-pro-api
installation by providing a configuration.
const { getCoinbaseAccounts } = require('coinbase-pro-api')
getCoinbaseAccounts()
const { getPaymentMethods } = require('coinbase-pro-api')
getPaymentMethods()
const { getAccounts } = require('coinbase-pro-api')
getAccounts()
const { getAccount } = require('coinbase-pro-api')
getAccount('7d0f7d8e-dd34-4d9c-a846-06f431c381ba')
const { getAccountHistory } = require('coinbase-pro-api')
getAccountHistory('7d0f7d8e-dd34-4d9c-a846-06f431c381ba', { before: 3000 })
const { getAccountTransfers } = require('coinbase-pro-api')
getAccountTransfers('7d0f7d8e-dd34-4d9c-a846-06f431c381ba', { before: 3000 })
const { getAccountHolds } = require('coinbase-pro-api')
getAccountHolds('7d0f7d8e-dd34-4d9c-a846-06f431c381ba', { before: 3000 })
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' })
const { cancelOrder } = require('coinbase-pro-api')
cancelOrder('d50ec984-77a8-460a-b958-66f114b0de9b')
const { cancelOrders } = require('coinbase-pro-api')
cancelOrders()
const { getOrders } = require('coinbase-pro-api')
getOrders({ after: 3000, status: 'open' })
const { getOrder } = require('coinbase-pro-api')
getOrder('d50ec984-77a8-460a-b958-66f114b0de9b')
const { getFills } = require('coinbase-pro-api')
getFills({ product_id: 'LTC-EUR', before: 3000 })
const { convert } = require('coinbase-pro-api')
convert({from: 'USD', to: 'USDC', amount: '100' })
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 eithertrue
,yes
and1
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;
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
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
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"
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')
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)
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 }))
## 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')
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)