Coinbase Pro API for Node.js, written in TypeScript and covered by tests.
npm install @nodefactory/coinbase-pro-node!Language Details !Code Coverage !License !Package Version !Dependency Updates
[Coinbase Pro][1] API for Node.js, written in TypeScript and covered by tests.
The purpose of [coinbase-pro-node][5] is to continue an active Coinbase Pro API after Coinbase deprecated the official Node.js library on January, 16 2020. Its predecessor got deprecated on July, 19th 2016.
- Typed. Source code is 100% TypeScript. No need to install external typings.
- Tested. Code coverage is 100%. No surprises when using "coinbase-pro-node".
- Convenient. Request throttling is built-in. Don't worry about rate limiting.
- Comfortable. More than an API client. You will get extras like candle watching.
- Maintained. Automated security updates. No threats from outdated dependencies.
- Documented. Get started with [demo scripts][3] and [generated documentation][4].
- Modern. HTTP client with Promise API. Don't lose yourself in callback hell.
- Robust. WebSocket reconnection is built-in. No problems if your Wi-Fi is gone.
- Reliable. Following [semantic versioning][8]. Get notified about breaking changes.
npm
``bash`
npm install coinbase-pro-node
Yarn
`bash`
yarn add coinbase-pro-node
JavaScript
`javascript`
const {CoinbasePro} = require('coinbase-pro-node');
const client = new CoinbasePro();
TypeScript
`typescript`
import {CoinbasePro} from 'coinbase-pro-node';
const client = new CoinbasePro();
The [demo section][3] provides many examples on how to use "coinbase-pro-node". There is also an automatically generated [API documentation][4]. For a quick start, here is a simple example for a REST request:
`typescript
import {CoinbasePro} from 'coinbase-pro-node';
// API Keys can be generated here:
// https://pro.coinbase.com/profile/api
// https://public.sandbox.pro.coinbase.com/profile/api
const auth = {
apiKey: '',
apiSecret: '',
passphrase: '',
// The Sandbox is for testing only and offers a subset of the products/assets:
// https://docs.pro.coinbase.com/#sandbox
useSandbox: true,
};
const client = new CoinbasePro(auth);
client.rest.account.listAccounts().then(accounts => {
const message = You can trade "${accounts.length}" different pairs.;`
console.log(message);
});
If you want to listen to WebSocket messages, have a look at these demo scripts:
- Subscribe to "ticker" channel (real-time price updates)
- Subscribe to authenticated "user" channel
All [demo scripts][3] are executable from the root directory. If you want to use specific credentials with a demo script, simply add a .env file to the root of this package to modify environment variables used in init-client.ts.
`bash`
npx ts-node ./src/demo/dump-candles.ts
Tip: There is a .env.defaults file which serves as a template. Just remove its .defaults extension and enter your credentials to get started. Do not commit this file (or your credentials) to any repository!
The "coinbase-pro-node" library was built to be used in Node.js environments BUT you can also make use of it in web frontend applications (using React, Vue.js, etc.). However, due to the CORS restrictions of modern web browser, you will have to use a proxy server.
A proxy server can be setup with webpack's DevServer proxy configuration or http-proxy-middleware.
Here is an example:
Backend
`typescript
import {createProxyMiddleware} from 'http-proxy-middleware';
import express from 'express';
const app = express();
app.use(
'/api-coinbase-pro',
createProxyMiddleware({
target: 'https://api.pro.coinbase.com',
changeOrigin: true,
pathRewrite: {
[^/api-coinbase-pro]: '',`
},
})
);
Later on, you can use the proxy URL (/api-coinbase-pro from above) in your web application to initialize "coinbase-pro-node" with it:
Frontend
`typescript``
const client = new CoinbasePro({
httpUrl: '/api-coinbase-pro',
apiKey: '',
apiSecret: '',
passphrase: '',
useSandbox: false,
});
Checkout [GitHub's dependency graph][6] to see who uses "coinbase-pro-node" in production. There are also [npm packages][7] depending on "coinbase-pro-node".
[![Benny Neugebauer on Stack Exchange][stack_exchange_bennyn_badge]][stack_exchange_bennyn_url]
Contributions, issues and feature requests are welcome!
Feel free to check the issues page.
The following commits will help you getting started quickly with the code base:
- Add REST API endpoint
- Add REST API endpoint (with fixtures)
All resources can be found in the [Coinbase Pro API reference][2].
This project is MIT licensed.
Please leave a star if you find this project useful.
If you like this project, you might also like these related projects:
- trading-signals, Technical indicators, written in TypeScript, with arbitrary-precision arithmetic.
- ig-trading-api, REST API, written in TypeScript, for CFD trading with IG.
- binance-api-node, Heavily tested and Promise-based Binance API with TypeScript definitions.
[1]: https://pro.coinbase.com/
[2]: https://docs.pro.coinbase.com/
[3]: https://github.com/bennycode/coinbase-pro-node/tree/main/src/demo
[4]: https://bennycode.com/coinbase-pro-node
[5]: https://www.npmjs.com/package/coinbase-pro-node
[6]: https://github.com/bennycode/coinbase-pro-node/network/dependents
[7]: https://www.npmjs.com/browse/depended/coinbase-pro-node
[8]: https://docs.npmjs.com/about-semantic-versioning
[stack_exchange_bennyn_badge]: https://stackexchange.com/users/flair/203782.png?theme=default
[stack_exchange_bennyn_url]: https://stackexchange.com/users/203782/benny-neugebauer?tab=accounts