Class: IGMarkets::Streaming::Subscription
- Inherits:
-
Object
- Object
- IGMarkets::Streaming::Subscription
- Defined in:
- lib/ig_markets/streaming/subscription.rb
Overview
This class manages a single Lightstreamer subscription used to handle streaming data. Subscriptions should always be managed using the methods provided by DealingPlatform::StreamingMethods. Data can be consumed by registering an asynchronous data callback using #on_data.
Instance Attribute Summary collapse
-
#lightstreamer_subscription ⇒ Lightstreamer::Subscription
readonly
The underlying Lightstreamer subscription instance being managed by this class.
Instance Method Summary collapse
-
#initialize(dealing_platform, lightstreamer_subscription) ⇒ Subscription
constructor
Initializes this subscription with the specified dealing platform and Lightstreamer subscription.
-
#on_data(&callback) ⇒ Object
Adds the passed block to the list of callbacks that will be run when this subscription receives new data.
-
#unsilence ⇒ Object
If this subscription was started with the ‘silent: true` option then this method can be called to unsilence the subscription and start receiving its data.
Constructor Details
#initialize(dealing_platform, lightstreamer_subscription) ⇒ Subscription
Initializes this subscription with the specified dealing platform and Lightstreamer subscription.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ig_markets/streaming/subscription.rb', line 18 def initialize(dealing_platform, lightstreamer_subscription) @dealing_platform = dealing_platform @lightstreamer_subscription = lightstreamer_subscription @lightstreamer_subscription.on_data do |subscription, item_name, item_data, new_data| on_raw_data subscription, item_name, item_data, new_data end @on_data_callbacks = [] end |
Instance Attribute Details
#lightstreamer_subscription ⇒ Lightstreamer::Subscription (readonly)
The underlying Lightstreamer subscription instance being managed by this class.
10 11 12 |
# File 'lib/ig_markets/streaming/subscription.rb', line 10 def lightstreamer_subscription @lightstreamer_subscription end |
Instance Method Details
#on_data(&callback) ⇒ Object
Adds the passed block to the list of callbacks that will be run when this subscription receives new data. The block will be called on a worker thread and so the code that is run by the block must be thread-safe. The arguments passed to the block are ‘|data, merged_data|`, and the data will be an instance of AccountUpdate, MarketUpdate, DealConfirmation, PositionUpdate, WorkingOrderUpdate, ConsolidatedChartDataUpdate or ChartTickUpdate, depending on what was subscribed to. The `merged_data` argument will be `nil` for deal confirmations, position updates, working order updates, and chart tick updates.
43 44 45 |
# File 'lib/ig_markets/streaming/subscription.rb', line 43 def on_data(&callback) @on_data_callbacks << callback end |
#unsilence ⇒ Object
If this subscription was started with the ‘silent: true` option then this method can be called to unsilence the subscription and start receiving its data.
31 32 33 |
# File 'lib/ig_markets/streaming/subscription.rb', line 31 def unsilence lightstreamer_subscription.unsilence end |