Class: IGMarkets::DealingPlatform::SprintMarketPositionMethods

Inherits:
Object
  • Object
show all
Defined in:
lib/ig_markets/dealing_platform/sprint_market_position_methods.rb

Overview

Provides methods for working with sprint market positions. Returned by #sprint_market_positions.

Instance Method Summary collapse

Constructor Details

#initialize(dealing_platform) ⇒ SprintMarketPositionMethods

Initializes this helper class with the specified dealing platform.

Parameters:


8
9
10
# File 'lib/ig_markets/dealing_platform/sprint_market_position_methods.rb', line 8

def initialize(dealing_platform)
  @dealing_platform = WeakRef.new dealing_platform
end

Instance Method Details

#[](deal_id) ⇒ SprintMarketPosition

Returns the sprint market position with the specified deal ID, or nil if there is no sprint market position with that ID.

Parameters:

  • deal_id (String)

    The deal ID of the sprint market position to return.

Returns:


27
28
29
30
31
# File 'lib/ig_markets/dealing_platform/sprint_market_position_methods.rb', line 27

def [](deal_id)
  all.detect do |sprint_market_position|
    sprint_market_position.deal_id == deal_id
  end
end

#allArray<SprintMarketPosition>

Returns all sprint market positions.

Returns:


15
16
17
18
19
# File 'lib/ig_markets/dealing_platform/sprint_market_position_methods.rb', line 15

def all
  result = @dealing_platform.session.get('positions/sprintmarkets', API_V2).fetch :sprint_market_positions

  @dealing_platform.instantiate_models SprintMarketPosition, result
end

#create(attributes) ⇒ String

Creates a new sprint market position.

Parameters:

  • attributes (Hash)

    The attributes for the new sprint market position.

Options Hash (attributes):

  • :epic (String)

    The EPIC for the instrument to create a sprint market position for. Required.

  • :direction (:buy, :sell)

    The position direction. Required.

  • :expiry_period (:one_minute, :two_minutes, :five_minutes, :twenty_minutes, :sixty_minutes)

    The expiry period. Required.

  • :size (Float)

    The size of the sprint market position to create. Required.

Returns:


44
45
46
47
48
# File 'lib/ig_markets/dealing_platform/sprint_market_position_methods.rb', line 44

def create(attributes)
  body = RequestBodyFormatter.format SprintMarketPositionCreateAttributes.new(attributes)

  @dealing_platform.session.post('positions/sprintmarkets', body).fetch :deal_reference
end