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 = 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:



24
25
26
27
28
# File 'lib/ig_markets/dealing_platform/watchlist_methods.rb', line 24

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

#allArray<Watchlist>

Returns all watchlists.

Returns:



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

def all
  @dealing_platform.gather 'watchlists', :watchlists, Watchlist
end

#create(name, *epics) ⇒ Watchlist

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

Returns:



33
34
35
36
37
# File 'lib/ig_markets/dealing_platform/watchlist_methods.rb', line 33

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

  self[result.fetch(:watchlist_id)]
end