Jump to content

Lightstreamer Access?

Recommended Posts

Building my app with Ruby and Rails. I've been able to easily consume the REST API portion, but I am having a bit of trouble with the Lightstreamer sub. I've been getting an authentication error. I've played with it enough that it seems as though I'm touching the endpoint, but not getting through with my username/session.

So two questions:

1.) Do I need to submitted my application for approval to obtain access to the Lightstreamer portion of GC's API?

2.) Has anyone used the Lightstreamer ruby gem before?


I can post code if needed, but it's going to be based on an external library, mentioned above, that is not supported by GC or LS. Just looking for direction at the moment.



Share this post

Link to post

Hi TomG,

A quick check, for LS authentication are you sending the password as the SessionID you receive back from the REST API? For authenticating wiht LS, the username is your username as used in REST API, but the password is not your account password, it is the REST API Session ID.

That could explain the issue you are seeing?

Kind Regards, PM

Share this post

Link to post

So from what I can tell I was able to get it to authenticate correctly. I think it was just a small syntax error on my part. I am using the same username/session_id for the REST API and the Live.

Still working with this gem, it's throwing an error when starting the subscription.

require 'lightstreamer'

# Create a new session that connects to the Lightstreamer demo server
session = Lightstreamer::Session.new server_url: 'https://push.cityindex.com',
                                     adapter_set: 'STREAMINGALL', username: 'username', password: 'session_id'

# Add a simple error handler that just raises the error and so terminates the application
session.on_error do |error|
  raise error

# Connect the session

# Create a new subscription that subscribes an array of items
subscription = session.build_subscription data_adapter: 'PRICES', mode: :merge, items: ['PRICE.401484347', 'PRICE.401484392'],
                                          fields: [:MarketID, :Bid, :Offer]

# Create a thread-safe queue
queue = Queue.new

# When new data becomes available for the subscription it will be put on the queue. This callback
# will be run on a worker thread.
subscription.on_data do |subscription, item_name, item_data, new_data|
    queue.push item_data
  # Start streaming data for the subscription and request an initial snapshot
  subscription.start snapshot: true
  # Print new data as soon as it becomes available on the queue
  loop do
    data = queue.pop
    puts " #{data[:MarketId]} - Bid: #{data[:Bid]}, Ask: #{data[:Offer]}"


The above is currently throwing the following error.

Traceback (most recent call last):
	10: from testingLS.rb:30:in `<main>'
	 9: from /Users/tomg/.rvm/gems/ruby-2.6.3/gems/lightstreamer-0.16/lib/lightstreamer/subscription.rb:95:in `start'
	 8: from /Users/tomg/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/delegate.rb:83:in `method_missing'
	 7: from /Users/tomg/.rvm/gems/ruby-2.6.3/gems/lightstreamer-0.16/lib/lightstreamer/session.rb:288:in `control_request'
	 6: from /Users/tomg/.rvm/gems/ruby-2.6.3/gems/lightstreamer-0.16/lib/lightstreamer/post_request.rb:15:in `execute'
	 5: from /Users/tomg/.rvm/gems/ruby-2.6.3/gems/lightstreamer-0.16/lib/lightstreamer/post_request.rb:30:in `execute_multiple'
	 4: from /Users/tomg/.rvm/gems/ruby-2.6.3/gems/excon-0.76.0/lib/excon.rb:250:in `post'
	 3: from /Users/tomg/.rvm/gems/ruby-2.6.3/gems/excon-0.76.0/lib/excon/connection.rb:281:in `request'
	 2: from /Users/tomg/.rvm/gems/ruby-2.6.3/gems/excon-0.76.0/lib/excon/connection.rb:450:in `response'
	 1: from /Users/tomg/.rvm/gems/ruby-2.6.3/gems/excon-0.76.0/lib/excon/middlewares/response_parser.rb:12:in `response_call'
/Users/tomg/.rvm/gems/ruby-2.6.3/gems/excon-0.76.0/lib/excon/middlewares/expects.rb:13:in `response_call': Expected(200) <=> Actual(503 Service Unavailable) (Excon::Error::ServiceUnavailable)
	6: from testingLS.rb:30:in `<main>'
	5: from /Users/tomg/.rvm/gems/ruby-2.6.3/gems/lightstreamer-0.16/lib/lightstreamer/subscription.rb:95:in `start'
	4: from /Users/tomg/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/delegate.rb:83:in `method_missing'
	3: from /Users/tomg/.rvm/gems/ruby-2.6.3/gems/lightstreamer-0.16/lib/lightstreamer/session.rb:288:in `control_request'
	2: from /Users/tomg/.rvm/gems/ruby-2.6.3/gems/lightstreamer-0.16/lib/lightstreamer/post_request.rb:15:in `execute'
	1: from /Users/tomg/.rvm/gems/ruby-2.6.3/gems/lightstreamer-0.16/lib/lightstreamer/post_request.rb:29:in `execute_multiple'
/Users/tomg/.rvm/gems/ruby-2.6.3/gems/lightstreamer-0.16/lib/lightstreamer/post_request.rb:41:in `rescue in execute_multiple': Expected(200) <=> Actual(503 Service Unavailable) (Lightstreamer::Errors::ConnectionError)

Any thoughts?

Share this post

Link to post

Hi Tom,

Since Lightstreamer do not have a specific Ruby on Rails client development kit, presumably you are using the one named "Genric Client SDK"? Did you download the version of the SDK for the version of LS we are running on the server, which is 7.0.3?

Possibly some sort of incompatibility happening if you are using the latest client SDK. The client SDKs for the LS server version we run can be downloaded at: https://lightstreamer.com/download/#ls70

Kind Regards, PM

Share this post

Link to post

After some more digging it looks like the LightStreamer gem is coded against the Lightstreamer protocol rather than a particular SDK version. It also looks like the "503 Service Unavailable" error comes directly for the Gains lightstreamer?

The 503 Service Unavailable error is an HTTP status code that means the website's server is simply not available right now. Most of the time, it occurs because the server is too busy or because there's maintenance being performed on it.

My guess is there might be something missing the Gain lightstreamer server is needing in order to complete the sub?

I would like to find the missing link and not have to resort to JS or Python for my streaming (just extra overhead). Then again I don't think I'm gonna bang head against the wall too much longer lol.


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