coinbase / coinbase-pro-node

DEPRECATED — The official Node.js library for Coinbase Pro
Apache License 2.0
844 stars 316 forks source link

Normalize method arguments #362

Closed vansergen closed 4 years ago

vansergen commented 5 years ago

What does this PR do?

It introduces a few changes that unify the way one can use this library.

PublicClient.getProductTrades(
  { product_id: 'BTC-USD', before: 953, after: 1000 },
  callback
);
PublicClient.getCurrencies(callback);
AuthenticatedClient.getOrder({ id: 'some-order-id' }, callback);
const PublicClient = new CoinbasePro.PublicClient({
  sandbox: true,
});
// Throws an error because `granularity` is undefined.
AuthenticatedClient.getProductHistoricRates(callback);
// Throws an error because `id` is undefined.
AuthenticatedClient.cancelOrder(callback);
// Throws an error because `payment_method_id` is undefined.
AuthenticatedClient.depositPayment(
  { amount: '100.00', currency: 'USD' },
  callback
);
const websocket = new CoinbasePro.WebsocketClient({
  product_ids: 'ETH-DAI',
});
// (somewhere else in your code) when you need you can connect to the websocket.
websocket.connect();
// when you do not need the connection you can disconnect from the websocket.
websocket.disconnect();
// when you need it again
websocket.connect();

Related PRs

const AuthenticatedClient = new CoinbasePro.AuthenticatedClient({
  key: 'my-API-key',
  secret: 'my-API-secret',
  passphrase: 'my-API-passphrase',
  product_id: 'LTC-USD',
});
// get LTC-USD trades
const trades = AuthenticatedClient.getProductTradeStream({
  tradesFrom: 8408000,
  tradesTo: 8409000,
});

Other features

const AuthenticatedClient = new CoinbasePro.AuthenticatedClient({
  key: 'my-API-key',
  secret: 'my-API-secret',
  passphrase: 'my-API-passphrase',
  product_id: 'ETH-BTC',
});
// You do not define `type`.
// You do not define `product_id` because you saved it in `AuthenticatedClient`.
// buy 1 ETH @ 0.01 (LIMIT because you provide `price`)
const order = AuthenticatedClient.buy({
  price: '0.01',
  size: '1',
});
// buy ETH (MARKET because you provide `funds`)
const order = AuthenticatedClient.buy({
  funds: '0.01',
});
// You do not define `type` because you provide `account_id`.
const report = AuthenticatedClient.createReport({
  start_date: 'some_start_date',
  end_date: 'some_end_date',
  account_id: 'some_account_id',
  format: 'csv',
});

Backwards compatibility

This PR removes all deprecation warnings that were introduced in https://github.com/coinbase/coinbase-pro-node/pull/178 and contains incompatible changes. So, this PR can be a good start towards v1.0.0-beta release.

drewrothstein commented 4 years ago

Hi, we are closing out PRs + Issues as this project is being archived.