Skip to content

Commit eceec92

Browse files
authored
feat: demo-trading support added
1 parent 5539e0a commit eceec92

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

php-binance-api.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,28 @@ class API
3131
{
3232
protected $base = 'https://api.binance.com/api/'; // /< REST endpoint for the currency exchange
3333
protected $baseTestnet = 'https://testnet.binance.vision/api/'; // /< Testnet REST endpoint for the currency exchange
34+
protected $baseTestnetBackup = 'https://testnet.binance.vision/api/';
35+
protected $baseDemo = 'https://demo-api.binance.com/api/'; // /< Demo REST endpoint for the currency exchange
3436
protected $wapi = 'https://api.binance.com/wapi/'; // /< REST endpoint for the withdrawals
3537
protected $sapi = 'https://api.binance.com/sapi/'; // /< REST endpoint for the supporting network API
3638
protected $fapi = 'https://fapi.binance.com/fapi/'; // /< REST endpoint for the futures API
3739
protected $fapiData = 'https://fapi.binance.com/futures/data/'; // /< REST endpoint for the futures API
3840
protected $fapiTestnet = 'https://testnet.binancefuture.com/fapi/'; // /< Testnet REST endpoint for the futures API
41+
protected $fapiTestnetBackup = 'https://testnet.binancefuture.com/fapi/';
42+
protected $fapiDemo = 'https://demo-fapi.binance.com/fapi/'; // /< Demo REST endpoint for the futures API
3943
protected $dapi = 'https://dapi.binance.com/dapi/'; // /< REST endpoint for the delivery API
4044
protected $dapiData = 'https://dapi.binance.com/futures/data/'; // /< REST endpoint for the delivery API
4145
protected $dapiTestnet = 'https://testnet.binancefuture.com/dapi/'; // /< Testnet REST endpoint for the delivery API
46+
protected $dapiTestnetBackup = 'https://testnet.binancefuture.com/dapi/';
47+
protected $dapiDemo = 'https://demo-dapi.binance.com/dapi/'; // /< Demo REST endpoint for the delivery API
4248
protected $papi = 'https://papi.binance.com/papi/'; // /< REST endpoint for the options API
4349
protected $bapi = 'https://www.binance.com/bapi/'; // /< REST endpoint for the internal Binance API
4450
protected $stream = 'wss://stream.binance.com:9443/ws/'; // /< Endpoint for establishing websocket connections
4551
protected $streamTestnet = 'wss://testnet.binance.vision/ws/'; // /< Testnet endpoint for establishing websocket connections
4652
protected $api_key; // /< API key that you created in the binance website member area
4753
protected $api_secret; // /< API secret that was given to you when you created the api key
48-
protected $useTestnet = false; // /< Enable/disable testnet (https://testnet.binance.vision/)
54+
protected $useTestnet = false; // /< Enable/disable testnet
55+
protected $useDemoForTestnet = false; // /< Use demo endpoints for testnet
4956
protected $depthCache = []; // /< Websockets depth cache
5057
protected $depthQueue = []; // /< Websockets depth queue
5158
protected $chartQueue = []; // /< Websockets chart queue
@@ -115,6 +122,23 @@ public function __construct()
115122
}
116123
}
117124

125+
/**
126+
*
127+
*/
128+
public function enableDemoTrading(?bool $enable = true)
129+
{
130+
if ($enable) {
131+
$this->baseTestnet = $this->baseDemo;
132+
$this->fapiTestnet = $this->fapiDemo;
133+
$this->dapiTestnet = $this->dapiDemo;
134+
} else {
135+
$this->baseTestnet = $this->baseTestnetBackup;
136+
$this->fapiTestnet = $this->fapiTestnetBackup;
137+
$this->dapiTestnet = $this->dapiTestnetBackup;
138+
}
139+
$this->useDemoForTestnet = $enable;
140+
}
141+
118142
/**
119143
* magic get for protected and protected members
120144
*
@@ -1674,6 +1698,10 @@ protected function httpRequest(string $url, string $method = "GET", array $param
16741698
$base = $this->bapi;
16751699
}
16761700

1701+
print_r(PHP_EOL . '-----------------------------------------' . PHP_EOL);
1702+
print_r($base . $url);
1703+
print_r(PHP_EOL . '-----------------------------------------' . PHP_EOL);
1704+
16771705
$curl = curl_init();
16781706
curl_setopt($curl, CURLOPT_VERBOSE, $this->httpDebug);
16791707

0 commit comments

Comments
 (0)