mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 14:31:25 +00:00
Increasing trades.price decimal scale (#89)
* Changing trades.price to have a larger scale - a scale of 4 causes destructive rounding when calculating transaction cost; changes to the UI to allow for inputting and showing increased scale trade prices; test case
This commit is contained in:
@@ -20,4 +20,38 @@ class TradeTest < ActiveSupport::TestCase
|
||||
name = Trade.build_name("buy", 0.25, "BTC")
|
||||
assert_equal "Buy 0.25 shares of BTC", name
|
||||
end
|
||||
|
||||
test "price scale is preserved at 10 decimal places" do
|
||||
security = Security.create!(ticker: "TEST", exchange_operating_mic: "XNAS")
|
||||
|
||||
# up to 10 decimal places — should persist exactly
|
||||
precise_price = BigDecimal("12.3456789012")
|
||||
trade = Trade.create!(
|
||||
security: security,
|
||||
price: precise_price,
|
||||
qty: 10000,
|
||||
currency: "USD"
|
||||
)
|
||||
|
||||
trade.reload
|
||||
|
||||
assert_equal precise_price, trade.price
|
||||
end
|
||||
|
||||
test "price is rounded to 10 decimal places" do
|
||||
security = Security.create!(ticker: "TEST", exchange_operating_mic: "XNAS")
|
||||
|
||||
# over 10 decimal places — will be rounded
|
||||
price_with_too_many_decimals = BigDecimal("1.123456789012345")
|
||||
trade = Trade.create!(
|
||||
security: security,
|
||||
price: price_with_too_many_decimals,
|
||||
qty: 1,
|
||||
currency: "USD"
|
||||
)
|
||||
|
||||
trade.reload
|
||||
|
||||
assert_equal BigDecimal("1.1234567890"), trade.price
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user