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.
7 8 9 |
# File 'lib/bitflyer/cli/model/position.rb', line 7 def initialize(positions) @positions = positions end |
Instance Method Details
#average ⇒ Object
17 18 19 |
# File 'lib/bitflyer/cli/model/position.rb', line 17 def average @positions.size.positive? ? (sum / size.abs).to_i : 0 end |
#profit(current_price) ⇒ Object
11 12 13 14 15 |
# File 'lib/bitflyer/cli/model/position.rb', line 11 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
25 26 27 |
# File 'lib/bitflyer/cli/model/position.rb', line 25 def size @positions.inject('0'.to_d) { |sum, position| sum + (position['size'].to_s.to_d * coefficient(position)) } end |
#sum ⇒ Object
21 22 23 |
# File 'lib/bitflyer/cli/model/position.rb', line 21 def sum @positions.inject('0'.to_d) { |sum, position| sum + (position['price'].to_s.to_d * position['size'].to_s.to_d) } end |