Class: IGMarkets::CLI::Positions
- Inherits:
-
Thor
- Object
- Thor
- IGMarkets::CLI::Positions
- Defined in:
- lib/ig_markets/cli/commands/positions_command.rb
Overview
Implements the ‘ig_markets positions` command.
Instance Method Summary collapse
- #close(deal_id) ⇒ Object
- #close_all ⇒ Object
- #create ⇒ Object
- #list ⇒ Object
- #update(deal_id) ⇒ Object
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_all ⇒ Object
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() 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 |
#create ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/ig_markets/cli/commands/positions_command.rb', line 51 def create Main.begin_session() do |dealing_platform| deal_reference = dealing_platform.positions.create position_attributes Main.report_deal_confirmation deal_reference end end |
#list ⇒ Object
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() do |dealing_platform| positions = dealing_platform.positions.all.reject do |position| position.market.instrument_type == :binary end positions_table = Tables::PositionsTable.new positions, aggregate: [: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 |