@@ -60,10 +60,6 @@ class API
60
60
protected $ requestCount = 0 ; // /< This stores the amount of API requests
61
61
protected $ httpDebug = false ; // /< If you enable this, curl will output debugging information
62
62
protected $ subscriptions = []; // /< View all websocket subscriptions
63
- protected $ btc_value = 0.00 ; // /< value of available spot assets
64
- protected $ btc_total = 0.00 ;
65
- protected $ futures_btc_value = 0.00 ; // /< value of available futures assets
66
- protected $ futures_btc_total = 0.00 ;
67
63
68
64
// /< value of available onOrder assets
69
65
@@ -1299,19 +1295,15 @@ public function depth(string $symbol, int $limit = 100)
1299
1295
*
1300
1296
* $balances = $api->balances();
1301
1297
*
1302
- * @param bool $priceData (optional) array of the symbols and their prices that balances are required for (supported only for spot)
1303
1298
* @param string $market_type (optional) market type - "spot" or "futures" (default is "spot")
1304
1299
* @param int $recvWindow (optional) the time in milliseconds to wait for the transfer to complete (not for spot)
1305
1300
* @param string $api_version (optional) not for spot - the api version to use (default is v2)
1306
1301
*
1307
1302
* @return array with error message or array of balances
1308
1303
* @throws \Exception
1309
1304
*/
1310
- public function balances ($ priceData = false , string $ market_type = 'spot ' , $ recvWindow = null , string $ api_version = 'v2 ' )
1305
+ public function balances (string $ market_type = 'spot ' , $ recvWindow = null , string $ api_version = 'v2 ' )
1311
1306
{
1312
- if (is_array ($ priceData ) === false ) {
1313
- $ priceData = false ;
1314
- }
1315
1307
$ is_spot = $ market_type === 'spot ' ;
1316
1308
$ params = [];
1317
1309
if ($ is_spot ) {
@@ -1337,7 +1329,7 @@ public function balances($priceData = false, string $market_type = 'spot', $recv
1337
1329
echo "Error: your balances were empty or unset " . PHP_EOL ;
1338
1330
return [];
1339
1331
}
1340
- return $ this ->balanceData ($ response , $ priceData , $ market_type );
1332
+ return $ this ->balanceData ($ response , $ market_type );
1341
1333
}
1342
1334
1343
1335
/**
@@ -1838,22 +1830,14 @@ public function candlesticks(string $symbol, string $interval = "5m", int $limit
1838
1830
1839
1831
/**
1840
1832
* balanceData Converts all your balances into a nice array
1841
- * If priceData is passed from $api->prices() it will add btcValue & btcTotal to each symbol
1842
- * This function sets $btc_value which is your estimated BTC value of all assets combined and $btc_total which includes amount on order
1843
- *
1844
- * $candles = $api->candlesticks("BNBBTC", "5m");
1845
1833
*
1846
- * @param $array array of your balances
1847
1834
* @param $priceData array of prices
1848
1835
* @return array containing the response
1849
1836
*/
1850
- protected function balanceData (array $ array , $ priceData , string $ marketType = 'spot ' )
1837
+ protected function balanceData (array $ array , string $ marketType = 'spot ' )
1851
1838
{
1852
1839
$ balances = [];
1853
1840
$ is_spot = $ marketType === 'spot ' ;
1854
- if (is_array ($ priceData )) {
1855
- $ btc_value = $ btc_total = 0.00 ;
1856
- }
1857
1841
if (empty ($ array ) || ($ is_spot && empty ($ array ['balances ' ]))) {
1858
1842
// WPCS: XSS OK.
1859
1843
echo "balanceData error: Please make sure your system time is synchronized: call \$api->useServerTime() before this function " . PHP_EOL ;
@@ -1878,59 +1862,8 @@ protected function balanceData(array $array, $priceData, string $marketType = 's
1878
1862
"available " => $ avaliable ,
1879
1863
"onOrder " => $ onOrder ,
1880
1864
"total " => $ total ,
1865
+ "info " => $ obj ,
1881
1866
];
1882
-
1883
- if (is_array ($ priceData ) === false ) {
1884
- continue ;
1885
- }
1886
-
1887
- if ($ total < 0.00000001 ) {
1888
- continue ;
1889
- }
1890
-
1891
- if ($ is_spot ) {
1892
- if ($ asset === 'BTC ' ) {
1893
- $ balances [$ asset ]['btcValue ' ] = $ avaliable ;
1894
- $ balances [$ asset ]['btcTotal ' ] = $ total ;
1895
- $ btc_value += $ avaliable ;
1896
- $ btc_total += $ total ;
1897
- continue ;
1898
- } elseif ($ asset === 'USDT ' || $ asset === 'USDC ' || $ asset === 'PAX ' || $ asset === 'BUSD ' ) {
1899
- $ btcValue = $ avaliable / $ priceData ['BTCUSDT ' ];
1900
- $ btcTotal = $ total / $ priceData ['BTCUSDT ' ];
1901
- $ balances [$ asset ]['btcValue ' ] = $ btcValue ;
1902
- $ balances [$ asset ]['btcTotal ' ] = $ btcTotal ;
1903
- $ btc_value += $ btcValue ;
1904
- $ btc_total += $ btcTotal ;
1905
- continue ;
1906
- }
1907
-
1908
- $ symbol = $ asset . 'BTC ' ;
1909
-
1910
- if ($ symbol === 'BTCUSDT ' ) {
1911
- $ btcValue = number_format ($ avaliable / $ priceData ['BTCUSDT ' ], 8 , '. ' , '' );
1912
- $ btcTotal = number_format ($ total / $ priceData ['BTCUSDT ' ], 8 , '. ' , '' );
1913
- } elseif (isset ($ priceData [$ symbol ]) === false ) {
1914
- $ btcValue = $ btcTotal = 0 ;
1915
- } else {
1916
- $ btcValue = number_format ($ avaliable * $ priceData [$ symbol ], 8 , '. ' , '' );
1917
- $ btcTotal = number_format ($ total * $ priceData [$ symbol ], 8 , '. ' , '' );
1918
- }
1919
-
1920
- $ balances [$ asset ]['btcValue ' ] = $ btcValue ;
1921
- $ balances [$ asset ]['btcTotal ' ] = $ btcTotal ;
1922
- $ btc_value += $ btcValue ;
1923
- $ btc_total += $ btcTotal ;
1924
- }
1925
- }
1926
- if (is_array ($ priceData ) && $ is_spot ) {
1927
- uasort ($ balances , function ($ opA , $ opB ) {
1928
- if ($ opA == $ opB )
1929
- return 0 ;
1930
- return ($ opA ['btcValue ' ] < $ opB ['btcValue ' ]) ? 1 : -1 ;
1931
- });
1932
- $ this ->btc_value = $ btc_value ;
1933
- $ this ->btc_total = $ btc_total ;
1934
1867
}
1935
1868
return $ balances ;
1936
1869
}
@@ -5501,7 +5434,7 @@ public function futuresBalances($recvWindow = null, string $api_version = 'v3')
5501
5434
if ($ api_version !== 'v2 ' && $ api_version !== 'v3 ' ) {
5502
5435
throw new \Exception ('futuresBalances: api_version must be either v2 or v3 ' );
5503
5436
}
5504
- return $ this ->balances (false , 'futures ' , $ recvWindow , 'v3 ' );
5437
+ return $ this ->balances ('futures ' , $ recvWindow , 'v3 ' );
5505
5438
}
5506
5439
5507
5440
/**
0 commit comments