Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bitfinex v2 fetch_ohlcv empty / null response handling #399

Closed
ralondo opened this issue Oct 25, 2017 · 6 comments
Closed

bitfinex v2 fetch_ohlcv empty / null response handling #399

ralondo opened this issue Oct 25, 2017 · 6 comments
Assignees

Comments

@ralondo
Copy link

ralondo commented Oct 25, 2017

It seems, that bitfinex v2 fetch_ohlcv sometimes returns empty / null responses. I guess some problems on bitfinexs side. I get these warnings in my errorlog:
PHP Warning: array_key_exists() expects parameter 2 to be array, null given in /srv/www/htdocs/crypt/includes/classes/ccxt.php on line 4772
PHP Warning: array_values() expects parameter 1 to be array, null given in /srv/www/htdocs/crypt/includes/classes/ccxt.php on line 917
PHP Warning: Invalid argument supplied for foreach() in /srv/www/htdocs/crypt/includes/classes/ccxt.php on line 918

The $response in line 4771 is empty, the parameters for the fetch2 call are:
$body: (is empty)
$path:candles/trade:{timeframe}:{symbol}/hist
$params (print_r): Array\n(\n [symbol] => tBTCUSD\n [timeframe] => 1m\n)\n

Would it be possible to have some kind of handling there for empty responses?

@kroitor
Copy link
Member

kroitor commented Oct 25, 2017

@ralondo hi! Thanks for reporting! I'll take a look into it. In the meantime, can you show your code, please? These symptoms may indicate that you are hitting their rate limit... Do you actually throttle your requests?

@kroitor kroitor self-assigned this Oct 25, 2017
@ralondo
Copy link
Author

ralondo commented Oct 25, 2017

What code do you need? How can I check with ccxt if I hit the rate limit? Anyway, I do throttle my requests by having my own scheduler, in average only one call every 12 seconds to bitfinex. According to their API-docs the the rate limit on the REST-API is 10-90 calls per minute, so I could make at least 1 call every 6 seconds.
The warning doesn't always come, only every few minutes. I lowered my rate now a little bit to a max. of one call every 14 seconds. Maybe it will help.

@kroitor
Copy link
Member

kroitor commented Oct 25, 2017

@ralondo ok, no need for the code... Unfortunately, they state it clear, v2 is beta. We will add more checks to handle for empty responses. Thx!

@ralondo
Copy link
Author

ralondo commented Oct 25, 2017

No problem. I just changed the code for me a bit to get rid of those annoying warnings:
if (!is_array($response)) { logtext($response." BODY:".$body." PATH:".$path." PARAMS:".print_r($params,true)); $response = array(); } else { if (array_key_exists ('message', $response)) { if (mb_strpos ($response['message'], 'not enough exchange balance') !== false) throw new InsufficientFunds ($this->id . ' ' . $this->json ($response)); throw new ExchangeError ($this->id . ' ' . $this->json ($response)); } }
I just don't have to forget to reinsert this code after upgrading ccxt ;)

@kroitor
Copy link
Member

kroitor commented Oct 25, 2017

With examples/php/bitfinex2-fetch-ohlcv.php I'm also having some errors from Bitfinex v2:

...
2017-10-25T14:32:00.000+00:00	120
2017-10-25T14:32:00.000+00:00	120
2017-10-25T14:33:00.000+00:00	120
PHP Fatal error:  Uncaught exception 'ccxt\RequestTimeout' with message 'bitfinex2 GET https://api.bitfinex.com/v2/candles/trade:1m:tBTCUSD/hist 28 Operation timed out after 10000 milliseconds with 0 bytes received' in /Users/igorkroitor/ccxt/build/ccxt.php:629
Stack trace:
#0 /Users/igorkroitor/ccxt/build/ccxt.php(765): ccxt\Exchange->raise_error('RequestTimeout', 'https://api.bit...', 'GET', 28, 'Operation timed...')
#1 /Users/igorkroitor/ccxt/build/ccxt.php(650): ccxt\Exchange->fetch('https://api.bit...', 'GET', NULL, NULL)
#2 /Users/igorkroitor/ccxt/build/ccxt.php(4771): ccxt\Exchange->fetch2('candles/trade:{...', 'public', 'GET', Array, NULL, NULL)
#3 [internal function]: ccxt\bitfinex2->request('candles/trade:{...', 'public', 'GET', Array)
#4 /Users/igorkroitor/ccxt/build/ccxt.php(593): call_user_func(Array, 'candles/trade:{...', 'public', 'GET', Array)
#5 [internal function]: ccxt\Exchange->ccxt\{closure}(Array)
#6 /Users/igorkroitor/ccxt/build/ccxt.php(1327): call_user_func_array(Object(Closure), Array)
#7 /Users/igork in /Users/igorkroitor/ccxt/build/ccxt.php on line 629
mbp:ccxt igorkroitor$ 

So, yes, I am adding the handling for it now.

@kroitor
Copy link
Member

kroitor commented Oct 25, 2017

This issue was addressed and fixed in 1.9.262. Thx again for your feedback! Really appreciate it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants