Class: IGMarkets::DealingPlatform::WatchlistMethods

Inherits:
Object
  • Object
show all
Defined in:
lib/ig_markets/dealing_platform/watchlist_methods.rb

Overview

Provides methods for working with watchlists. Returned by #watchlists.

Instance Method Summary collapse

Constructor Details

#initialize(dealing_platform) ⇒ WatchlistMethods

Initializes this helper class with the specified dealing platform.

Parameters:



8
9
10
# File 'lib/ig_markets/dealing_platform/watchlist_methods.rb', line 8

def initialize(dealing_platform)
  @dealing_platform = WeakRef.new dealing_platform
end

Instance Method Details

#[](watchlist_id) ⇒ Watchlist

Returns the watchlist that has the specified ID, or ‘nil` if there is no watchlist with that ID.

Parameters:

  • watchlist_id (String)

    The ID of the watchlist to return.

Returns:



26
27
28
29
30
# File 'lib/ig_markets/dealing_platform/watchlist_methods.rb', line 26

def [](watchlist_id)
  all.detect do |watchlist|
    watchlist.id == watchlist_id
  end
end

#allArray<Watchlist>

Returns all watchlists.

Returns:



15
16
17
18
19
# File 'lib/ig_markets/dealing_platform/watchlist_methods.rb', line 15

def all
  result = @dealing_platform.session.get('watchlists').fetch :watchlists

  @dealing_platform.instantiate_models Watchlist, result
end

#create(name, *epics) ⇒ Watchlist

Creates and returns a new watchlist with a name and an initial set of markets.

Returns:



35
36
37
38
39
# File 'lib/ig_markets/dealing_platform/watchlist_methods.rb', line 35

def create(name, *epics)
  result = @dealing_platform.session.post 'watchlists', name: name, epics: epics.flatten

  self[result.fetch(:watchlist_id)]
end