connect ('ws.pusherapp.com', 443, $Socket::TYPE_TCP, true); $Socket->pipeStream ($Websocket, true, function (qcEvents_Socket $Socket, $Status) use ($Websocket) { if (!$Status) die ('Websocket-Connection failed' . "\n"); // Subscribe to live-trades-channel $JSON = array ( 'event' => 'pusher:subscribe', 'data' => array ( 'auth' => null, 'channel_data' => null, 'channel' => 'live_trades', ), ); $Websocket->sendMessage (new qcEvents_Stream_Websocket_Message ($Websocket, 0x01, json_encode ($JSON))); }); $Websocket->addHook ('websocketMessage', function (qcEvents_Stream_Websocket $Websocket, qcEvents_Stream_Websocket_Message $Message) { // Check if it's a text-message if ($Message->getOpcode () != 0x01) return; // Try to parse the pusher-event $JSON = json_decode ($Message->getData ()); // Filter for trade-events if ($JSON->event != 'trade') return; // Read the trade $Trade = json_decode ($JSON->data); // Output the trade echo $Trade->amount_str, ' BTC at ', $Trade->price_str, ' USD', "\n"; }); $Base->loop (); ?>