• Stars
    star
    243
  • Rank 166,489 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Coinbase API written in TypeScript and covered by tests.

Coinbase API

Language Details Code Coverage License Package Version

Unofficial Coinbase API for Node.js, written in TypeScript and covered by tests.

Motivation

The purpose of this coinbase-pro-node package is to maintain a recent Coinbase API for Node.js with type safety through TypeScript.

Features

  • 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 and generated documentation.
  • 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. Get notified about breaking changes.

Installation

npm

npm install coinbase-pro-node

Yarn

yarn add coinbase-pro-node

Setup

JavaScript

const {CoinbasePro} = require('coinbase-pro-node');
const client = new CoinbasePro();

TypeScript

import {CoinbasePro} from 'coinbase-pro-node';
const client = new CoinbasePro();

Usage

The demo section provides many examples on how to use "coinbase-pro-node". There is also an automatically generated API documentation. For a quick start, here is a simple example for a REST request:

REST Example

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.cloud.coinbase.com/exchange/docs#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);
});

WebSocket Example

If you want to listen to WebSocket messages, have a look at these demo scripts:

Demos

All demo scripts 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.

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!

Web Frontend Applications

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

import {createProxyMiddleware} from 'http-proxy-middleware';
import express from 'express';

const app = express();

app.use(
  '/api-coinbase-pro',
  createProxyMiddleware({
    target: 'https://api.exchange.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

const client = new CoinbasePro({
  httpUrl: '/api-coinbase-pro',
  apiKey: '',
  apiSecret: '',
  passphrase: '',
  useSandbox: false,
});

Real-world Examples

Checkout GitHub's dependency graph to see who uses "coinbase-pro-node" in production. There are also npm packages depending on "coinbase-pro-node".

Maintainers

Benny Neugebauer on Stack Exchange

Stargazers

Stargazers

Contributing

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:

All resources can be found in the Coinbase Exchange API reference. For the latest updates, check Coinbase's API Changelog.

License

This project is MIT licensed.

⭐️ Show your support ⭐️

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.

Problems with official Coinbase APIs

There are official Coinbase APIs for Node.js, but they all come with some disadvantages leading to decreased developer experience (DX):

  1. Coinbase's first Node.js API has no type safety and got deprecated on July, 19th 2016
  2. Coinbase's second Node.js API has no type safety and got deprecated on January, 16 2020
  3. Coinbase's current Node.js API (OAS spec) still lacks type safety and does not incorporate best practices like automatic reconnections and request throttling

Official Coinbase API

Coinbase is versioning its API through ReadMe.com, so you can generate an API client from their OpenAPI Specification. ReadMe provides a Node.js package named "api" which allows you to retrieve an automatically generated Node.js client:

Installation

npm install api@^4.5.1

Usage

import api from 'api';

const sdk = api('@coinbase-exchange/v1.0#qgumw1pl3iz4yut');

sdk['ExchangeRESTAPI_GetProductTrades']({
  product_id: 'BTC-USD',
}).then(response => {
  console.log(`Found "${response.length}" trades.`);
});

Drawbacks

The current Coinbase Node.js SDK (provided by the api package) does not support typings for response payloads:

Official Coinbase API

More Repositories

1

trading-signals

Technical indicators to run technical analysis with JavaScript & TypeScript. 📈
TypeScript
444
star
2

ts-node-starter

GitHub template to get started with Node.js & TypeScript. ⚡
TypeScript
34
star
3

ig-trading-api

IG Trading API for Node.js, written in TypeScript.
TypeScript
22
star
4

typescript-errors

11
star
5

diagram-dsl

Library for easily drawing UML diagrams with JavaScript and "js-sequence-diagrams".
JavaScript
9
star
6

wizardy

Conversational wizard and prompts generator
TypeScript
6
star
7

sort-everything

VS Code extension to sort JSON files.
TypeScript
6
star
8

wlc-webapp

Website for free programming tutorials and screencasts.
CSS
6
star
9

atmosphere-framework-sample

Demonstrates the Atmosphere Framework (client side and serverside) in conjunction with Jersey and Comet.
4
star
10

hexo-insert-markdown

JavaScript
4
star
11

linessorterplus

Java
4
star
12

JiraButler

Test
Java
3
star
13

show-type-guards

TypeScript
2
star
14

example-puppeteer-travis-ci

JavaScript
2
star
15

webapp

Java
2
star
16

awesome-assets-resources

2
star
17

generator-toe

JavaScript
2
star
18

not-create-react-app

TypeScript
2
star
19

coffeedoc2jsdoc

A website which helps to convert CoffeeDoc syntax into valid JSDoc 3 syntax.
JavaScript
2
star
20

bennyn-playground

JavaScript
1
star
21

wire-raspberry-pi-demo

JavaScript
1
star
22

selecthor

TypeScript
1
star
23

stop-merging

JavaScript
1
star
24

knockout-image-rotator

JavaScript
1
star
25

ts-lerna-template

TypeScript
1
star
26

benny-lernt-react

TypeScript
1
star
27

wlc-blog

CSS
1
star
28

readyator

Check port to be ready before running a script.
TypeScript
1
star
29

bennys-utilities

JavaScript Utilities from Benny Neugebauer
JavaScript
1
star
30

csv2markdown

TypeScript
1
star
31

hexo-insert-toc

JavaScript
1
star
32

website

JavaScript
1
star
33

electron-gpu-util

JavaScript
1
star
34

test-coverage

JavaScript
1
star
35

welovecoding

TypeScript
1
star