Skip to content

Commit a6266d6

Browse files
committed
Changed the precision of decimals stored in the database.
1 parent 880e125 commit a6266d6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Repository/SqlKataMarketOrderRepository.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace Repository
99
{
1010
public class SqlKataMarketOrderRepository : SqlKataRepository<MarketOrder>, IMarketOrderRepository
1111
{
12+
private const int DecimalPrecision = 100000000;
13+
1214
public SqlKataMarketOrderRepository(SqlKataDatabase db) : base(db, "market_orders")
1315
{
1416
}
@@ -19,17 +21,17 @@ public override object ToRow(MarketOrder entry)
1921
{
2022
return new
2123
{
22-
filled_price = (int) (entry.FilledPrice * 100),
23-
fee = (int) (entry.Fee * 100),
24-
size = (int) (entry.Size * 100),
24+
filled_price = (long) (entry.FilledPrice * DecimalPrecision),
25+
fee = (long) (entry.Fee * DecimalPrecision),
26+
size = (long) (entry.Size * DecimalPrecision),
2527
date = ((DateTimeOffset) entry.Date).ToUnixTimeSeconds(),
2628
buy = entry.Buy ? 1 : 0,
2729
portfolio_entry_id = entry.PortfolioEntryId,
2830
};
2931
}
3032

3133
public override MarketOrder FromRow(dynamic d) =>
32-
new(Decimal.Divide(d.filled_price, 100), Decimal.Divide(d.fee, 100), Decimal.Divide(d.size, 100),
34+
new(Decimal.Divide(d.filled_price, DecimalPrecision), Decimal.Divide(d.fee, DecimalPrecision), Decimal.Divide(d.size, DecimalPrecision),
3335
DateTimeOffset.FromUnixTimeSeconds((int) d.date).DateTime.ToLocalTime(), d.buy > 0,
3436
(int) d.id, (int) d.portfolio_entry_id);
3537

0 commit comments

Comments
 (0)