Class: Tastytrade::Models::BuyingPowerEffect

Inherits:
Base
  • Object
show all
Defined in:
lib/tastytrade/models/buying_power_effect.rb

Overview

Represents the buying power effect from a dry-run order or order placement

Instance Attribute Summary collapse

Attributes inherited from Base

#data

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Tastytrade::Models::Base

Instance Attribute Details

#change_in_buying_powerObject (readonly)

Returns the value of attribute change_in_buying_power.



9
10
11
# File 'lib/tastytrade/models/buying_power_effect.rb', line 9

def change_in_buying_power
  @change_in_buying_power
end

#change_in_margin_requirementObject (readonly)

Returns the value of attribute change_in_margin_requirement.



9
10
11
# File 'lib/tastytrade/models/buying_power_effect.rb', line 9

def change_in_margin_requirement
  @change_in_margin_requirement
end

#current_buying_powerObject (readonly)

Returns the value of attribute current_buying_power.



9
10
11
# File 'lib/tastytrade/models/buying_power_effect.rb', line 9

def current_buying_power
  @current_buying_power
end

#effectObject (readonly)

Returns the value of attribute effect.



9
10
11
# File 'lib/tastytrade/models/buying_power_effect.rb', line 9

def effect
  @effect
end

#impactObject (readonly)

Returns the value of attribute impact.



9
10
11
# File 'lib/tastytrade/models/buying_power_effect.rb', line 9

def impact
  @impact
end

#is_spreadObject (readonly)

Returns the value of attribute is_spread.



9
10
11
# File 'lib/tastytrade/models/buying_power_effect.rb', line 9

def is_spread
  @is_spread
end

#isolated_order_margin_requirementObject (readonly)

Returns the value of attribute isolated_order_margin_requirement.



9
10
11
# File 'lib/tastytrade/models/buying_power_effect.rb', line 9

def isolated_order_margin_requirement
  @isolated_order_margin_requirement
end

#new_buying_powerObject (readonly)

Returns the value of attribute new_buying_power.



9
10
11
# File 'lib/tastytrade/models/buying_power_effect.rb', line 9

def new_buying_power
  @new_buying_power
end

Instance Method Details

#buying_power_change_amountObject

Get the absolute value of the buying power change



28
29
30
# File 'lib/tastytrade/models/buying_power_effect.rb', line 28

def buying_power_change_amount
  change_in_buying_power&.abs || impact&.abs || BigDecimal("0")
end

#buying_power_usage_percentageObject

Calculate the buying power usage percentage for this order



15
16
17
18
19
20
# File 'lib/tastytrade/models/buying_power_effect.rb', line 15

def buying_power_usage_percentage
  return BigDecimal("0") if current_buying_power.nil? || current_buying_power.zero?

  impact_amount = impact || change_in_buying_power&.abs || BigDecimal("0")
  ((impact_amount / current_buying_power) * 100).round(2)
end

#credit?Boolean

Check if this is a credit (increases buying power)

Returns:

  • (Boolean)


38
39
40
# File 'lib/tastytrade/models/buying_power_effect.rb', line 38

def credit?
  effect == "Credit" || (change_in_buying_power && change_in_buying_power > 0)
end

#debit?Boolean

Check if this is a debit (reduces buying power)

Returns:

  • (Boolean)


33
34
35
# File 'lib/tastytrade/models/buying_power_effect.rb', line 33

def debit?
  effect == "Debit" || (change_in_buying_power && change_in_buying_power < 0)
end

#exceeds_threshold?(threshold_percentage) ⇒ Boolean

Check if this order would use more than the specified percentage of buying power

Returns:

  • (Boolean)


23
24
25
# File 'lib/tastytrade/models/buying_power_effect.rb', line 23

def exceeds_threshold?(threshold_percentage)
  buying_power_usage_percentage > BigDecimal(threshold_percentage.to_s)
end