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.
30 31 32 33 34 |
# File 'lib/ig_markets/dealing_platform/working_order_methods.rb', line 30 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 22 23 |
# 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)) WorkingOrder.new(attributes).tap do |working_order| working_order.instance_variable_set :@dealing_platform, @dealing_platform end end end |
#create(attributes) ⇒ String
Creates a new working order with the specified attributes.
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ig_markets/dealing_platform/working_order_methods.rb', line 64 def create(attributes) attributes[:force_open] ||= false attributes[:guaranteed_stop] ||= false attributes[:time_in_force] ||= :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 |