Class: IGMarkets::Streaming::Subscription

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(dealing_platform, lightstreamer_subscription) ⇒ Subscription

Initializes this subscription with the specified dealing platform and Lightstreamer subscription.

Parameters:

  • dealing_platform (DealingPlatform)
  • lightstreamer_subscription (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_subscriptionLightstreamer::Subscription (readonly)

The underlying Lightstreamer subscription instance being managed by this class.

Returns:

  • (Lightstreamer::Subscription)


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.

Parameters:

  • callback (Proc)

    The callback that is to be run.



43
44
45
# File 'lib/ig_markets/streaming/subscription.rb', line 43

def on_data(&callback)
  @on_data_callbacks << callback
end

#unsilenceObject

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