Class: SchwabRb::DataObjects::Position
- Inherits:
-
Object
- Object
- SchwabRb::DataObjects::Position
- Defined in:
- lib/schwab_rb/data_objects/position.rb
Instance Attribute Summary collapse
-
#average_long_price ⇒ Object
readonly
Returns the value of attribute average_long_price.
-
#average_price ⇒ Object
readonly
Returns the value of attribute average_price.
-
#average_short_price ⇒ Object
readonly
Returns the value of attribute average_short_price.
-
#current_day_cost ⇒ Object
readonly
Returns the value of attribute current_day_cost.
-
#current_day_profit_loss ⇒ Object
readonly
Returns the value of attribute current_day_profit_loss.
-
#current_day_profit_loss_percentage ⇒ Object
readonly
Returns the value of attribute current_day_profit_loss_percentage.
-
#delta ⇒ Object
readonly
Returns the value of attribute delta.
-
#instrument ⇒ Object
readonly
Returns the value of attribute instrument.
-
#long_open_profit_loss ⇒ Object
readonly
Returns the value of attribute long_open_profit_loss.
-
#long_quantity ⇒ Object
readonly
Returns the value of attribute long_quantity.
-
#maintenance_requirement ⇒ Object
readonly
Returns the value of attribute maintenance_requirement.
-
#mark ⇒ Object
readonly
Returns the value of attribute mark.
-
#market_value ⇒ Object
readonly
Returns the value of attribute market_value.
-
#settled_long_quantity ⇒ Object
readonly
Returns the value of attribute settled_long_quantity.
-
#settled_short_quantity ⇒ Object
readonly
Returns the value of attribute settled_short_quantity.
-
#short_open_profit_loss ⇒ Object
readonly
Returns the value of attribute short_open_profit_loss.
-
#short_quantity ⇒ Object
readonly
Returns the value of attribute short_quantity.
-
#strike ⇒ Object
readonly
Returns the value of attribute strike.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(short_quantity: nil, average_price: nil, current_day_profit_loss: nil, current_day_profit_loss_percentage: nil, long_quantity: nil, settled_long_quantity: nil, settled_short_quantity: nil, instrument: nil, market_value: nil, maintenance_requirement: nil, average_long_price: nil, average_short_price: nil, long_open_profit_loss: nil, short_open_profit_loss: nil, current_day_cost: nil, strike: nil, delta: nil, mark: nil) ⇒ Position
constructor
A new instance of Position.
- #long? ⇒ Boolean
- #long_short ⇒ Object
- #put_call ⇒ Object
- #short? ⇒ Boolean
- #symbol ⇒ Object
- #to_h ⇒ Object
- #underlying_symbol ⇒ Object
Constructor Details
#initialize(short_quantity: nil, average_price: nil, current_day_profit_loss: nil, current_day_profit_loss_percentage: nil, long_quantity: nil, settled_long_quantity: nil, settled_short_quantity: nil, instrument: nil, market_value: nil, maintenance_requirement: nil, average_long_price: nil, average_short_price: nil, long_open_profit_loss: nil, short_open_profit_loss: nil, current_day_cost: nil, strike: nil, delta: nil, mark: nil) ⇒ Position
Returns a new instance of Position.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/schwab_rb/data_objects/position.rb', line 34 def initialize( short_quantity: nil, average_price: nil, current_day_profit_loss: nil, current_day_profit_loss_percentage: nil, long_quantity: nil, settled_long_quantity: nil, settled_short_quantity: nil, instrument: nil, market_value: nil, maintenance_requirement: nil, average_long_price: nil, average_short_price: nil, long_open_profit_loss: nil, short_open_profit_loss: nil, current_day_cost: nil, strike: nil, delta: nil, mark: nil ) @short_quantity = short_quantity @average_price = average_price @current_day_profit_loss = current_day_profit_loss @current_day_profit_loss_percentage = current_day_profit_loss_percentage @long_quantity = long_quantity @settled_long_quantity = settled_long_quantity @settled_short_quantity = settled_short_quantity @instrument = instrument @market_value = market_value @maintenance_requirement = maintenance_requirement @average_long_price = average_long_price @average_short_price = average_short_price @long_open_profit_loss = long_open_profit_loss @short_open_profit_loss = short_open_profit_loss @current_day_cost = current_day_cost @strike = strike @delta = delta @mark = mark end |
Instance Attribute Details
#average_long_price ⇒ Object (readonly)
Returns the value of attribute average_long_price.
8 9 10 |
# File 'lib/schwab_rb/data_objects/position.rb', line 8 def average_long_price @average_long_price end |
#average_price ⇒ Object (readonly)
Returns the value of attribute average_price.
8 9 10 |
# File 'lib/schwab_rb/data_objects/position.rb', line 8 def average_price @average_price end |
#average_short_price ⇒ Object (readonly)
Returns the value of attribute average_short_price.
8 9 10 |
# File 'lib/schwab_rb/data_objects/position.rb', line 8 def average_short_price @average_short_price end |
#current_day_cost ⇒ Object (readonly)
Returns the value of attribute current_day_cost.
8 9 10 |
# File 'lib/schwab_rb/data_objects/position.rb', line 8 def current_day_cost @current_day_cost end |
#current_day_profit_loss ⇒ Object (readonly)
Returns the value of attribute current_day_profit_loss.
8 9 10 |
# File 'lib/schwab_rb/data_objects/position.rb', line 8 def current_day_profit_loss @current_day_profit_loss end |
#current_day_profit_loss_percentage ⇒ Object (readonly)
Returns the value of attribute current_day_profit_loss_percentage.
8 9 10 |
# File 'lib/schwab_rb/data_objects/position.rb', line 8 def current_day_profit_loss_percentage @current_day_profit_loss_percentage end |
#delta ⇒ Object (readonly)
Returns the value of attribute delta.
8 9 10 |
# File 'lib/schwab_rb/data_objects/position.rb', line 8 def delta @delta end |
#instrument ⇒ Object (readonly)
Returns the value of attribute instrument.
8 9 10 |
# File 'lib/schwab_rb/data_objects/position.rb', line 8 def instrument @instrument end |
#long_open_profit_loss ⇒ Object (readonly)
Returns the value of attribute long_open_profit_loss.
8 9 10 |
# File 'lib/schwab_rb/data_objects/position.rb', line 8 def long_open_profit_loss @long_open_profit_loss end |
#long_quantity ⇒ Object (readonly)
Returns the value of attribute long_quantity.
8 9 10 |
# File 'lib/schwab_rb/data_objects/position.rb', line 8 def long_quantity @long_quantity end |
#maintenance_requirement ⇒ Object (readonly)
Returns the value of attribute maintenance_requirement.
8 9 10 |
# File 'lib/schwab_rb/data_objects/position.rb', line 8 def maintenance_requirement @maintenance_requirement end |
#mark ⇒ Object (readonly)
Returns the value of attribute mark.
8 9 10 |
# File 'lib/schwab_rb/data_objects/position.rb', line 8 def mark @mark end |
#market_value ⇒ Object (readonly)
Returns the value of attribute market_value.
8 9 10 |
# File 'lib/schwab_rb/data_objects/position.rb', line 8 def market_value @market_value end |
#settled_long_quantity ⇒ Object (readonly)
Returns the value of attribute settled_long_quantity.
8 9 10 |
# File 'lib/schwab_rb/data_objects/position.rb', line 8 def settled_long_quantity @settled_long_quantity end |
#settled_short_quantity ⇒ Object (readonly)
Returns the value of attribute settled_short_quantity.
8 9 10 |
# File 'lib/schwab_rb/data_objects/position.rb', line 8 def settled_short_quantity @settled_short_quantity end |
#short_open_profit_loss ⇒ Object (readonly)
Returns the value of attribute short_open_profit_loss.
8 9 10 |
# File 'lib/schwab_rb/data_objects/position.rb', line 8 def short_open_profit_loss @short_open_profit_loss end |
#short_quantity ⇒ Object (readonly)
Returns the value of attribute short_quantity.
8 9 10 |
# File 'lib/schwab_rb/data_objects/position.rb', line 8 def short_quantity @short_quantity end |
#strike ⇒ Object (readonly)
Returns the value of attribute strike.
8 9 10 |
# File 'lib/schwab_rb/data_objects/position.rb', line 8 def strike @strike end |
Class Method Details
.build(data) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/schwab_rb/data_objects/position.rb', line 13 def build(data) new( short_quantity: data[:shortQuantity], average_price: data[:averagePrice], current_day_profit_loss: data[:currentDayProfitLoss], current_day_profit_loss_percentage: data[:currentDayProfitLossPercentage], long_quantity: data[:longQuantity], settled_long_quantity: data[:settledLongQuantity], settled_short_quantity: data[:settledShortQuantity], instrument: Instrument.build(data[:instrument]), market_value: data[:marketValue], maintenance_requirement: data[:maintenanceRequirement], average_long_price: data[:averageLongPrice], average_short_price: data[:averageShortPrice], long_open_profit_loss: data[:longOpenProfitLoss], short_open_profit_loss: data[:shortOpenProfitLoss], current_day_cost: data[:currentDayCost] ) end |
Instance Method Details
#long? ⇒ Boolean
66 67 68 |
# File 'lib/schwab_rb/data_objects/position.rb', line 66 def long? long_quantity.positive? end |
#long_short ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/schwab_rb/data_objects/position.rb', line 74 def long_short if long? "LONG" elsif short? "SHORT" else "NONE" end end |
#put_call ⇒ Object
84 85 86 |
# File 'lib/schwab_rb/data_objects/position.rb', line 84 def put_call instrument.put_call end |
#short? ⇒ Boolean
70 71 72 |
# File 'lib/schwab_rb/data_objects/position.rb', line 70 def short? short_quantity.positive? end |
#symbol ⇒ Object
58 59 60 |
# File 'lib/schwab_rb/data_objects/position.rb', line 58 def symbol instrument&.symbol end |
#to_h ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/schwab_rb/data_objects/position.rb', line 88 def to_h { symbol: symbol, underlying_symbol: , average_price: average_price, market_value: market_value, put_call: put_call, long_short: long_short } end |
#underlying_symbol ⇒ Object
62 63 64 |
# File 'lib/schwab_rb/data_objects/position.rb', line 62 def instrument. end |