@@ -52,7 +52,7 @@ class API
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
5454 protected $ useTestnet = false ; // /< Enable/disable testnet
55- protected $ useDemoForTestnet = false ; // /< Use demo endpoints for testnet
55+ protected $ useDemo = false ; // /< Use demo endpoints for testnet
5656 protected $ depthCache = []; // /< Websockets depth cache
5757 protected $ depthQueue = []; // /< Websockets depth queue
5858 protected $ chartQueue = []; // /< Websockets chart queue
@@ -91,6 +91,7 @@ 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
9495 *
9596 * @return null
9697 */
@@ -117,6 +118,13 @@ public function __construct()
117118 $ this ->api_secret = $ param [1 ];
118119 $ this ->useTestnet = (bool )$ param [2 ];
119120 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 ;
120128 default :
121129 echo 'Please see valid constructors here: https://github.com/jaggedsoft/php-binance-api/blob/master/examples/constructor.php ' ;
122130 }
@@ -130,15 +138,25 @@ public function __construct()
130138 public function enableDemoTrading (?bool $ enable = true )
131139 {
132140 if ($ enable ) {
133- $ this ->baseTestnet = $ this ->baseDemo ;
134- $ this ->fapiTestnet = $ this ->fapiDemo ;
135- $ this ->dapiTestnet = $ this ->dapiDemo ;
141+ $ this ->setDemoEndpoints ();
136142 } else {
137- $ this ->baseTestnet = $ this ->baseTestnetBackup ;
138- $ this ->fapiTestnet = $ this ->fapiTestnetBackup ;
139- $ this ->dapiTestnet = $ this ->dapiTestnetBackup ;
143+ $ this ->setTestnetEndpoints ();
140144 }
141- $ this ->useDemoForTestnet = $ enable ;
145+ $ this ->useDemo = $ enable ;
146+ }
147+
148+ protected function setDemoEndpoints ()
149+ {
150+ $ this ->baseTestnet = $ this ->baseDemo ;
151+ $ this ->fapiTestnet = $ this ->fapiDemo ;
152+ $ this ->dapiTestnet = $ this ->dapiDemo ;
153+ }
154+
155+ protected function setTestnetEndpoints ()
156+ {
157+ $ this ->baseTestnet = $ this ->baseTestnetBackup ;
158+ $ this ->fapiTestnet = $ this ->fapiTestnetBackup ;
159+ $ this ->dapiTestnet = $ this ->dapiTestnetBackup ;
142160 }
143161
144162 /**
@@ -190,6 +208,7 @@ protected function setupApiConfigFromFile(?string $file = null)
190208 $ this ->api_key = isset ($ contents ['api-key ' ]) ? $ contents ['api-key ' ] : "" ;
191209 $ this ->api_secret = isset ($ contents ['api-secret ' ]) ? $ contents ['api-secret ' ] : "" ;
192210 $ this ->useTestnet = isset ($ contents ['use-testnet ' ]) ? (bool )$ contents ['use-testnet ' ] : false ;
211+ $ this ->useDemo = isset ($ contents ['use-demo ' ]) ? (bool )$ contents ['use-demo ' ] : false ;
193212 }
194213
195214 /**
0 commit comments