coinbase-pro-api
v1.0.2
Published
lightweight coinbase pro api implementation
Downloads
20
Maintainers
Readme
coinbase-pro-api
Lightweight Coinbase Pro API implementation.
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()
.getProductOrderBook(productId[, query[, env[, parser=JSON[, stringifier=QS]]]])
const { getProductOrderBook } = require('coinbase-pro-api')
getProductOrderBook('BTC-EUR', { level: 3 })
.getProductTicker(productId[, query[, env[, parser=JSON[, stringifier=QS]]]])
const { getProductTicker } = require('coinbase-pro-api')
getProductTicker('BTC-EUR')
.getProductTrades(productId[, query[, env[, parser=JSON[, stringifier=QS]]]])
const { getProductTrades } = require('coinbase-pro-api')
getProductTrades('BTC-EUR', { after: 1000 })
.getProductHistoricRates(productId[, query[, env[, parser=JSON[, stringifier=QS]]]])
const { getProductHistoricRates } = require('coinbase-pro-api')
getProductHistoricRates('BTC-EUR', { granularity: 3600 })
.getProduct24HrStats(productId[, query[, env[, parser=JSON[, stringifier=QS]]]])
const { getProduct24HrStats } = require('coinbase-pro-api')
getProduct24HrStats('BTC-EUR')
.getCurrencies([query[, env[, parser=JSON[, stringifier=QS]]]])
const { getCurrencies } = require('coinbase-pro-api')
getCurrencies()
.getTime([query[, env[, parser=JSON[, stringifier=QS]]]])
const { getTime } = require('coinbase-pro-api')
getTime()
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()
.getPaymentMethods([query[, env[, parser=JSON[, stringifier=QS]]]])
const { getPaymentMethods } = require('coinbase-pro-api')
getPaymentMethods()
.getAccounts([query[, env[, parser=JSON[, stringifier=QS]]]])
const { getAccounts } = require('coinbase-pro-api')
getAccounts()
.getAccount(accountId[, query[, env[, parser=JSON[, stringifier=QS]]]])
const { getAccount } = require('coinbase-pro-api')
getAccount('7d0f7d8e-dd34-4d9c-a846-06f431c381ba')
.getAccountHistory(accountId[, query[, env[, parser=JSON[, stringifier=QS]]]])
const { getAccountHistory } = require('coinbase-pro-api')
getAccountHistory('7d0f7d8e-dd34-4d9c-a846-06f431c381ba', { before: 3000 })
.getAccountTransfers(accountId[, query[, env[, parser=JSON[, stringifier=QS]]]])
const { getAccountTransfers } = require('coinbase-pro-api')
getAccountTransfers('7d0f7d8e-dd34-4d9c-a846-06f431c381ba', { before: 3000 })
.getAccountHolds(accountId[, query[, env[, parser=JSON[, stringifier=QS]]]])
const { getAccountHolds } = require('coinbase-pro-api')
getAccountHolds('7d0f7d8e-dd34-4d9c-a846-06f431c381ba', { before: 3000 })
.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' })
.cancelOrder(orderId[, query[, env[, parser=JSON[, stringifier=QS]]]])
const { cancelOrder } = require('coinbase-pro-api')
cancelOrder('d50ec984-77a8-460a-b958-66f114b0de9b')
.cancelOrders([query[, env[, parser=JSON[, stringifier=QS]]]])
const { cancelOrders } = require('coinbase-pro-api')
cancelOrders()
.getOrders([query[, env[, parser=JSON[, stringifier=QS]]]])
const { getOrders } = require('coinbase-pro-api')
getOrders({ after: 3000, status: 'open' })
.getOrder(orderId[, query[, env[, parser=JSON[, stringifier=QS]]]])
const { getOrder } = require('coinbase-pro-api')
getOrder('d50ec984-77a8-460a-b958-66f114b0de9b')
.getFills([query[, env[, parser=JSON[, stringifier=QS]]]])
const { getFills } = require('coinbase-pro-api')
getFills({ product_id: 'LTC-EUR', before: 3000 })
.convert([query[, env[, parser=JSON[, stringifier=QS]]]])
const { convert } = require('coinbase-pro-api')
convert({from: 'USD', to: 'USDC', amount: '100' })
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 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;
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 }))
## 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)