Class: SchwabRb::DataObjects::Position

Inherits:
Object
  • Object
show all
Defined in:
lib/schwab_rb/data_objects/position.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_priceObject (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_priceObject (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_priceObject (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_costObject (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_lossObject (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_percentageObject (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

#deltaObject (readonly)

Returns the value of attribute delta.



8
9
10
# File 'lib/schwab_rb/data_objects/position.rb', line 8

def delta
  @delta
end

#instrumentObject (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_lossObject (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_quantityObject (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_requirementObject (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

#markObject (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_valueObject (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_quantityObject (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_quantityObject (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_lossObject (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_quantityObject (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

#strikeObject (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

Returns:

  • (Boolean)


66
67
68
# File 'lib/schwab_rb/data_objects/position.rb', line 66

def long?
  long_quantity.positive?
end

#long_shortObject



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_callObject



84
85
86
# File 'lib/schwab_rb/data_objects/position.rb', line 84

def put_call
  instrument.put_call
end

#short?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/schwab_rb/data_objects/position.rb', line 70

def short?
  short_quantity.positive?
end

#symbolObject



58
59
60
# File 'lib/schwab_rb/data_objects/position.rb', line 58

def symbol
  instrument&.symbol
end

#to_hObject



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: underlying_symbol,
    average_price: average_price,
    market_value: market_value,
    put_call: put_call,
    long_short: long_short
  }
end

#underlying_symbolObject



62
63
64
# File 'lib/schwab_rb/data_objects/position.rb', line 62

def underlying_symbol
  instrument.underlying_symbol
end