Class: Position

Inherits:
Object
  • Object
show all
Defined in:
lib/bitflyer/cli/model/position.rb

Instance Method Summary collapse

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

#averageObject



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

#sizeObject



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

#sumObject



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