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

Commit

Permalink
refactor: Upgrade from pro.coinbase.com to exchange.coinbase.com (#729)
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode committed May 24, 2022
1 parent b7b45a2 commit 76c2c45
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 33 deletions.
17 changes: 9 additions & 8 deletions README.md
@@ -1,12 +1,12 @@
# Coinbase Pro API
# Coinbase API

![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) ![Dependency Updates](https://img.shields.io/david/bennycode/coinbase-pro-node.svg)
![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 Pro][1] API for Node.js, written in TypeScript and covered by tests.
[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 Pro 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 [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).

## Features

Expand Down Expand Up @@ -67,7 +67,7 @@ const auth = {
apiSecret: '',
passphrase: '',
// The Sandbox is for testing only and offers a subset of the products/assets:
// https://docs.pro.coinbase.com/#sandbox
// https://docs.cloud.coinbase.com/exchange/docs#sandbox
useSandbox: true,
};

Expand Down Expand Up @@ -115,7 +115,7 @@ const app = express();
app.use(
'/api-coinbase-pro',
createProxyMiddleware({
target: 'https://api.pro.coinbase.com',
target: 'https://api.exchange.coinbase.com',
changeOrigin: true,
pathRewrite: {
[`^/api-coinbase-pro`]: '',
Expand Down Expand Up @@ -157,7 +157,7 @@ The following commits will help you getting started quickly with the code base:
- [Add REST API endpoint](https://github.com/bennycode/coinbase-pro-node/commit/9920c2f4343985c349b68e2a47d7fe2c42e23e34)
- [Add REST API endpoint (with fixtures)](https://github.com/bennycode/coinbase-pro-node/commit/8a150fecb7d32b7b7cd39a8109985f665aaee26e)

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

## License

Expand All @@ -174,12 +174,13 @@ If you like this project, you might also like these related projects:
- [**binance-api-node**](https://github.com/Ashlar/binance-api-node), Heavily tested and Promise-based Binance API with TypeScript definitions.

[1]: https://pro.coinbase.com/
[2]: https://docs.pro.coinbase.com/
[2]: https://docs.cloud.coinbase.com/exchange
[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
[9]: https://docs.cloud.coinbase.com/exchange/docs/changelog
[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
6 changes: 3 additions & 3 deletions src/CoinbasePro.ts
Expand Up @@ -41,11 +41,11 @@ export class CoinbasePro {
} = {
PRODUCTION: {
REST: 'https://api.exchange.coinbase.com',
WebSocket: 'wss://ws-feed.pro.coinbase.com',
WebSocket: 'wss://ws-feed.exchange.coinbase.com',
},
SANDBOX: {
REST: 'https://api-public.sandbox.pro.coinbase.com',
WebSocket: 'wss://ws-feed-public.sandbox.pro.coinbase.com',
REST: 'https://api-public.sandbox.exchange.coinbase.com',
WebSocket: 'wss://ws-feed-public.sandbox.exchange.coinbase.com',
},
};

Expand Down
2 changes: 1 addition & 1 deletion src/account/AccountAPI.test.ts
Expand Up @@ -96,7 +96,7 @@ describe('AccountAPI', () => {
const newDepositAddress = await global.client.rest.account.generateDepositAddress(
'322dfa88-e10d-4678-856d-2930eac3e62d'
);
expect(newDepositAddress).toBeDefined();
expect(newDepositAddress.address).toBe('0xd518A6B23D8bCA15B9cC46a00Be8a818E34Ca79E');
});
});
});
12 changes: 7 additions & 5 deletions src/account/AccountAPI.ts
Expand Up @@ -60,11 +60,13 @@ export interface CoinbaseAccount {
export interface GeneratedAddress {
address: string;
address_info: AddressInfo;
callback_url: null;
callback_url?: string;
created_at: Date;
deposit_uri: string;
deposit_uri?: string;
destination_tag?: string;
exchange_deposit_address: boolean;
id: string;
legacy_address?: string;
name: string;
network: string;
resource: string;
Expand All @@ -76,6 +78,7 @@ export interface GeneratedAddress {

export interface AddressInfo {
address: string;
destination_tag?: string;
}

export interface Warning {
Expand Down Expand Up @@ -124,7 +127,7 @@ export class AccountAPI {
* Get information for a single account. API key must belong to the same profile as the account.
*
* @param accountId - Account ID belonging to the API key’s profile
* @see https://docs.pro.coinbase.com/#get-an-account
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccount
*/
async getAccount(accountId: string): Promise<Account> {
const resource = `${AccountAPI.URL.ACCOUNTS}/${accountId}`;
Expand Down Expand Up @@ -196,13 +199,12 @@ export class AccountAPI {
}

/**
* Generate a new deposit address for a given account
* Generate a new deposit address for a given account.
*
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postcoinbaseaccountaddresses
*/
async generateDepositAddress(accountId: string): Promise<GeneratedAddress> {
const resource = `${AccountAPI.URL.COINBASE_ACCOUNT}/${accountId}/addresses`;

const response = await this.apiClient.post<GeneratedAddress>(resource);
return response.data;
}
Expand Down
2 changes: 1 addition & 1 deletion src/auth/RequestSigner.ts
Expand Up @@ -16,7 +16,7 @@ export interface SignedRequest {
}

export class RequestSigner {
// https://docs.pro.coinbase.com/#creating-a-request
// https://docs.cloud.coinbase.com/exchange/docs/authorization-and-authentication#creating-a-request
static signRequest(auth: ClientAuthentication, setup: RequestSetup, clockSkew: number): SignedRequest {
const timestamp = Date.now() / 1000 + clockSkew;
const what = `${timestamp}${setup.httpMethod}${setup.requestPath}${setup.payload}`;
Expand Down
2 changes: 1 addition & 1 deletion src/currency/CurrencyAPI.ts
Expand Up @@ -38,7 +38,7 @@ export class CurrencyAPI {
* Currency codes will conform to the ISO 4217 standard where possible.
* Currencies which have or had no representation in ISO 4217 may use a custom code.
*
* @see https://docs.pro.coinbase.com/#get-currencies
* @see https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-currencies#get-currencies
*/
async listCurrencies(): Promise<Currency[]> {
const resource = CurrencyAPI.URL.CURRENCIES;
Expand Down
2 changes: 1 addition & 1 deletion src/order/OrderAPI.ts
Expand Up @@ -20,7 +20,7 @@ export enum CancelOrderPeriod {
ONE_MINUTE = 'min',
}

// https://docs.pro.coinbase.com/#self-trade-prevention
/** @see https://docs.cloud.coinbase.com/exchange/docs/matching-engine#self-trade-prevention */
export enum SelfTradePrevention {
CANCEL_BOTH = 'cb',
CANCEL_NEWEST = 'cn',
Expand Down
2 changes: 1 addition & 1 deletion src/payload/common.ts
Expand Up @@ -9,7 +9,7 @@ export enum OrderSide {
SELL = 'sell',
}

/** @see https://docs.pro.coinbase.com/#pagination */
/** @see https://docs.cloud.coinbase.com/exchange/docs/pagination */
export interface Pagination {
/** Request page after (older) this pagination id. */
after?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/product/CandleBucketUtil.ts
@@ -1,7 +1,7 @@
import {Candle, CandleGranularity} from '.';
import {ISO_8601_MS_UTC} from '..';

/** The maximum number of data points for a single historic rates API request on Coinbase Pro is 300 candles: https://docs.pro.coinbase.com/#get-historic-rates */
/** The maximum number of data points for a single historic rates API request on Coinbase Pro is 300 candles: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproductcandles */
const MAXIMUM_HISTORIC_DATA_POINTS = 300;

export interface CandleBatchBucket {
Expand Down
6 changes: 0 additions & 6 deletions src/test/helpers/SetupCoinbasePro.ts
Expand Up @@ -3,12 +3,6 @@ import nock from 'nock';
import {TimeAPI} from '../../time/TimeAPI';

declare global {
module NodeJS {
interface Global {
client: CoinbasePro;
REST_URL: string;
}
}
/* eslint-disable no-var */
var client: CoinbasePro;
var REST_URL: string;
Expand Down
2 changes: 1 addition & 1 deletion src/time/TimeAPI.ts
Expand Up @@ -18,7 +18,7 @@ export class TimeAPI {
* Get the server time from Coinbase Pro API. It has been reported that sometimes the return value is a string:
* https://github.com/bennycode/coinbase-pro-node/issues/354
*
* @see https://docs.pro.coinbase.com/#time
* @see https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-time
*/
async getTime(): Promise<TimeSkew> {
const response = await axios.get<TimeSkew>(`${this.baseURL}${TimeAPI.URL.TIME}`, {
Expand Down
4 changes: 2 additions & 2 deletions src/transfer/TransferAPI.ts
Expand Up @@ -45,8 +45,8 @@ export class TransferAPI {
* Get a list of deposits/withdrawals from the profile of the API key, in descending order by created time.
*
* @param pagination - Pagination field
* @see https://docs.pro.coinbase.com/#list-deposits
* @see https://docs.pro.coinbase.com/#list-withdrawals
* @see https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-deposits#list-deposits
* @see https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-withdrawals#list-withdrawals
*/
async getTransfers(
transferType: TransferType,
Expand Down
5 changes: 3 additions & 2 deletions src/user/UserAPI.ts
Expand Up @@ -22,7 +22,7 @@ export class UserAPI {
* Verify your authentication with Coinbase Pro.
*
* @returns Your account
* @see https://docs.pro.coinbase.com/#subscribe
* @see https://docs.cloud.coinbase.com/exchange/docs/websocket-overview#authentication
*/
async verifyAuthentication(): Promise<VerifiedUser> {
const resource = `${UserAPI.URL.USERS}/self/verify`;
Expand All @@ -36,7 +36,8 @@ export class UserAPI {
*
* @note This endpoint requires either the “view” or “trade” permission
* @returns Your 30-day trailing volume for all products of the API key’s profile
* @see https://docs.pro.coinbase.com/#trailing-volume
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getfees
* @deprecated The Trailing Volume endpoint has been deprecated in favor of the Fees endpoint to get the latest volumes: https://docs.cloud.coinbase.com/exchange/docs/changelog#2021-feb-04
*/
async getTrailingVolume(): Promise<TrailingVolume[]> {
const resource = `${UserAPI.URL.USERS}/self/trailing-volume`;
Expand Down

0 comments on commit 76c2c45

Please sign in to comment.