Skip to content

Instantly share code, notes, and snippets.

@vikasprogrammer
Last active July 23, 2019 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vikasprogrammer/3f42eae721cb663a2da79910cb7555db to your computer and use it in GitHub Desktop.
Save vikasprogrammer/3f42eae721cb663a2da79910cb7555db to your computer and use it in GitHub Desktop.
Retry Requests CCXT (PHP)
class RetryCCXT {
public $ex;
public function __construct($ex) {
$this->ex = $ex;
}
public function __call($function, $params) {
try {
return call_user_func_array([$this->ex, "$function"], $params);
} catch (\ccxt\RequestTimeout $e){
C::log("Request timeout.. retrying.. ");
sleep(5);
return $this->__call($function, $params);
} catch (\ccxt\ExchangeNotAvailable $e) {
C::log("Exchange unavailable.. retrying.. ");
sleep(5);
return $this->__call($function, $params);
}
//you can add more error blocks here..
//TODO: Implement maxTries and retryBackoff functions
}
}
//How to
$ex = new \ccxt\bitmex();
$exObj = new RetryCCXT($ex);
var_dump($exObj->fetch_ticker("BTC/USD"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment