I'm using the Binance REST API to get previous trade information:
Endpoint: https://api.binance.com/api/v1/trades?symbol=BTCUSDT
$btc_trades = file_get_contents('https://api.binance.com/api/v1/trades?symbol=BTCUSDT');
$btc_trades = json_decode($btc_trades, true);
$five_minutes_ago = strtotime('-5 minutes');
echo "five minutes ago: " . $five_minutes_ago . "<br><br>";
foreach ($btc_trades as $btc_trade) {
$btc_trade_time = strtotime($btc_trade['time']);
$btc_trade_total = $btc_trade['qty'] * $btc_trade['price'];
if ($btc_trade_time >= $five_minutes_ago) {
$btc_trade_time = $btc_trade['time'];
echo "Time: " . $btc_trade_time . "<br>";
echo "Qty: " . $btc_trade['qty'] . "<br>";
echo "Price: $" . $btc_trade['price'] . "<br>";
echo "Total: " . $btc_trade_total . "<br><br>";
}
}
I can confirm by testing that there are trades returned that meet the condition (happened less than five minutes ago) however nothing is returned in this case.
Are the timestamps formatted differently? It seems as if I have everything correct.
From Binance API (https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md):
All time and timestamp related fields are in milliseconds.
Thanks for the help!
change to
$btc_trade_time = $btc_trade['time']/1000