diff --git a/php-binance-api.php b/php-binance-api.php index 68b9662..4b46270 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -30,22 +30,29 @@ class API { protected $base = 'https://api.binance.com/api/'; // /< REST endpoint for the currency exchange - protected $baseTestnet = 'https://testnet.binance.vision/api/'; // /< Testnet REST endpoint for the currency exchange + protected $baseTestnet = 'https://demo-api.binance.com/api/'; // /< REST endpoint for the test currency exchange + protected $baseOldTestnet = 'https://testnet.binance.vision/api/'; // /< old Testnet REST endpoint for the currency exchange (deprecated) + protected $baseDemo = 'https://demo-api.binance.com/api/'; // /< Demo REST endpoint for the currency exchange protected $wapi = 'https://api.binance.com/wapi/'; // /< REST endpoint for the withdrawals protected $sapi = 'https://api.binance.com/sapi/'; // /< REST endpoint for the supporting network API protected $fapi = 'https://fapi.binance.com/fapi/'; // /< REST endpoint for the futures API protected $fapiData = 'https://fapi.binance.com/futures/data/'; // /< REST endpoint for the futures API - protected $fapiTestnet = 'https://testnet.binancefuture.com/fapi/'; // /< Testnet REST endpoint for the futures API + protected $fapiTestnet = 'https://demo-fapi.binance.com/fapi/'; // /< REST endpoint for the test futures API + protected $fapiOldTestnet = 'https://testnet.binancefuture.com/fapi/'; // /< old Testnet REST endpoint for the futures API (deprecated) + protected $fapiDemo = 'https://demo-fapi.binance.com/fapi/'; // /< Demo REST endpoint for the futures API protected $dapi = 'https://dapi.binance.com/dapi/'; // /< REST endpoint for the delivery API protected $dapiData = 'https://dapi.binance.com/futures/data/'; // /< REST endpoint for the delivery API - protected $dapiTestnet = 'https://testnet.binancefuture.com/dapi/'; // /< Testnet REST endpoint for the delivery API + protected $dapiTestnet = 'https://demo-dapi.binance.com/dapi/'; // /< REST endpoint for the test delivery API + protected $dapiOldTestnet = 'https://testnet.binancefuture.com/dapi/'; // /< Old Testnet REST endpoint for the delivery API (deprecated) + protected $dapiDemo = 'https://demo-dapi.binance.com/dapi/'; // /< Demo REST endpoint for the delivery API protected $papi = 'https://papi.binance.com/papi/'; // /< REST endpoint for the options API protected $bapi = 'https://www.binance.com/bapi/'; // /< REST endpoint for the internal Binance API protected $stream = 'wss://stream.binance.com:9443/ws/'; // /< Endpoint for establishing websocket connections protected $streamTestnet = 'wss://testnet.binance.vision/ws/'; // /< Testnet endpoint for establishing websocket connections protected $api_key; // /< API key that you created in the binance website member area protected $api_secret; // /< API secret that was given to you when you created the api key - protected $useTestnet = false; // /< Enable/disable testnet (https://testnet.binance.vision/) + protected $useTestnet = false; // /< Enable/disable test url + protected $useOldTestnet = false; // /< Enable/disable old testnet url protected $depthCache = []; // /< Websockets depth cache protected $depthQueue = []; // /< Websockets depth queue protected $chartQueue = []; // /< Websockets chart queue @@ -115,6 +122,48 @@ public function __construct() } } + /** + * enableDemoTrading - Enable or disable demo trading endpoints for testnet + * + * @param bool $enable true to enable demo trading endpoints, false to disable + */ + public function enableDemoTrading(?bool $enable = true) + { + if ($enable) { + $this->setDemoForTestnet(); + } else { + $this->setOldUrlForTestnet(); + } + } + + /** + * enableOldTestnetTrading - Enable or disable old testnet trading endpoints for testnet + * + * @param bool $enable true to enable old testnet trading endpoints, false to disable + */ + public function enableOldTestnetTrading(?bool $enable = true) + { + if ($enable) { + $this->setOldUrlForTestnet(); + } else { + $this->setDemoForTestnet(); + } + } + + protected function setDemoForTestnet() + { + $this->baseTestnet = $this->baseDemo; + $this->fapiTestnet = $this->fapiDemo; + $this->dapiTestnet = $this->dapiDemo; + } + + protected function setOldUrlForTestnet() + { + $this->baseTestnet = $this->baseOldTestnet; + $this->fapiTestnet = $this->fapiOldTestnet; + $this->dapiTestnet = $this->dapiOldTestnet; + } + /** * magic get for protected and protected members * @@ -164,6 +213,7 @@ protected function setupApiConfigFromFile(?string $file = null) $this->api_key = isset($contents['api-key']) ? $contents['api-key'] : ""; $this->api_secret = isset($contents['api-secret']) ? $contents['api-secret'] : ""; $this->useTestnet = isset($contents['use-testnet']) ? (bool)$contents['use-testnet'] : false; + $this->useTestnet = isset($contents['use-demo']) ? (bool)$contents['use-demo'] : false; } /**