bausmeier/node-bitx

Unhandled promise rejection when calling the stopOrder function

JustinNothling opened this issue · 11 comments

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: BitX error 504

Any ideas?

This module doesn't use promises so that part must be coming from your code, but the error is caused by an HTTP response status code of 504 (Gateway Timeout) being returned by the Luno API. Their docs don't mention a case where a 504 would be returned so I can only suspect that the issue is on the Luno side. I'm able to access their API at the moment, so maybe try again now?

Afraid I'm still getting the same 504 timeout error. Are you able to call stopOrder as part of a series of calls? stopOrder works correctly for me if it is the only call but produces the error when there are more processes happening after it.

  • When I just call any of the GET methods via this library all works fine -- both for single calls and consecutive calls.
  • Similarly, when I just call any of the POST methods via the library all works fine -- both for single calls and consecutive calls.
  • However, if I call a POST method followed by a GET method then I get the above 504 error and the GET request http request never ends
  • Subsequent POST calls still work but not GET
  • the GET requests are only handled again once I restart my server

As a check, I have run sequences similar to the above using curl and the issues do not occur.

@andrewrobertdavies Thanks for the additional detail. I will try and find some time to investigate this further in the next few days and keep you updated.

Additionally: I am performing similar operations re: the Bitstamp exchange using the npm Bitstamp lib (which appears to be a very similar https wrapper) but the problems above are not encountered.
Possibly related to the Rate Limiting per the Luno documentation & the node https handling of sockets?

@bausmeier it appears to be working now so I think the issue must have been with luno and not your library.

Ok - so here is what is happening & it is on the Luno server end.

  • The 'rate limiting' allows 'bursts up to 5 consecutive calls'.
  • Calls by all methods count towards this tally.
  • Once the tally reaches 5 GET calls become blocked, but POST calls do not.

This approach kind of makes sense in maintaining the ability to trade but preventing data being drawn from the server unconditionally.

The blocking gets lifted after a period of a few minutes.

Again though, calling via curl (or resetting the client server) circumnavigates this issue so it is something to do with the sockets/connections when called by the node https methods.

Thanks for investigating further. I think there is an issue in this package to do with the headers that are being set when a post request is sent. I will confirm and fix it this evening.

I published bitx@1.5.1. Please confirm that this resolves your issue.

The API does do rate limiting, but returns the correct 429 Too Many Requests response code in that case. The 504 that you were getting was because the content type and content length headers from the previous POST request were being included in following GET requests and it seems like the gateway timeout was due to the server waiting for the content to arrive. I implemented a fix so that these headers are no longer included incorrectly on the GET requests.

Works like a charm. Thanks!