Bybit API V5获取交易历史返回空列表问题求助
Bybit API V5获取交易历史返回空列表问题求助
各位好,我最近在对接Bybit API V5,想拉取自己的交易历史,但遇到了个棘手的问题:调用交易历史接口一直返回空列表,可是调用钱包余额的接口却完全正常。
我写了下面这段PHP代码,getBybitWalletBalance函数能顺利拿到钱包数据,但getBybitTradeHistory函数不管传哪个分类参数(比如我试了linear),返回结果里的list都是空数组。我上个月明明在BTCUSDT永续合约有过交易,而且换了其他分类参数测试,结果也一样是空的。
我的代码如下:
<?php $apiKey = '...'; $apiSecret = '...'; $window = "5000"; // Global function 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 function getBybitTradeHistory($category) { return bybitCurl("https://api.bybit.com/v5/execution/list?category=" . $category, bybitSignature("GET", "/v5/execution/list", "category=" . $category, "")); } // Account function 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)); ?>
调用getBybitTradeHistory("linear")后的输出结果:
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) }
有没有朋友遇到过类似的问题?或者能帮我看看代码哪里可能出问题了吗?
内容来源于stack exchange




