Class: IGMarkets::CLI::Watchlists

Inherits:
Thor
  • Object
show all
Defined in:
lib/ig_markets/cli/commands/watchlists_command.rb

Overview

Implements the ‘ig_markets watchlists` command.

Instance Method Summary collapse

Instance Method Details

#add_markets(watchlist_id, *epics) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/ig_markets/cli/commands/watchlists_command.rb', line 32

def add_markets(watchlist_id, *epics)
  with_watchlist(watchlist_id) do |watchlist|
    epics.each do |epic|
      watchlist.add_market epic
    end
  end
end

#create(name, *epics) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/ig_markets/cli/commands/watchlists_command.rb', line 22

def create(name, *epics)
  Main.begin_session(options) do |dealing_platform|
    new_watchlist = dealing_platform.watchlists.create(name, *epics)

    puts "New watchlist ID: #{new_watchlist.id}"
  end
end

#delete(watchlist_id) ⇒ Object



52
53
54
# File 'lib/ig_markets/cli/commands/watchlists_command.rb', line 52

def delete(watchlist_id)
  with_watchlist(watchlist_id, &:delete)
end

#listObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/ig_markets/cli/commands/watchlists_command.rb', line 7

def list
  Main.begin_session(options) do |dealing_platform|
    dealing_platform.watchlists.all.each_with_index do |watchlist, index|
      table = Tables::MarketOverviewsTable.new watchlist.markets, title: table_title(watchlist)

      puts '' if index.positive?
      puts table
    end
  end
end

#remove_markets(watchlist_id, *epics) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/ig_markets/cli/commands/watchlists_command.rb', line 42

def remove_markets(watchlist_id, *epics)
  with_watchlist(watchlist_id) do |watchlist|
    epics.each do |epic|
      watchlist.remove_market epic
    end
  end
end