fix(ledger): preserve exact decimal amount in manual and unified responses

Co-authored-by: genichin <4282227+genichin@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-09-09 12:41:36 +00:00
committed by GitHub
co-authored by genichin
parent 7fc3386f3a
commit fde5b33f05
5 changed files with 32 additions and 8 deletions
+10 -2
View File
@@ -16,6 +16,7 @@ import json
import logging
import uuid
from datetime import date, datetime, timedelta, timezone
from decimal import Decimal
from fastapi import APIRouter, Depends, HTTPException, Query, Response, status
@@ -687,7 +688,11 @@ def record_ledger_trade_v1(
def _manual_entry_to_response(entry) -> ManualLedgerResponse:
action = (entry.action or entry.side or "").upper()
amount = entry.price if action in {"INVEST", "BUFFER_OUT", "BUFFER_IN", "WITHDRAW", "PROFIT", "DIVIDEND"} else None
amount = (
(entry.price_decimal if entry.price_decimal is not None else Decimal(str(entry.price)))
if action in {"INVEST", "BUFFER_OUT", "BUFFER_IN", "WITHDRAW", "PROFIT", "DIVIDEND"}
else None
)
return ManualLedgerResponse(
ledger_entry_id=entry.ledger_entry_id,
portfolio_id=entry.portfolio_id,
@@ -786,6 +791,9 @@ def _decode_ledger_cursor(cursor: str, *, portfolio_id: str, source: str | None)
def _ledger_entry_to_history_item(entry) -> LedgerHistoryItem:
action = (entry.action or entry.side or "").upper()
amount = None
if action in {"INVEST", "BUFFER_OUT", "BUFFER_IN", "WITHDRAW", "PROFIT", "DIVIDEND"}:
amount = entry.price_decimal if entry.price_decimal is not None else Decimal(str(entry.price))
return LedgerHistoryItem(
ledger_entry_id=entry.ledger_entry_id,
portfolio_id=entry.portfolio_id,
@@ -796,7 +804,7 @@ def _ledger_entry_to_history_item(entry) -> LedgerHistoryItem:
order_id=entry.order_id,
execution_id=entry.execution_id,
quantity=entry.quantity,
amount=entry.price if action in {"INVEST", "BUFFER_OUT", "BUFFER_IN", "WITHDRAW", "PROFIT", "DIVIDEND"} else None,
amount=amount,
price=entry.price,
fee_amount=entry.fee_amount,
tax_amount=entry.tax_amount,