Class: IGMarkets::CLI::Positions

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

Overview

Implements the ‘ig_markets positions` command.

Instance Method Summary collapse

Instance Method Details

#close(deal_id) ⇒ Object



82
83
84
85
86
# File 'lib/ig_markets/cli/commands/positions_command.rb', line 82

def close(deal_id)
  with_position(deal_id) do |position|
    position.close position_attributes
  end
end

#close_allObject



93
94
95
96
97
98
99
100
101
# File 'lib/ig_markets/cli/commands/positions_command.rb', line 93

def close_all
  Main.begin_session(options) do |dealing_platform|
    dealing_platform.positions.all.each do |position|
      deal_reference = position.close position_attributes

      Main.report_deal_confirmation deal_reference
    end
  end
end

#createObject



51
52
53
54
55
56
57
# File 'lib/ig_markets/cli/commands/positions_command.rb', line 51

def create
  Main.begin_session(options) do |dealing_platform|
    deal_reference = dealing_platform.positions.create position_attributes

    Main.report_deal_confirmation deal_reference
  end
end

#listObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ig_markets/cli/commands/positions_command.rb', line 9

def list
  Main.begin_session(options) do |dealing_platform|
    positions = dealing_platform.positions.all.reject do |position|
      position.market.instrument_type == :binary
    end

    positions_table = Tables::PositionsTable.new positions, aggregate: options[:aggregate]

    puts positions_table

    print_position_totals positions
  end
end

#update(deal_id) ⇒ Object



67
68
69
70
71
# File 'lib/ig_markets/cli/commands/positions_command.rb', line 67

def update(deal_id)
  with_position(deal_id) do |position|
    position.update position_attributes
  end
end