Running into Infinite Loop when using EventLoop::run()

Hi,

I am using below to get live feed through PHP but when I do this, I run into infinite loop and it stops responding.

use Upstox\Client\Configuration;
use Upstox\Client\Feeder\MarketDataStreamer;
use Revolt\EventLoop;

function on_open($streamer)
{
print(“Connection Established”);
$streamer->subscribe([“NSE_INDEX|Nifty 50”, “NSE_INDEX|Bank Nifty”], “full”);
}

function on_message($streamer, $data)
{
print($data);
}

config = Configuration::getDefaultConfiguration()->setAccessToken(<ACCESS_TOKEN>);

$streamer = new MarketDataStreamer($config);

$streamer->on(“open”, ‘on_open’);
$streamer->on(“message”, ‘on_message’);
$streamer->connect();

EventLoop::run();

Rest assured that the following code has been tested and is sourced from Github Upstox PHP:

<?php
require_once('../tester/vendor/autoload.php'); //Change as per location of your autoload.php
use Upstox\Client\Configuration;
use Upstox\Client\Feeder\MarketDataStreamer;
use Revolt\EventLoop;

function on_message($streamer, $data)
{
    print($data);
}

$config = Configuration::getDefaultConfiguration()->setAccessToken(<ACCESS_TOKEN>);

$streamer = new MarketDataStreamer($config, ["NSE_INDEX|Nifty 50", "NSE_INDEX|Bank Nifty"], "full");

$streamer->on("message", 'on_message');
$streamer->connect();

EventLoop::run();
?>

If you encounter any issues, please provide additional information such as the output or error log for further assistance.

I get below error. It gets timedout. I use the same code which is in php. I have this code in header.php of my website

{“feeds”:{“NSE_INDEX|Bank Nifty”:{“ff”:{“marketFF”:{“ltpc”:{},“marketLevel”:{},“optionGreeks”:{},“marketOHLC”:{},“eFeedDetails”:{}}}},“NSE_INDEX|Nifty 50”:{“ff”:{“indexFF”:{“ltpc”:{“ltp”:22753.799999999999,“ltt”:“1712745000000”,“cp”:22642.75},“marketOHLC”:{“ohlc”:[{“interval”:“1d”,“open”:22720.25,“high”:22775.700000000001,“low”:22673.700000000001,“close”:22753.799999999999,“ts”:“1712687400000”},{“interval”:“I1”,“open”:22739.349999999999,“high”:22741.650000000001,“low”:22730.599999999999,“close”:22735.049999999999,“ts”:“1712743140000”},{“interval”:“I1”,“open”:22735.049999999999,“high”:22735.049999999999,“low”:22735.049999999999,“close”:22735.049999999999,“ts”:“1712743200000”},{“interval”:“I30”,“open”:22744.099999999999,“high”:22775.700000000001,“low”:22729.849999999999,“close”:22752,“ts”:“1712740500000”},{“interval”:“I30”,“open”:22753.75,“high”:22755.650000000001,“low”:22730.599999999999,“close”:22735.049999999999,“ts”:“1712742300000”}]},“yh”:22775.700000000001,“yl”:17553.950000000001}}}}}
Fatal error : Maximum execution time of 120 seconds exceeded in C:\xampp\htdocs\m2dstocks\vendor\revolt\event-loop\src\EventLoop\Driver\StreamSelectDriver.php on line 254

Also is there a java script web socket package? like in zerdha we had a javascript websocket called ticker.js. we need to include that in the file and then subscribe to instrument.

Yes there is javascript websocket by upstox Upstox Nodejs SDK and React Websocket

No, this is using nodejs. I was asking about plain javascript? Also is the api documentations totally outdated? I followed the steps for PHP as well as JS, and resulted in errors. Please see errors for nodejs

Isn’t that easy to integrate as we follow clear steps in documentation as have in other brokers? Can you please share updated and WORKING copy of API documentation? Also can you please help with above bugs?

any update on this ?

To execute the code in the browser, please refer to the react_websocket at the same GitHub link:

Please give it a try and let us know how it goes.