Class: IGMarkets::DealingPlatform::WorkingOrderMethods

Inherits:
Object
  • Object
show all
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

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 = WeakRef.new 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

#allArray<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.

Options Hash (attributes):

  • :currency_code (String)

    The 3 character currency code, must be one of the instrument's currencies (see Instrument#currencies). Required.

  • :direction (:buy, :sell)

    Order direction. Required.

  • :epic (String)

    The EPIC of the instrument for the order. Required.

  • :expiry (Date)

    The expiry date of the instrument (if applicable). Optional.

  • :force_open (Boolean)

    Whether a force open is required. Defaults to true.

  • :good_till_date (Time)

    The date that the working order will live till. If not specified then the working order will remain until it is cancelled.

  • :guaranteed_stop (Boolean)

    Whether a guaranteed stop is required. Defaults to false.

  • :level (Float)

    The level at which the order will be triggered. Required.

  • :limit_distance (Integer)

    The distance away in pips to place the limit. If this is set then the :limit_level option must be omitted. Optional.

  • :limit_level (Float)

    The level at which to place the limit. If this is set then the :limit_distance option must be omitted. Optional.

  • :size (Float)

    The size of the working order. Required.

  • :stop_distance (Integer)

    The distance away in pips to place the stop. If this is set then the :stop_level option must be omitted. Optional.

  • :stop_level (Float)

    The level at which to place the stop. If this is set then the :stop_distance option must be omitted. Optional.

  • :type (:limit, :stop)

    :limit means the working order is intended to buy at a price lower than at present, or to sell at a price higher than at present, i.e. there is an expectation of a market reversal at the specified :level. :stop means the working order is intended to sell at a price lower than at present, or to buy at a price higher than at present, i.e. there is no expectation of a market reversal at the specified :level. Required.


64
65
66
67
68
69
70
# File 'lib/ig_markets/dealing_platform/working_order_methods.rb', line 64

def create(attributes)
  model = WorkingOrderCreateAttributes.new attributes

  body = RequestBodyFormatter.format model, expiry: '-'

  @dealing_platform.session.post('workingorders/otc', body, API_V2).fetch :deal_reference
end