From eceec92ffccdcbdb716658da7d8f42e6c02d25ef Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Thu, 11 Dec 2025 11:15:42 +0300 Subject: [PATCH 1/5] feat: demo-trading support added --- php-binance-api.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/php-binance-api.php b/php-binance-api.php index 68b9662..228e1f5 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -31,21 +31,28 @@ 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 $baseTestnetBackup = 'https://testnet.binance.vision/api/'; + 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 $fapiTestnetBackup = 'https://testnet.binancefuture.com/fapi/'; + 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 $dapiTestnetBackup = 'https://testnet.binancefuture.com/dapi/'; + 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 testnet + protected $useDemoForTestnet = false; // /< Use demo endpoints for testnet protected $depthCache = []; // /< Websockets depth cache protected $depthQueue = []; // /< Websockets depth queue protected $chartQueue = []; // /< Websockets chart queue @@ -115,6 +122,23 @@ public function __construct() } } + /** + * + */ + public function enableDemoTrading(?bool $enable = true) + { + if ($enable) { + $this->baseTestnet = $this->baseDemo; + $this->fapiTestnet = $this->fapiDemo; + $this->dapiTestnet = $this->dapiDemo; + } else { + $this->baseTestnet = $this->baseTestnetBackup; + $this->fapiTestnet = $this->fapiTestnetBackup; + $this->dapiTestnet = $this->dapiTestnetBackup; + } + $this->useDemoForTestnet = $enable; + } + /** * magic get for protected and protected members * @@ -1674,6 +1698,10 @@ protected function httpRequest(string $url, string $method = "GET", array $param $base = $this->bapi; } + print_r(PHP_EOL . '-----------------------------------------' . PHP_EOL); + print_r($base . $url); + print_r(PHP_EOL . '-----------------------------------------' . PHP_EOL); + $curl = curl_init(); curl_setopt($curl, CURLOPT_VERBOSE, $this->httpDebug); From 1c95eb5d1409f77731340861fb28e7d6e5027e9f Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Thu, 11 Dec 2025 11:17:55 +0300 Subject: [PATCH 2/5] fix: excessive lines deleted --- php-binance-api.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index 228e1f5..c3a52b6 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -1698,10 +1698,6 @@ protected function httpRequest(string $url, string $method = "GET", array $param $base = $this->bapi; } - print_r(PHP_EOL . '-----------------------------------------' . PHP_EOL); - print_r($base . $url); - print_r(PHP_EOL . '-----------------------------------------' . PHP_EOL); - $curl = curl_init(); curl_setopt($curl, CURLOPT_VERBOSE, $this->httpDebug); From 16d59915f6a8f897f17a6e47bd7f2ccc57c7f834 Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Thu, 11 Dec 2025 11:20:22 +0300 Subject: [PATCH 3/5] docs: description of enableDemoTrading added --- php-binance-api.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/php-binance-api.php b/php-binance-api.php index c3a52b6..7b6a0fb 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -123,7 +123,9 @@ 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) { From e36732303be2f5d98646e76ac9e5d80dc77bd8c6 Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Mon, 15 Dec 2025 14:35:59 +0300 Subject: [PATCH 4/5] feat: `useDemo` flag added to the constructor --- php-binance-api.php | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index 7b6a0fb..e5e6174 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -52,7 +52,7 @@ class API 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 - protected $useDemoForTestnet = false; // /< Use demo endpoints for testnet + protected $useDemo = false; // /< Use demo endpoints for testnet protected $depthCache = []; // /< Websockets depth cache protected $depthQueue = []; // /< Websockets depth queue protected $chartQueue = []; // /< Websockets chart queue @@ -91,6 +91,7 @@ class API * 1 argument - file to load config from * 2 arguments - api key and api secret * 3 arguments - api key, api secret and use testnet flag + * 4 arguments - api key, api secret, use testnet flag and use demo for testnet flag * * @return null */ @@ -117,6 +118,13 @@ public function __construct() $this->api_secret = $param[1]; $this->useTestnet = (bool)$param[2]; break; + case 4: + $useDemo = (bool)$param[3]; + $this->api_key = $param[0]; + $this->api_secret = $param[1]; + $this->useTestnet = (bool)$param[2]; + $this->enableDemoTrading($useDemo); + break; default: echo 'Please see valid constructors here: https://github.com/jaggedsoft/php-binance-api/blob/master/examples/constructor.php'; } @@ -130,15 +138,25 @@ public function __construct() public function enableDemoTrading(?bool $enable = true) { if ($enable) { - $this->baseTestnet = $this->baseDemo; - $this->fapiTestnet = $this->fapiDemo; - $this->dapiTestnet = $this->dapiDemo; + $this->setDemoEndpoints(); } else { - $this->baseTestnet = $this->baseTestnetBackup; - $this->fapiTestnet = $this->fapiTestnetBackup; - $this->dapiTestnet = $this->dapiTestnetBackup; + $this->setTestnetEndpoints(); } - $this->useDemoForTestnet = $enable; + $this->useDemo = $enable; + } + + protected function setDemoEndpoints() + { + $this->baseTestnet = $this->baseDemo; + $this->fapiTestnet = $this->fapiDemo; + $this->dapiTestnet = $this->dapiDemo; + } + + protected function setTestnetEndpoints() + { + $this->baseTestnet = $this->baseTestnetBackup; + $this->fapiTestnet = $this->fapiTestnetBackup; + $this->dapiTestnet = $this->dapiTestnetBackup; } /** @@ -190,6 +208,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->useDemo = isset($contents['use-demo']) ? (bool)$contents['use-demo'] : false; } /** From e9a585d826d475f493e9975545310e5e77eed069 Mon Sep 17 00:00:00 2001 From: yzh-pelle <81404729+yzh-pelle@users.noreply.github.com> Date: Wed, 17 Dec 2025 13:10:05 +0300 Subject: [PATCH 5/5] feat: demo url is set by default for testnet --- php-binance-api.php | 55 ++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index e5e6174..4b46270 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -30,20 +30,20 @@ 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 $baseTestnetBackup = 'https://testnet.binance.vision/api/'; + 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 $fapiTestnetBackup = 'https://testnet.binancefuture.com/fapi/'; + 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 $dapiTestnetBackup = 'https://testnet.binancefuture.com/dapi/'; + 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 @@ -51,8 +51,8 @@ class API 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 - protected $useDemo = false; // /< Use demo endpoints for testnet + 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 @@ -91,7 +91,6 @@ class API * 1 argument - file to load config from * 2 arguments - api key and api secret * 3 arguments - api key, api secret and use testnet flag - * 4 arguments - api key, api secret, use testnet flag and use demo for testnet flag * * @return null */ @@ -118,13 +117,6 @@ public function __construct() $this->api_secret = $param[1]; $this->useTestnet = (bool)$param[2]; break; - case 4: - $useDemo = (bool)$param[3]; - $this->api_key = $param[0]; - $this->api_secret = $param[1]; - $this->useTestnet = (bool)$param[2]; - $this->enableDemoTrading($useDemo); - break; default: echo 'Please see valid constructors here: https://github.com/jaggedsoft/php-binance-api/blob/master/examples/constructor.php'; } @@ -138,25 +130,38 @@ public function __construct() public function enableDemoTrading(?bool $enable = true) { if ($enable) { - $this->setDemoEndpoints(); + $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->setTestnetEndpoints(); + $this->setDemoForTestnet(); } - $this->useDemo = $enable; } - protected function setDemoEndpoints() + protected function setDemoForTestnet() { $this->baseTestnet = $this->baseDemo; $this->fapiTestnet = $this->fapiDemo; $this->dapiTestnet = $this->dapiDemo; } - protected function setTestnetEndpoints() + protected function setOldUrlForTestnet() { - $this->baseTestnet = $this->baseTestnetBackup; - $this->fapiTestnet = $this->fapiTestnetBackup; - $this->dapiTestnet = $this->dapiTestnetBackup; + $this->baseTestnet = $this->baseOldTestnet; + $this->fapiTestnet = $this->fapiOldTestnet; + $this->dapiTestnet = $this->dapiOldTestnet; } /** @@ -208,7 +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->useDemo = isset($contents['use-demo']) ? (bool)$contents['use-demo'] : false; + $this->useTestnet = isset($contents['use-demo']) ? (bool)$contents['use-demo'] : false; } /**