我正在使用Laravel框架和棘轮将Bitmex Websocket API与棘轮连接。问题是我无法创建用于在Bitmex Websocket服务器上进行身份验证的“签名” ...
我使用此code在Bitmex上进行连接,但该连接始终返回{"error":"Signature not valid."}
我不确定自己在做什么错...也许某些哈希函数不正确或其他...我试图在Internet上搜索,但没有找到任何可靠的解决方案。你们能告诉我我做错了吗?
public function positions($callback){
//this->env is "wss://testnet.bitmex.com/realtime";
$expires = strtotime('+60 minute');
$loop = Factory::create();
$react = new \React\Socket\Connector($loop);
$connector = new Connector($loop, $react);
$endpoint = 'position';
$signature = bin2hex(hash_hmac('sha256', 'GET/realtime' . $expires, $this->secret));
$apiEndPoint = $this->env . "?api-expires=$expires&api-signature=$signature&api-key=$this->apiKey";
$connector($apiEndPoint)->then(function ($ws) use ($callback, $loop, $endpoint) {
//
$ws->on('message', function ($data) use ($ws, $loop, $callback, $endpoint) {
$socketData = json_decode($data, true);
dd($socketData);
if (!array_key_exists("info", $socketData)){
dd($socketData);
}
});
$ws->on('close', function ($code = null, $reason = null) use ($loop) {
echo "WebSocket Connection closed! ({$code} - {$reason})" . PHP_EOL;
$loop->stop();
});
}, function ($e) use ($loop) {
echo "Could not connect: {$e->getMessage()}" . PHP_EOL;
$loop->stop();
});
$loop->run();
}