class Position

Public Class Methods

new(positions) click to toggle source
# File lib/bitflyer/cli/model/position.rb, line 5
def initialize(positions)
  @positions = positions
end

Public Instance Methods

average() click to toggle source
# File lib/bitflyer/cli/model/position.rb, line 15
def average
  @positions.size > 0 ? (sum / size.abs).to_i : 0
end
profit(current_price) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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

Private Instance Methods

coefficient(position) click to toggle source
# File lib/bitflyer/cli/model/position.rb, line 29
def coefficient(position)
  position['side'] == 'BUY' ? 1.0 : -1.0
end