Ruby Lightstreamer Client Gem

Gem Build Status Test Coverage Code Climate Dependencies Documentation License

Easily interface with a Lightstreamer service from Ruby. Written against the official API specification.

License

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

Installation

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 snippet demonstrates how to setup a Lightstreamer session, a subscription, then print streaming output as it comes in.

require 'lightstreamer'

# Create a new session that connects to the Lightstreamer demo server, which needs no authentication
session = Lightstreamer::Session.new server_url: 'http://push.lightstreamer.com',
                                     adapter_set: 'DEMO', username: '', password: ''

# Connect the session
session.connect

# Create a new subscription that subscribes to thirty items and to four fields on each item
subscription = Lightstreamer::Subscription.new items: (1..30).map { |i| "item#{i}" },
                                               fields: [:ask, :bid, :stock_name, :time],
                                               mode: :merge, adapter: 'QUOTE_ADAPTER'

# 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.add_data_callback do |subscription, item_name, item_data, new_values|
  queue.push item_data
end

# Activate the subscription
session.subscribe subscription

# Loop printing out 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]}"
end

Usage — Command-Line Client

This gem provides a simple command-line client that can connect to a Lightstreamer server, activate a subscription, then print streaming output from the server as it becomes available.

To print streaming data from the demo server run the following command:

lightstreamer --server-url http://push.lightstreamer.com --adapter-set DEMO --adapter QUOTE_ADAPTER \
              --items item1 item2 item3 item4 item5 --fields ask bid stock_name time

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

lightstreamer help stream

Documentation

API documentation is available here.

Contributors

Gem created by Richard Viney. All contributions welcome.