bennycode / coinbase-pro-node

Coinbase API written in TypeScript and covered by tests.
https://bennycode.com/coinbase-pro-node
MIT License
254 stars 62 forks source link

How to Get Complete Response from getCandles() #98

Closed bfailing closed 4 years ago

bfailing commented 4 years ago

The following seems to only return the body from the response:

client.rest.product.getCandles('BTC-USD', {
  granularity: CandleGranularity.ONE_HOUR,
  start: start_time,
  end: end_time
});

How do you get the complete response including, e.g., the status code?

bennycode commented 4 years ago

Hi @bfailing, it is by design that only data is returned. Why would you need more than this? If there is an error you will get the full HTTP response (with status code, etc.).

bfailing commented 4 years ago

To test this (i.e. hit a rate limit), I need to disable the rate limiting in your code. How do I do that?

bennycode commented 4 years ago

The rate limiting is implemented here: https://github.com/bennyn/coinbase-pro-node/blob/v1.4.1/src/client/RESTClient.ts#L42-L48

bennycode commented 4 years ago

@bfailing here is an example how you can catch errors with additional information (you will get everything which AxiosError provides):

import {AxiosError} from 'axios';
import {CoinbasePro} from 'coinbase-pro-node';

// [...]

client.rest.product.getCandles('DOES-BOT-EXIST').catch((error: AxiosError) => {
  console.error(`Request failed when querying "${error.config.url}": ${error.message}`);
});

I hope this answers your question. Please leave me a star if it does. ⭐