Authorization Required with PHP
I am new with binary and WebSocket technology. I have the below code but the problem is I get Authorization Required. I understood what the problem is, but not show I know how to solve the problem.
How can I authorize and then called Balance for example?
require DIR . '/vendor/autoload.php';
$loop = \React\EventLoop\Factory::create();
$connector = new \Ratchet\Client\Connector($loop);
$connector('wss://ws.binaryws.com/websockets/v3?app_id=xxxx')->then(function ($conn) {
$conn->on('message', function ($msg) {
echo "ticks update: {$msg}\n";
$conn->close();
});
$conn->send("{\"balance\": \"1\",\"subscribe\": \"1\"}");
});
$loop->run();
Comments
You need to first authorize, and in
$conn->on('message',
check for a successful response then send the balance request.thank you so much @michael_mueller , really safe me time.
One last thing, do you know why each call is loading for almost 2minutes
Many thanks in advance
Solved the loading problem by closing the connection after getting the result. @michael_mueller thanks once again