class Rirera::Order

Attributes

actual[RW]
broker[RW]
stop[RW]
target[RW]
volume[RW]

Public Class Methods

new(broker, volume, target, actual, stop) click to toggle source
# File lib/rirera.rb, line 10
def initialize(broker, volume, target, actual, stop)
  @broker = Rirera.get_broker(broker)
  @volume = volume
  @target = target
  @actual = actual
  @stop = stop
end

Public Instance Methods

get_amount() click to toggle source
# File lib/rirera.rb, line 46
def get_amount
  (@volume/@actual).round
end
get_break_even() click to toggle source
# File lib/rirera.rb, line 58
def get_break_even
  ((@volume + get_total_commission) / get_amount).round(2)
end
get_loss() click to toggle source
# File lib/rirera.rb, line 54
def get_loss
  ((@volume-(get_amount*@stop)) + get_total_commission).round(2)
end
get_max_gain() click to toggle source
# File lib/rirera.rb, line 50
def get_max_gain
  ((get_amount * @target) - @volume - get_total_commission).round(2)
end
get_rrr() click to toggle source
# File lib/rirera.rb, line 18
def get_rrr
  chance = @target - @actual
  risk = @actual - @stop
  (chance/risk).round(1)
end
get_total_commission() click to toggle source
# File lib/rirera.rb, line 24
def get_total_commission
  # calculate order pricing
  basic_price = Rirera::CONFIG['broker'][@broker]['basic_price']
  commission_rate = Rirera::CONFIG['broker'][@broker]['commission_rate']
  volume_rate_buy = (get_amount * @actual * commission_rate).round(2)
  volume_rate_sell = (get_amount * @target * commission_rate).round(2)
  total_commission = 0.0

  [volume_rate_buy, volume_rate_sell].each do |vr|
    if (vr + basic_price) > Rirera::CONFIG['broker'][@broker]['min_rate']
      if (vr + basic_price) > Rirera::CONFIG['broker'][@broker]['max_rate']
        total_commission += Rirera::CONFIG['broker'][@broker]['max_rate']
      else
        total_commission += (basic_price + vr)
      end
    else
      total_commission += Rirera::CONFIG['broker'][@broker]['min_rate']
    end
  end
  total_commission.round(2)
end
print_result() click to toggle source