I am trying to get my trade history from the Bybit api V5, but it keeps returning an empty list although getting my wallet balance works.
I wrote this code below and although the “getBybitWalletBalance” function works perfectly, the “getBybitTradeHistory” function keeps returning an empty list. My last trade on BTCUSDT perpetuals was a month ago. I also tried the other categories, but they all give the same output.
bybit.php
<?php
$apiKey = '...';
$apiSecret = '...';
$window = "5000";
// Global
function bybitSignature($method, $path, $query, $body) {
global $apiKey, $apiSecret, $window;
$timestamp = round(microtime(true) * 1000);
if($method === "GET") {
return hash_hmac("sha256", $timestamp . $apiKey . $window . $query, $apiSecret);
} else {
return hash_hmac("sha256", $timestamp . $apiKey . $window . $body, $apiSecret);
}
}
function bybitCurl($url, $signature) {
global $apiKey, $window;
$timestamp = round(microtime(true) * 1000);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/json",
"X-BAPI-API-KEY: " . $apiKey,
"X-BAPI-TIMESTAMP: " . $timestamp,
"X-BAPI-SIGN: " . $signature,
"X-BAPI-RECV-WINDOW: " . $window
));
if(curl_errno($ch)) {
return curl_error($ch);
} else {
return curl_exec($ch);
}
curl_close($ch);
}
// Trade
function getBybitTradeHistory($category) {
return bybitCurl("https://api.bybit.com/v5/execution/list?category=" . $category, bybitSignature("GET", "/v5/execution/list", "category=" . $category, ""));
}
// Account
function getBybitWalletBalance($accountType) {
return bybitCurl("https://api.bybit.com/v5/account/wallet-balance?accountType=" . $accountType, bybitSignature("GET", "/v5/account/wallet-balance", "accountType=" . $accountType, ""));
}
var_dump(json_decode(getBybitTradeHistory("linear"), true));
?>
output
array(5) { ["retCode"]=> int(0) ["retMsg"]=> string(2) "OK" ["result"]=> array(3) { ["nextPageCursor"]=> string(0) "" ["category"]=> string(6) "linear" ["list"]=> array(0) { } } ["retExtInfo"]=> array(0) { } ["time"]=> int(1751725711326) }