Last active
July 23, 2019 07:46
-
-
Save vikasprogrammer/3f42eae721cb663a2da79910cb7555db to your computer and use it in GitHub Desktop.
Retry Requests CCXT (PHP)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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