Class: IGMarkets::DealingPlatform::PositionMethods
- Inherits:
-
Object
- Object
- IGMarkets::DealingPlatform::PositionMethods
- Defined in:
- lib/ig_markets/dealing_platform/position_methods.rb
Overview
Provides methods for working with positions. Returned by #positions.
Instance Method Summary collapse
-
#[](deal_id) ⇒ Position
Returns the position with the specified deal ID, or
nilif there is no position with that ID. -
#all ⇒ Array<Position>
Returns all positions.
-
#create(attributes) ⇒ String
Creates a new position.
-
#initialize(dealing_platform) ⇒ PositionMethods
constructor
Initializes this helper class with the specified dealing platform.
Constructor Details
#initialize(dealing_platform) ⇒ PositionMethods
Initializes this helper class with the specified dealing platform.
8 9 10 |
# File 'lib/ig_markets/dealing_platform/position_methods.rb', line 8 def initialize(dealing_platform) @dealing_platform = dealing_platform end |
Instance Method Details
#[](deal_id) ⇒ Position
Returns the position with the specified deal ID, or nil if there is no position with that ID.
26 27 28 29 30 |
# File 'lib/ig_markets/dealing_platform/position_methods.rb', line 26 def [](deal_id) attributes = @dealing_platform.session.get "positions/#{deal_id}", API_V2 position_from_attributes attributes end |
#all ⇒ Array<Position>
Returns all positions.
15 16 17 18 19 |
# File 'lib/ig_markets/dealing_platform/position_methods.rb', line 15 def all @dealing_platform.session.get('positions', API_V2).fetch(:positions).map do |attributes| position_from_attributes attributes end end |
#create(attributes) ⇒ String
Creates a new position.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ig_markets/dealing_platform/position_methods.rb', line 70 def create(attributes) attributes[:force_open] = false unless attributes.key? :force_open attributes[:guaranteed_stop] = false unless attributes.key? :guaranteed_stop attributes[:order_type] ||= :market attributes[:time_in_force] = :execute_and_eliminate if attributes[:order_type] == :market model = PositionCreateAttributes.new attributes model.validate payload = PayloadFormatter.format model payload[:expiry] ||= '-' @dealing_platform.session.post('positions/otc', payload, API_V2).fetch(:deal_reference) end |