Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
docs: Updated API
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode committed Sep 30, 2022
1 parent 2016513 commit e4a2fd7
Show file tree
Hide file tree
Showing 85 changed files with 780 additions and 641 deletions.
50 changes: 45 additions & 5 deletions docs/README.md
Expand Up @@ -4,11 +4,11 @@ coinbase-pro-node / [Exports](modules.md)

![Language Details](https://img.shields.io/github/languages/top/bennycode/coinbase-pro-node) ![Code Coverage](https://img.shields.io/codecov/c/github/bennycode/coinbase-pro-node/main) ![License](https://img.shields.io/npm/l/coinbase-pro-node.svg) ![Package Version](https://img.shields.io/npm/v/coinbase-pro-node.svg)

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

## Motivation

The purpose of [coinbase-pro-node][5] is to continue an active **Coinbase API** after Coinbase deprecated the official Node.js library on [January, 16 2020](https://github.com/coinbase/coinbase-pro-node/issues/393#issuecomment-574993096). Its predecessor got deprecated on [July, 19th 2016](https://github.com/coinbase/coinbase-exchange-node/commit/b8347efdb4e2589367c1395b646d283c9c391681).
The purpose of this [coinbase-pro-node][5] package is to maintain a recent Coinbase API for Node.js with type safety through TypeScript.

## Features

Expand Down Expand Up @@ -56,7 +56,7 @@ 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:

### REST example
### REST Example

```typescript
import {CoinbasePro} from 'coinbase-pro-node';
Expand All @@ -81,7 +81,7 @@ client.rest.account.listAccounts().then(accounts => {
});
```

### WebSocket example
### WebSocket Example

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

Expand Down Expand Up @@ -140,7 +140,7 @@ const client = new CoinbasePro({
});
```

### Real-world examples
### Real-world Examples

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".

Expand Down Expand Up @@ -175,6 +175,46 @@ If you like this project, you might also like these related projects:
- [**ig-trading-api**](https://github.com/bennycode/ig-trading-api), REST API, written in TypeScript, for CFD trading with IG.
- [**binance-api-node**](https://github.com/Ashlar/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](https://github.com/coinbase/coinbase-exchange-node) has no type safety and got deprecated on [July, 19th 2016](https://github.com/coinbase/coinbase-exchange-node/commit/b8347efdb4e2589367c1395b646d283c9c391681)
2. [Coinbase's second Node.js API](https://github.com/coinbase/coinbase-pro-node) has no type safety and got deprecated on [January, 16 2020](https://github.com/coinbase/coinbase-pro-node/issues/393#issuecomment-574993096)
3. [Coinbase's current Node.js API](https://docs.cloud.coinbase.com/exchange/reference) ([OAS spec](https://dash.readme.com/api/v1/api-registry/qgumw1pl3iz4yut)) 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](https://readme.com/), so you can generate an API client from their [OpenAPI Specification](https://dash.readme.com/api/v1/api-registry/qgumw1pl3iz4yut). ReadMe provides a Node.js package named "[api](https://www.npmjs.com/package/api)" which allows you to retrieve an automatically generated Node.js client:

### Installation

```bash
npm install api@^4.5.1
```

### Usage

```ts
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](https://www.npmjs.com/package/api)) does not support typings for response payloads:

![Official Coinbase API](./coinbase-api-screenshot.png 'Type safety problems in official Coinbase API')

[1]: https://pro.coinbase.com/
[2]: https://docs.cloud.coinbase.com/exchange
[3]: https://github.com/bennycode/coinbase-pro-node/tree/main/src/demo
Expand Down
40 changes: 26 additions & 14 deletions docs/classes/AccountAPI.md
Expand Up @@ -35,7 +35,7 @@

#### Defined in

[account/AccountAPI.ts:124](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/account/AccountAPI.ts#L124)
[account/AccountAPI.ts:124](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/account/AccountAPI.ts#L124)

## Properties

Expand All @@ -52,7 +52,7 @@

#### Defined in

[account/AccountAPI.ts:119](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/account/AccountAPI.ts#L119)
[account/AccountAPI.ts:119](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/account/AccountAPI.ts#L119)

## Methods

Expand All @@ -62,7 +62,9 @@

Generate a new deposit address for a given account.

**`see`** https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postcoinbaseaccountaddresses
**`See`**

https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postcoinbaseaccountaddresses

#### Parameters

Expand All @@ -76,7 +78,7 @@ Generate a new deposit address for a given account.

#### Defined in

[account/AccountAPI.ts:206](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/account/AccountAPI.ts#L206)
[account/AccountAPI.ts:206](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/account/AccountAPI.ts#L206)

---

Expand All @@ -86,7 +88,9 @@ Generate a new deposit address for a given account.

Get information for a single account. API key must belong to the same profile as the account.

**`see`** https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccount
**`See`**

https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccount

#### Parameters

Expand All @@ -100,7 +104,7 @@ Get information for a single account. API key must belong to the same profile as

#### Defined in

[account/AccountAPI.ts:132](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/account/AccountAPI.ts#L132)
[account/AccountAPI.ts:132](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/account/AccountAPI.ts#L132)

---

Expand All @@ -110,7 +114,9 @@ Get information for a single account. API key must belong to the same profile as

List account activity of the API key’s profile. Account activity either increases or decreases your account balance. Items are paginated and sorted latest first.

**`see`** https://docs.pro.coinbase.com/#get-account-history
**`See`**

https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccountledger

#### Parameters

Expand All @@ -125,7 +131,7 @@ List account activity of the API key’s profile. Account activity either increa

#### Defined in

[account/AccountAPI.ts:146](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/account/AccountAPI.ts#L146)
[account/AccountAPI.ts:146](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/account/AccountAPI.ts#L146)

---

Expand All @@ -135,7 +141,9 @@ List account activity of the API key’s profile. Account activity either increa

List holds of an account that belong to the same profile as the API key. Holds are placed on an account for any active orders or pending withdraw requests. As an order is filled, the hold amount is updated. If an order is canceled, any remaining hold is removed. For a withdraw, once it is completed, the hold is removed.

**`see`** https://docs.pro.coinbase.com/#get-holds
**`See`**

https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccountholds

#### Parameters

Expand All @@ -150,7 +158,7 @@ List holds of an account that belong to the same profile as the API key. Holds a

#### Defined in

[account/AccountAPI.ts:167](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/account/AccountAPI.ts#L167)
[account/AccountAPI.ts:167](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/account/AccountAPI.ts#L167)

---

Expand All @@ -160,15 +168,17 @@ List holds of an account that belong to the same profile as the API key. Holds a

Get a list of trading accounts from the profile of the API key.

**`see`** https://docs.pro.coinbase.com/#list-accounts
**`See`**

https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccounts

#### Returns

`Promise`<[`Account`](../interfaces/Account.md)[]\>

#### Defined in

[account/AccountAPI.ts:184](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/account/AccountAPI.ts#L184)
[account/AccountAPI.ts:184](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/account/AccountAPI.ts#L184)

---

Expand All @@ -178,12 +188,14 @@ Get a list of trading accounts from the profile of the API key.

Get a list of your coinbase accounts.

**`see`** https://docs.pro.coinbase.com/#coinbase-accounts
**`See`**

https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getcoinbaseaccounts

#### Returns

`Promise`<[`CoinbaseAccount`](../interfaces/CoinbaseAccount.md)[]\>

#### Defined in

[account/AccountAPI.ts:195](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/account/AccountAPI.ts#L195)
[account/AccountAPI.ts:195](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/account/AccountAPI.ts#L195)
28 changes: 14 additions & 14 deletions docs/classes/CandleBucketUtil.md
Expand Up @@ -49,7 +49,7 @@

#### Defined in

[product/CandleBucketUtil.ts:29](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/product/CandleBucketUtil.ts#L29)
[product/CandleBucketUtil.ts:29](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/product/CandleBucketUtil.ts#L29)

---

Expand All @@ -71,7 +71,7 @@

#### Defined in

[product/CandleBucketUtil.ts:23](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/product/CandleBucketUtil.ts#L23)
[product/CandleBucketUtil.ts:23](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/product/CandleBucketUtil.ts#L23)

---

Expand All @@ -93,7 +93,7 @@

#### Defined in

[product/CandleBucketUtil.ts:67](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/product/CandleBucketUtil.ts#L67)
[product/CandleBucketUtil.ts:67](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/product/CandleBucketUtil.ts#L67)

---

Expand All @@ -113,7 +113,7 @@

#### Defined in

[product/CandleBucketUtil.ts:90](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/product/CandleBucketUtil.ts#L90)
[product/CandleBucketUtil.ts:90](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/product/CandleBucketUtil.ts#L90)

---

Expand All @@ -135,7 +135,7 @@

#### Defined in

[product/CandleBucketUtil.ts:72](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/product/CandleBucketUtil.ts#L72)
[product/CandleBucketUtil.ts:72](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/product/CandleBucketUtil.ts#L72)

---

Expand All @@ -149,7 +149,7 @@

#### Defined in

[product/CandleBucketUtil.ts:53](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/product/CandleBucketUtil.ts#L53)
[product/CandleBucketUtil.ts:53](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/product/CandleBucketUtil.ts#L53)

---

Expand All @@ -162,15 +162,15 @@
| Name | Type | Default value |
| :--------- | :------------------------------------------- | :------------ |
| `candles` | [`Candle`](../interfaces/Candle.md)[] | `undefined` |
| `property` | `"close"` \| `"high"` \| `"low"` \| `"open"` | `'close'` |
| `property` | `"high"` \| `"low"` \| `"open"` \| `"close"` | `'close'` |

#### Returns

`number`

#### Defined in

[product/CandleBucketUtil.ts:18](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/product/CandleBucketUtil.ts#L18)
[product/CandleBucketUtil.ts:18](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/product/CandleBucketUtil.ts#L18)

---

Expand All @@ -183,15 +183,15 @@
| Name | Type | Default value |
| :--------- | :------------------------------------------- | :------------ |
| `candles` | [`Candle`](../interfaces/Candle.md)[] | `undefined` |
| `property` | `"close"` \| `"high"` \| `"low"` \| `"open"` | `'close'` |
| `property` | `"high"` \| `"low"` \| `"open"` \| `"close"` | `'close'` |

#### Returns

`number`

#### Defined in

[product/CandleBucketUtil.ts:13](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/product/CandleBucketUtil.ts#L13)
[product/CandleBucketUtil.ts:13](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/product/CandleBucketUtil.ts#L13)

---

Expand All @@ -211,7 +211,7 @@

#### Defined in

[product/CandleBucketUtil.ts:63](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/product/CandleBucketUtil.ts#L63)
[product/CandleBucketUtil.ts:63](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/product/CandleBucketUtil.ts#L63)

---

Expand All @@ -232,7 +232,7 @@

#### Defined in

[product/CandleBucketUtil.ts:57](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/product/CandleBucketUtil.ts#L57)
[product/CandleBucketUtil.ts:57](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/product/CandleBucketUtil.ts#L57)

---

Expand All @@ -254,7 +254,7 @@

#### Defined in

[product/CandleBucketUtil.ts:44](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/product/CandleBucketUtil.ts#L44)
[product/CandleBucketUtil.ts:44](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/product/CandleBucketUtil.ts#L44)

---

Expand All @@ -276,4 +276,4 @@

#### Defined in

[product/CandleBucketUtil.ts:38](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/product/CandleBucketUtil.ts#L38)
[product/CandleBucketUtil.ts:38](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/product/CandleBucketUtil.ts#L38)
10 changes: 5 additions & 5 deletions docs/classes/CoinbasePro.md
Expand Up @@ -29,7 +29,7 @@

#### Defined in

[CoinbasePro.ts:54](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/CoinbasePro.ts#L54)
[CoinbasePro.ts:54](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/CoinbasePro.ts#L54)

## Properties

Expand All @@ -39,7 +39,7 @@

#### Defined in

[CoinbasePro.ts:34](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/CoinbasePro.ts#L34)
[CoinbasePro.ts:34](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/CoinbasePro.ts#L34)

---

Expand All @@ -49,7 +49,7 @@

#### Defined in

[CoinbasePro.ts:35](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/CoinbasePro.ts#L35)
[CoinbasePro.ts:35](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/CoinbasePro.ts#L35)

---

Expand All @@ -59,7 +59,7 @@

#### Defined in

[CoinbasePro.ts:36](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/CoinbasePro.ts#L36)
[CoinbasePro.ts:36](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/CoinbasePro.ts#L36)

---

Expand All @@ -76,4 +76,4 @@

#### Defined in

[CoinbasePro.ts:38](https://github.com/bennycode/coinbase-pro-node/blob/7770f03/src/CoinbasePro.ts#L38)
[CoinbasePro.ts:38](https://github.com/bennycode/coinbase-pro-node/blob/2016513/src/CoinbasePro.ts#L38)

0 comments on commit e4a2fd7

Please sign in to comment.