Class: IGMarkets::DealingPlatform::WatchlistMethods
- Inherits:
-
Object
- Object
- IGMarkets::DealingPlatform::WatchlistMethods
- Defined in:
- lib/ig_markets/dealing_platform/watchlist_methods.rb
Overview
Provides methods for working with watchlists. Returned by #watchlists.
Instance Method Summary collapse
-
#[](watchlist_id) ⇒ Watchlist
Returns the watchlist that has the specified ID, or
nilif there is no watchlist with that ID. -
#all ⇒ Array<Watchlist>
Returns all watchlists.
-
#create(name, *epics) ⇒ Watchlist
Creates and returns a new watchlist with a name and an initial set of markets.
-
#initialize(dealing_platform) ⇒ WatchlistMethods
constructor
Initializes this helper class with the specified dealing platform.
Constructor Details
#initialize(dealing_platform) ⇒ WatchlistMethods
Initializes this helper class with the specified dealing platform.
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.
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 |
#all ⇒ Array<Watchlist>
Returns all watchlists.
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.
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 |