Class: Position
- Inherits:
-
Object
- Object
- Position
- Defined in:
- lib/bitflyer/cli/model/position.rb
Instance Method Summary collapse
- #average ⇒ Object
-
#initialize(positions) ⇒ Position
constructor
A new instance of Position.
- #profit(current_price) ⇒ Object
- #size ⇒ Object
- #sum ⇒ Object
Constructor Details
#initialize(positions) ⇒ Position
Returns a new instance of Position.
5 6 7 |
# File 'lib/bitflyer/cli/model/position.rb', line 5 def initialize(positions) @positions = positions end |
Instance Method Details
#average ⇒ Object
15 16 17 |
# File 'lib/bitflyer/cli/model/position.rb', line 15 def average @positions.size > 0 ? (sum / size.abs).to_i : 0 end |
#profit(current_price) ⇒ Object
9 10 11 12 13 |
# File 'lib/bitflyer/cli/model/position.rb', line 9 def profit(current_price) @positions.inject('0'.to_d) do |sum, position| sum + (current_price - position['price'].to_s.to_d) * position['size'].to_s.to_d * coefficient(position) end end |
#size ⇒ Object
23 24 25 |
# File 'lib/bitflyer/cli/model/position.rb', line 23 def size @positions.inject('0'.to_d) { |sum, position| sum + position['size'].to_s.to_d * coefficient(position) } end |
#sum ⇒ Object
19 20 21 |
# File 'lib/bitflyer/cli/model/position.rb', line 19 def sum @positions.inject('0'.to_d) { |sum, position| sum + position['price'].to_s.to_d * position['size'].to_s.to_d } end |