Jump to content
wertmandu

Lightstreamer - Attempting to stream Offer and Bid Prices, but no luck.

Recommended Posts

Hello World.

I have been lurking and going over old forum posts for the past few weeks and have been able to begin to delve into the Gain API. I have a primarily php project that stores username and session keys on login and so far have gotten GET and POST url requests done, but I am still having trouble with getting a lightstreamer to subscribe to a stream for showing bid and ask prices.

So far for the body I want the Bid and Ask/Offer Prices to appear at the head of a table with the code for that below here:

<table>
	<tr>                               
        <td>Currency Selected: <?php print_r($_SESSION["currency_pair"]);?>
        </td>
                                             
		<td>
            <div id="marketID" data-source="lightstreamer" data-grid="stocks" name="Offer"
			data-field="Offer" data-item="item1"></div>
		</td>
                                             
		<td>
			<div id="marketID" data-source="lightstreamer" data-grid="stocks" data-item="item1" name="Bid"
			data-field="Bid"></div>
		</td>
	</tr>
</table>

As for my lightstreamer client code I have that at the bottom of the page like this:

<script src="assets/js/require.js"></script>
    <script src="assets/js/lightstreamer.js"></script>


	<script>
	define("js/lsClient", ["LightstreamerClient", "StatusWidget"], function(LightstreamerClient, StatusWidget) {
        var protocolToUse = document.location.protocol != "file:" ? document.location.protocol : "http:";
        var portToUse = document.location.protocol == "https:" ? "443" : "80";
        //
        //

        var lsClient = new LightstreamerClient(protocolToUse + "//push.lightstreamer.com:" + portToUse,
            "DEMO");

        lsClient.connectionSharing.enableSharing("OnlineDemoCommonConnection", "ATTACH", "CREATE");
        lsClient.addListener(new StatusWidget("left", "0px", true));
        lsClient.connect();

        return lsClient;
    });
	</script>
    
	<script>
		require(["LightstreamerClient","Subscription","StaticGrid"],function(LightstreamerClient,Subscription,StaticGrid) {
			//var ls = require(['lightstreamer-client']); 

			var lsClient = new LightstreamerClient("https://push.cityindex.com", "STREAMINGALL");
			lsClient.connectionDetails.setUser("<?php echo $_SESSION["username"]?>");
			lsClient.connectionDetails.setPassword("<?php echo $_SESSION["login_session"]?>");
			lsClient.connect();
			var stocksGrid = new StaticGrid("stocks",true);
			stocksGrid.setAutoCleanBehavior(true,false);
			stocksGrid.addListener({
			onVisualUpdate: function(key,info) {
				if (info == null) {
				//cleaning
				return;
				}
				var cold = (key.substring(4) % 2 == 1) ? "#eeeeee" : "#ddddee";
				info.setAttribute("yellow", cold, "backgroundColor");
			}
			});
			var marketId = "401484317";
			var stockSubscription = new Subscription("MERGE", ["PRICE."+ marketID], ["Bid", "Offer"], true);
			stockSubscription.addListener(stocksGrid);
			//stockSubscription.setItems(["PRICE.99588"])
			stockSubscription.setDataAdapter("PRICES");
			stockSubscription.setRequestedSnapshot("yes");
			lsClient.subscribe(stockSubscription);
		});
    </script>

But whenever I run it on a local instance for testing, I receive an error in my Chrome Console stating that "IllegalArgumentException", message: "An item name cannot contain spaces". I feel like I am missing something extremely obvious but I have been trying small tweaks for hours. I would like an outside perspective to help see what I have missed.

Share this post


Link to post

Hello,

For Lightstreamer queries, you may find the Lightstreamer forums are more helpful in resolving your queries - https://forums.lightstreamer.com/.

Additionally, take a look at the Lightstreamer PHP "Hellow World" example project on Github: https://github.com/Lightstreamer/Lightstreamer-example-HelloWorld-adapter-php.

Kind Regards, PM

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×