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 ‘nil` if 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 = 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.
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 |
#all ⇒ Array<Watchlist>
Returns all watchlists.
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.
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 |