Class: IGMarkets::DealingPlatform::WorkingOrderMethods
- Inherits:
-
Object
- Object
- IGMarkets::DealingPlatform::WorkingOrderMethods
- Defined in:
- lib/ig_markets/dealing_platform/working_order_methods.rb
Overview
Provides methods for working with working orders. Returned by #working_orders.
Instance Method Summary collapse
-
#[](deal_id) ⇒ WorkingOrder
Returns the working order with the specified deal ID, or
nilif there is no order with that deal ID. -
#all ⇒ Array<WorkingOrder>
Returns all working orders.
-
#create(attributes) ⇒ String
Creates a new working order with the specified attributes.
-
#initialize(dealing_platform) ⇒ WorkingOrderMethods
constructor
Initializes this helper class with the specified dealing platform.
Constructor Details
#initialize(dealing_platform) ⇒ WorkingOrderMethods
Initializes this helper class with the specified dealing platform.
8 9 10 |
# File 'lib/ig_markets/dealing_platform/working_order_methods.rb', line 8 def initialize(dealing_platform) @dealing_platform = dealing_platform end |
Instance Method Details
#[](deal_id) ⇒ WorkingOrder
Returns the working order with the specified deal ID, or nil if there is no order with that deal ID.
28 29 30 31 32 |
# File 'lib/ig_markets/dealing_platform/working_order_methods.rb', line 28 def [](deal_id) all.detect do |working_order| working_order.deal_id == deal_id end end |
#all ⇒ Array<WorkingOrder>
Returns all working orders.
15 16 17 18 19 20 21 |
# File 'lib/ig_markets/dealing_platform/working_order_methods.rb', line 15 def all @dealing_platform.session.get('workingorders', API_V2).fetch(:working_orders).map do |attributes| attributes = attributes.fetch(:working_order_data).merge market: attributes.fetch(:market_data) @dealing_platform.instantiate_models WorkingOrder, attributes end end |
#create(attributes) ⇒ String
Creates a new working order with the specified attributes.
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ig_markets/dealing_platform/working_order_methods.rb', line 58 def create(attributes) attributes[:force_open] ||= false attributes[:guaranteed_stop] ||= false attributes[:time_in_force] = attributes[:good_till_date] ? :good_till_date : :good_till_cancelled model = build_working_order_model attributes payload = PayloadFormatter.format model payload[:expiry] ||= '-' @dealing_platform.session.post('workingorders/otc', payload, API_V2).fetch(:deal_reference) end |