Ruby Lightstreamer Client Gem

Gem Build Status Test Coverage Code Climate Dependencies Documentation License

Easily interface with a Lightstreamer service from Ruby with this gem, either directly through code or by using the provided command-line client. Written against the official API specification.

Includes support for:

  • Streaming and polling connections
  • All subscription modes: command, distinct, merge and raw
  • Automatic management of table content when in command mode
  • Silent subscriptions
  • Item snapshots and end-of-snapshot notifications
  • Unfiltered subscriptions and overflow notifications
  • Performing multiple subscription actions in a single request
  • Synchronous and asynchronous message sending
  • Detailed error reporting and error handling callbacks


Licensed under the MIT license. You must read and agree to its terms to use this software.


Install the latest version of the lightstreamer gem with the following command:

$ gem install lightstreamer

Usage — Library

The two primary classes that make up the public API are:

The following code demonstrates how to create a Lightstreamer session, build a subscription, then use a thread-safe queue to print streaming output as it arrives.

require 'lightstreamer'

# Create a new session that connects to the Lightstreamer demo server
session = server_url: '',
                                     adapter_set: 'DEMO', username: '', password: ''

# 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 to thirty items and to four fields on each item
subscription = session.build_subscription data_adapter: 'QUOTE_ADAPTER', mode: :merge,
                                          items: (1..30).map { |i| "item#{i}" },
                                          fields: [:ask, :bid, :stock_name, :time]

# Create a thread-safe queue
queue =

# 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[:time]} - #{data[:stock_name]} - bid: #{data[:bid]}, ask: #{data[:ask]}"

Usage — Command-Line Client

This gem provides a simple command-line client that can connect to a Lightstreamer server and display live streaming output for a set of items and fields.

To stream data from Lightstreamer's demo server run the following command:

lightstreamer --server-url --adapter-set DEMO \
              --data-adapter QUOTE_ADAPTER --mode merge --snapshot \
              --items item1 item2 item3 item4 item5 --fields ask bid stock_name

To see the full list of available options for the command-line client run the following command:

lightstreamer help stream


API documentation is available here.


Gem created by Richard Viney. All contributions welcome.