Skip to content

Commit e9a585d

Browse files
authored
feat: demo url is set by default for testnet
1 parent e367323 commit e9a585d

1 file changed

Lines changed: 30 additions & 25 deletions

File tree

php-binance-api.php

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,29 @@
3030
class API
3131
{
3232
protected $base = 'https://api.binance.com/api/'; // /< REST endpoint for the currency exchange
33-
protected $baseTestnet = 'https://testnet.binance.vision/api/'; // /< Testnet REST endpoint for the currency exchange
34-
protected $baseTestnetBackup = 'https://testnet.binance.vision/api/';
33+
protected $baseTestnet = 'https://demo-api.binance.com/api/'; // /< REST endpoint for the test currency exchange
34+
protected $baseOldTestnet = 'https://testnet.binance.vision/api/'; // /< old Testnet REST endpoint for the currency exchange (deprecated)
3535
protected $baseDemo = 'https://demo-api.binance.com/api/'; // /< Demo REST endpoint for the currency exchange
3636
protected $wapi = 'https://api.binance.com/wapi/'; // /< REST endpoint for the withdrawals
3737
protected $sapi = 'https://api.binance.com/sapi/'; // /< REST endpoint for the supporting network API
3838
protected $fapi = 'https://fapi.binance.com/fapi/'; // /< REST endpoint for the futures API
3939
protected $fapiData = 'https://fapi.binance.com/futures/data/'; // /< REST endpoint for the futures API
40-
protected $fapiTestnet = 'https://testnet.binancefuture.com/fapi/'; // /< Testnet REST endpoint for the futures API
41-
protected $fapiTestnetBackup = 'https://testnet.binancefuture.com/fapi/';
40+
protected $fapiTestnet = 'https://demo-fapi.binance.com/fapi/'; // /< REST endpoint for the test futures API
41+
protected $fapiOldTestnet = 'https://testnet.binancefuture.com/fapi/'; // /< old Testnet REST endpoint for the futures API (deprecated)
4242
protected $fapiDemo = 'https://demo-fapi.binance.com/fapi/'; // /< Demo REST endpoint for the futures API
4343
protected $dapi = 'https://dapi.binance.com/dapi/'; // /< REST endpoint for the delivery API
4444
protected $dapiData = 'https://dapi.binance.com/futures/data/'; // /< REST endpoint for the delivery API
45-
protected $dapiTestnet = 'https://testnet.binancefuture.com/dapi/'; // /< Testnet REST endpoint for the delivery API
46-
protected $dapiTestnetBackup = 'https://testnet.binancefuture.com/dapi/';
45+
protected $dapiTestnet = 'https://demo-dapi.binance.com/dapi/'; // /< REST endpoint for the test delivery API
46+
protected $dapiOldTestnet = 'https://testnet.binancefuture.com/dapi/'; // /< Old Testnet REST endpoint for the delivery API (deprecated)
4747
protected $dapiDemo = 'https://demo-dapi.binance.com/dapi/'; // /< Demo REST endpoint for the delivery API
4848
protected $papi = 'https://papi.binance.com/papi/'; // /< REST endpoint for the options API
4949
protected $bapi = 'https://www.binance.com/bapi/'; // /< REST endpoint for the internal Binance API
5050
protected $stream = 'wss://stream.binance.com:9443/ws/'; // /< Endpoint for establishing websocket connections
5151
protected $streamTestnet = 'wss://testnet.binance.vision/ws/'; // /< Testnet endpoint for establishing websocket connections
5252
protected $api_key; // /< API key that you created in the binance website member area
5353
protected $api_secret; // /< API secret that was given to you when you created the api key
54-
protected $useTestnet = false; // /< Enable/disable testnet
55-
protected $useDemo = false; // /< Use demo endpoints for testnet
54+
protected $useTestnet = false; // /< Enable/disable test url
55+
protected $useOldTestnet = false; // /< Enable/disable old testnet url
5656
protected $depthCache = []; // /< Websockets depth cache
5757
protected $depthQueue = []; // /< Websockets depth queue
5858
protected $chartQueue = []; // /< Websockets chart queue
@@ -91,7 +91,6 @@ class API
9191
* 1 argument - file to load config from
9292
* 2 arguments - api key and api secret
9393
* 3 arguments - api key, api secret and use testnet flag
94-
* 4 arguments - api key, api secret, use testnet flag and use demo for testnet flag
9594
*
9695
* @return null
9796
*/
@@ -118,13 +117,6 @@ public function __construct()
118117
$this->api_secret = $param[1];
119118
$this->useTestnet = (bool)$param[2];
120119
break;
121-
case 4:
122-
$useDemo = (bool)$param[3];
123-
$this->api_key = $param[0];
124-
$this->api_secret = $param[1];
125-
$this->useTestnet = (bool)$param[2];
126-
$this->enableDemoTrading($useDemo);
127-
break;
128120
default:
129121
echo 'Please see valid constructors here: https://github.com/jaggedsoft/php-binance-api/blob/master/examples/constructor.php';
130122
}
@@ -138,25 +130,38 @@ public function __construct()
138130
public function enableDemoTrading(?bool $enable = true)
139131
{
140132
if ($enable) {
141-
$this->setDemoEndpoints();
133+
$this->setDemoForTestnet();
134+
} else {
135+
$this->setOldUrlForTestnet();
136+
}
137+
}
138+
139+
/**
140+
* enableOldTestnetTrading - Enable or disable old testnet trading endpoints for testnet
141+
*
142+
* @param bool $enable true to enable old testnet trading endpoints, false to disable
143+
*/
144+
public function enableOldTestnetTrading(?bool $enable = true)
145+
{
146+
if ($enable) {
147+
$this->setOldUrlForTestnet();
142148
} else {
143-
$this->setTestnetEndpoints();
149+
$this->setDemoForTestnet();
144150
}
145-
$this->useDemo = $enable;
146151
}
147152

148-
protected function setDemoEndpoints()
153+
protected function setDemoForTestnet()
149154
{
150155
$this->baseTestnet = $this->baseDemo;
151156
$this->fapiTestnet = $this->fapiDemo;
152157
$this->dapiTestnet = $this->dapiDemo;
153158
}
154159

155-
protected function setTestnetEndpoints()
160+
protected function setOldUrlForTestnet()
156161
{
157-
$this->baseTestnet = $this->baseTestnetBackup;
158-
$this->fapiTestnet = $this->fapiTestnetBackup;
159-
$this->dapiTestnet = $this->dapiTestnetBackup;
162+
$this->baseTestnet = $this->baseOldTestnet;
163+
$this->fapiTestnet = $this->fapiOldTestnet;
164+
$this->dapiTestnet = $this->dapiOldTestnet;
160165
}
161166

162167
/**
@@ -208,7 +213,7 @@ protected function setupApiConfigFromFile(?string $file = null)
208213
$this->api_key = isset($contents['api-key']) ? $contents['api-key'] : "";
209214
$this->api_secret = isset($contents['api-secret']) ? $contents['api-secret'] : "";
210215
$this->useTestnet = isset($contents['use-testnet']) ? (bool)$contents['use-testnet'] : false;
211-
$this->useDemo = isset($contents['use-demo']) ? (bool)$contents['use-demo'] : false;
216+
$this->useTestnet = isset($contents['use-demo']) ? (bool)$contents['use-demo'] : false;
212217
}
213218

214219
/**

0 commit comments

Comments
 (0)