Hello, how can i get all my trades, wallets balances and earnings with an php api?
$secret = “secret”;
$key = “apikey”;
$s_time = “timestamp=”.time()*1000;
$sign=hash_hmac(‘SHA256’, $s_time, $secret);
$url = "https://data.binance.com/api/v3/trades?".$s_time.’&signature=’.$sign;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘X-MBX-APIKEY:’.$key));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
$result = json_decode($result, true);
You’ll need to leverage a few different endpoints to achieve your objective of fetching your trades, balances and earnings. In regards to the code in your post, the
trades endpoint will return recent public trades, not your own personal trades. Additionally you’re missing the required parameter:
$url = "https://data.binance.com/api/v3/trades?symbol=BTCUSDT". Additionally, it isn’t required to pass
signature for market-data endpoints.
For your intended purposes I suggest starting by taking a look at the endpoints below:
Trade History: Account Trade List
Account Balances: User Asset
In order to make your job easier, you can utilise our PHP Spot Connector in your PHP project.