Class: IGMarkets::WorkingOrder

Inherits:
Model
  • Object
show all
Defined in:
lib/ig_markets/working_order.rb

Overview

Contains details on a working order. Returned by DealingPlatform::WorkingOrderMethods#all and DealingPlatform::WorkingOrderMethods#[].

Instance Attribute Summary

Attributes inherited from Model

#attributes

Instance Method Summary collapse

Methods inherited from Model

#==, allowed_values, attribute, attribute_type, attribute_value_allowed?, defined_attribute_names, deprecated_attribute, #initialize, #initialize_copy, #inspect, #to_h, valid_attribute?

Constructor Details

This class inherits a constructor from IGMarkets::Model

Instance Method Details

#created_date_utcTime

The created_date_utc attribute.

Returns:

  • (Time)


5
# File 'lib/ig_markets/working_order.rb', line 5

attribute :created_date_utc, Time, format: '%FT%T'

#currency_codeString

The currency_code attribute.

Returns:

  • (String)


6
# File 'lib/ig_markets/working_order.rb', line 6

attribute :currency_code, String, regex: Regex::CURRENCY

#deal_idObject

The deal_id attribute.

Returns:



7
# File 'lib/ig_markets/working_order.rb', line 7

attribute :deal_id

#deleteString

Deletes this working order.

Returns:



34
35
36
# File 'lib/ig_markets/working_order.rb', line 34

def delete
  @dealing_platform.session.delete("workingorders/otc/#{deal_id}", nil, API_V2).fetch(:deal_reference)
end

#directionSymbol

The direction attribute.

Returns:

  • (Symbol)


8
# File 'lib/ig_markets/working_order.rb', line 8

attribute :direction, Symbol, allowed_values: %i[buy sell]

#dmaBoolean

The dma attribute.

Returns:



9
# File 'lib/ig_markets/working_order.rb', line 9

attribute :dma, Boolean

#epicString

The epic attribute.

Returns:

  • (String)


10
# File 'lib/ig_markets/working_order.rb', line 10

attribute :epic, String, regex: Regex::EPIC

#good_till_dateTime

The good_till_date attribute.

Returns:

  • (Time)


11
# File 'lib/ig_markets/working_order.rb', line 11

attribute :good_till_date, Time, format: '%Y/%m/%d %R'

#guaranteed_stopBoolean

The guaranteed_stop attribute.

Returns:



12
# File 'lib/ig_markets/working_order.rb', line 12

attribute :guaranteed_stop, Boolean

#limit_distanceInteger

The limit_distance attribute.

Returns:

  • (Integer)


13
# File 'lib/ig_markets/working_order.rb', line 13

attribute :limit_distance, Integer

#limited_risk_premiumLimitedRiskPremium

The limited_risk_premium attribute.

Returns:



14
# File 'lib/ig_markets/working_order.rb', line 14

attribute :limited_risk_premium, LimitedRiskPremium

#marketMarketOverview

The market attribute.

Returns:



21
# File 'lib/ig_markets/working_order.rb', line 21

attribute :market, MarketOverview

#order_levelFloat

The order_level attribute.

Returns:

  • (Float)


15
# File 'lib/ig_markets/working_order.rb', line 15

attribute :order_level, Float

#order_sizeFloat

The order_size attribute.

Returns:

  • (Float)


16
# File 'lib/ig_markets/working_order.rb', line 16

attribute :order_size, Float

#order_typeSymbol

The order_type attribute.

Returns:

  • (Symbol)


17
# File 'lib/ig_markets/working_order.rb', line 17

attribute :order_type, Symbol, allowed_values: %i[limit stop]

#reloadObject

Reloads this working order’s attributes by re-querying the IG Markets API.



26
27
28
# File 'lib/ig_markets/working_order.rb', line 26

def reload
  self.attributes = @dealing_platform.working_orders[deal_id].attributes
end

#stop_distanceInteger

The stop_distance attribute.

Returns:

  • (Integer)


18
# File 'lib/ig_markets/working_order.rb', line 18

attribute :stop_distance, Integer

#time_in_forceSymbol

The time_in_force attribute.

Returns:

  • (Symbol)


19
# File 'lib/ig_markets/working_order.rb', line 19

attribute :time_in_force, Symbol, allowed_values: %i[good_till_cancelled good_till_date]

#update(new_attributes) ⇒ String

Updates this working order. No attributes are mandatory, and any attributes not specified will be kept at their current values.

Parameters:

Options Hash (new_attributes):

  • :good_till_date (Time)
  • :level (Float)
  • :limit_distance (Integer)
  • :limit_level (Float)
  • :stop_distance (Integer)
  • :stop_level (Float)
  • :type (:limit, :stop)

Returns:



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ig_markets/working_order.rb', line 53

def update(new_attributes)
  existing_attributes = { good_till_date: good_till_date, level: order_level, limit_distance: limit_distance,
                          stop_distance: stop_distance, time_in_force: time_in_force, type: order_type }

  model = WorkingOrderUpdateAttributes.new existing_attributes, new_attributes
  model.validate

  body = RequestBodyFormatter.format model

  @dealing_platform.session.put("workingorders/otc/#{deal_id}", body, API_V2).fetch(:deal_reference)
end