coinbase / coinbase-pro-node

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

pageArgs Not Consistent With Header Response #381

Closed patwhite closed 4 years ago

patwhite commented 5 years ago

Hi, I'm trying to paginate through results and can't seem to figure out an issue. The header response for a call to getAccountTransfers returns cb-after as a ISO time stamp, see here: "2019-09-03 18:04:35.655243+00".

However, the api library only accepts a number for the before / after parameters. Should I be converting that to epoch time? Any advice on how to page items?

vansergen commented 5 years ago

It corresponds to the created_at property of the first/last element https://github.com/coinbase/coinbase-pro-node/issues/326

You can test it like this (which is equivalent to the request with no after parameter):

authClient.getAccountTransfers(
  'account-id',
  { after: new Date().toISOString() },
  cb
);
Nicholas-t commented 5 years ago

I am getting this error 'Invalid positive integer value for parameter - after' any other suggestions? thanks in advance

vansergen commented 5 years ago

@Nicholas-t I couldn't reproduce this error. Can you provide code you used? This works fine for me:

let limit = 10;
let accound_id = 'your-account-id';
authClient.getAccountTransfers(accound_id, { limit }, (error, response, data) => {
  if (error) {
    console.error(error);
  } else {
    let after = response.headers['cb-after'];
    let before = response.headers['cb-before'];
    console.log(before === data[0].created_at);
    console.log(after === data[data.length - 1].created_at);
    authClient.getAccountTransfers(
      accound_id,
      { limit, after },
      (error, response, data) => {
        if (error) {
          console.error(error);
        } else {
          console.log(response.headers['cb-before'] === data[0].created_at);
          console.log(
            response.headers['cb-after'] === data[data.length - 1].created_at
          );
        }
      }
    );
  }
});
drewrothstein commented 4 years ago

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