Module: Moneymarket::Calculator
Instance Method Summary collapse
- #fee(amount: nil, percent: nil) ⇒ Object
-
#order_fee(order: nil, collected_amount: nil) ⇒ Object
move this to command.
- #quote(volume: nil, unit_price: nil) ⇒ Object
- #volume(quote: nil, unit_price: nil, unit_currency: nil) ⇒ Object
Instance Method Details
#fee(amount: nil, percent: nil) ⇒ Object
16 17 18 19 |
# File 'lib/moneymarket/utils/calculator.rb', line 16 def fee(amount: nil, percent: nil) result = (amount.cents * (percent.to_d / 100)).floor # fees always round to floor Money.new result, amount.currency end |
#order_fee(order: nil, collected_amount: nil) ⇒ Object
move this to command
21 22 23 24 25 |
# File 'lib/moneymarket/utils/calculator.rb', line 21 def order_fee(order: nil, collected_amount: nil) # move this to command collected_amount = order.collected_amount if collected_amount.nil? fee_cents = (collected_amount.cents * (order.fee.to_d / 100)).floor Money.new fee_cents, collected_amount.currency end |
#quote(volume: nil, unit_price: nil) ⇒ Object
5 6 7 8 9 |
# File 'lib/moneymarket/utils/calculator.rb', line 5 def quote(volume: nil, unit_price: nil) base_currency = volume.currency quote = ((unit_price.cents * volume.cents).to_d / base_currency.subunit_to_unit).ceil Money.new quote, unit_price.currency end |
#volume(quote: nil, unit_price: nil, unit_currency: nil) ⇒ Object
11 12 13 14 |
# File 'lib/moneymarket/utils/calculator.rb', line 11 def volume(quote: nil, unit_price: nil, unit_currency: nil) volume = ((quote.cents * unit_currency.subunit_to_unit).to_d / unit_price.cents).floor Money.new volume, unit_currency end |