Socket
Socket
Sign inDemoInstall

coinbase-pro-api

Package Overview
Dependencies
0
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    coinbase-pro-api

lightweight coinbase pro api implementation


Version published
Maintainers
1
Install size
24.6 kB
Created

Readme

Source

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)

Keywords

FAQs

Last updated on 18 Jan 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc