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 ‘nil` if 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 = WeakRef.new 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) all.detect do |position| position.deal_id == deal_id end 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 |
# File 'lib/ig_markets/dealing_platform/position_methods.rb', line 70 def create(attributes) model = PositionCreateAttributes.new attributes body = RequestBodyFormatter.format model, expiry: '-' @dealing_platform.session.post('positions/otc', body, API_V2).fetch(:deal_reference) end |