44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/bitex/rates.rb', line 44
def self.calculate_path_backwards(path, value)
value = value.to_d
path_to_calculator(path).each do |step|
step.symbolize_keys!
case step[:type].to_sym
when :exchange
value /= step[:rate].to_d
when :percentual_fee
value /= 1 - (step[:percentage].to_d / 100.to_d)
when :fixed_fee
value += step[:amount].to_d
when :minimum_fee
value = [value + step[:minimum].to_d, value / (1 - (step[:percentage].to_d / 100.to_d))].max
end
end
value
end
|