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.

Parameters:



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.

Parameters:

  • deal_id (String)

    The deal ID of the working order to return.

Returns:



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

#allArray<WorkingOrder>

Returns all working orders.

Returns:



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.

Parameters:

  • attributes (Hash)

    The attributes for the new working order.

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 (Time)

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

  • :force_open (Boolean)

    Whether a force open is required. Defaults to false.

  • :good_till_date (Time)

    The date that the working order will live till. Must be set if :time_in_force is :good_till_date.

  • :guaranteed_stop (Boolean)

    Whether a guaranteed stop is required. Defaults to false.

  • :level (Float)

    The level at which the order will be triggered.

  • :limit_distance (Fixnum)

    The distance away in pips to place the limit. Optional.

  • :size (Float)

    The size of the working order. Required.

  • :stop_distance (Fixnum)

    The distance away in pips to place the stop. Optional.

  • :time_in_force (:good_till_cancelled, :good_till_date)

    The lifespan of the working order. :good_till_cancelled means the working order will live until it is explicitly cancelled. :good_till_date means the working order will live until the date specified by :good_till_date. Defaults to :good_till_cancelled.

  • :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.

Returns:



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