335 lines
9.7 KiB
Python
335 lines
9.7 KiB
Python
from datetime import date
|
|
from typing import Literal
|
|
|
|
from app.service.models import ReconSummary, Transaction
|
|
|
|
StatusType = Literal["Matched", "Unmatched", "Pending"]
|
|
FlagType = Literal["None", "Duplicate", "Threshold Breach", "Manual Review"]
|
|
|
|
|
|
TRANSACTIONS: list[Transaction] = [
|
|
Transaction(
|
|
transaction_id="TXN-001",
|
|
date=date(2026, 4, 10),
|
|
account="ACC-9821",
|
|
amount=12400.00,
|
|
status="Matched",
|
|
flag="None",
|
|
reference_id="REF-2026-0001",
|
|
counterparty="Morgan Stanley",
|
|
currency="USD",
|
|
booking_date=date(2026, 4, 9),
|
|
settlement_date=date(2026, 4, 12),
|
|
description="FX Swap USD/EUR",
|
|
),
|
|
Transaction(
|
|
transaction_id="TXN-002",
|
|
date=date(2026, 4, 11),
|
|
account="ACC-4473",
|
|
amount=3750.50,
|
|
status="Unmatched",
|
|
flag="Duplicate",
|
|
reference_id="REF-2026-0002",
|
|
counterparty="JPMorgan Chase",
|
|
currency="USD",
|
|
booking_date=date(2026, 4, 10),
|
|
settlement_date=date(2026, 4, 13),
|
|
description="Interest rate swap",
|
|
),
|
|
Transaction(
|
|
transaction_id="TXN-003",
|
|
date=date(2026, 4, 11),
|
|
account="ACC-1190",
|
|
amount=88200.00,
|
|
status="Unmatched",
|
|
flag="Threshold Breach",
|
|
reference_id="REF-2026-0003",
|
|
counterparty="Goldman Sachs",
|
|
currency="GBP",
|
|
booking_date=date(2026, 4, 10),
|
|
settlement_date=date(2026, 4, 14),
|
|
description="Cross-currency swap",
|
|
),
|
|
Transaction(
|
|
transaction_id="TXN-004",
|
|
date=date(2026, 4, 12),
|
|
account="ACC-6654",
|
|
amount=540.00,
|
|
status="Matched",
|
|
flag="None",
|
|
reference_id="REF-2026-0004",
|
|
counterparty="Barclays",
|
|
currency="EUR",
|
|
booking_date=date(2026, 4, 11),
|
|
settlement_date=date(2026, 4, 15),
|
|
description="Bond settlement",
|
|
),
|
|
Transaction(
|
|
transaction_id="TXN-005",
|
|
date=date(2026, 4, 13),
|
|
account="ACC-3312",
|
|
amount=21000.00,
|
|
status="Pending",
|
|
flag="Manual Review",
|
|
reference_id="REF-2026-0005",
|
|
counterparty="Deutsche Bank",
|
|
currency="USD",
|
|
booking_date=date(2026, 4, 12),
|
|
settlement_date=date(2026, 4, 16),
|
|
description="Equity options trade",
|
|
),
|
|
Transaction(
|
|
transaction_id="TXN-006",
|
|
date=date(2026, 4, 14),
|
|
account="ACC-5542",
|
|
amount=15600.00,
|
|
status="Matched",
|
|
flag="None",
|
|
reference_id="REF-2026-0006",
|
|
counterparty="Credit Suisse",
|
|
currency="CHF",
|
|
booking_date=date(2026, 4, 13),
|
|
settlement_date=date(2026, 4, 17),
|
|
description="Repo transaction",
|
|
),
|
|
Transaction(
|
|
transaction_id="TXN-007",
|
|
date=date(2026, 4, 14),
|
|
account="ACC-8834",
|
|
amount=2250.75,
|
|
status="Unmatched",
|
|
flag="Threshold Breach",
|
|
reference_id="REF-2026-0007",
|
|
counterparty="Citigroup",
|
|
currency="JPY",
|
|
booking_date=date(2026, 4, 13),
|
|
settlement_date=date(2026, 4, 18),
|
|
description="Forward contract",
|
|
),
|
|
Transaction(
|
|
transaction_id="TXN-008",
|
|
date=date(2026, 4, 15),
|
|
account="ACC-2201",
|
|
amount=45000.00,
|
|
status="Matched",
|
|
flag="None",
|
|
reference_id="REF-2026-0008",
|
|
counterparty="UBS",
|
|
currency="USD",
|
|
booking_date=date(2026, 4, 14),
|
|
settlement_date=date(2026, 4, 19),
|
|
description="Commodity swap",
|
|
),
|
|
Transaction(
|
|
transaction_id="TXN-009",
|
|
date=date(2026, 4, 15),
|
|
account="ACC-7123",
|
|
amount=8900.50,
|
|
status="Pending",
|
|
flag="Manual Review",
|
|
reference_id="REF-2026-0009",
|
|
counterparty="HSBC",
|
|
currency="AUD",
|
|
booking_date=date(2026, 4, 14),
|
|
settlement_date=date(2026, 4, 20),
|
|
description="Index futures",
|
|
),
|
|
Transaction(
|
|
transaction_id="TXN-010",
|
|
date=date(2026, 4, 16),
|
|
account="ACC-3345",
|
|
amount=1200.00,
|
|
status="Matched",
|
|
flag="None",
|
|
reference_id="REF-2026-0010",
|
|
counterparty="Bank of America",
|
|
currency="USD",
|
|
booking_date=date(2026, 4, 15),
|
|
settlement_date=date(2026, 4, 21),
|
|
description="Interest rate cap",
|
|
),
|
|
Transaction(
|
|
transaction_id="TXN-011",
|
|
date=date(2026, 4, 16),
|
|
account="ACC-5501",
|
|
amount=67500.00,
|
|
status="Unmatched",
|
|
flag="Duplicate",
|
|
reference_id="REF-2026-0011",
|
|
counterparty="Wells Fargo",
|
|
currency="EUR",
|
|
booking_date=date(2026, 4, 15),
|
|
settlement_date=date(2026, 4, 22),
|
|
description="Currency forward",
|
|
),
|
|
Transaction(
|
|
transaction_id="TXN-012",
|
|
date=date(2026, 4, 17),
|
|
account="ACC-6789",
|
|
amount=3400.25,
|
|
status="Matched",
|
|
flag="None",
|
|
reference_id="REF-2026-0012",
|
|
counterparty="BNY Mellon",
|
|
currency="GBP",
|
|
booking_date=date(2026, 4, 16),
|
|
settlement_date=date(2026, 4, 23),
|
|
description="Bond purchase",
|
|
),
|
|
Transaction(
|
|
transaction_id="TXN-013",
|
|
date=date(2026, 4, 17),
|
|
account="ACC-1234",
|
|
amount=52100.00,
|
|
status="Pending",
|
|
flag="Threshold Breach",
|
|
reference_id="REF-2026-0013",
|
|
counterparty="State Street",
|
|
currency="JPY",
|
|
booking_date=date(2026, 4, 16),
|
|
settlement_date=date(2026, 4, 24),
|
|
description="Swaption settlement",
|
|
),
|
|
Transaction(
|
|
transaction_id="TXN-014",
|
|
date=date(2026, 4, 18),
|
|
account="ACC-9876",
|
|
amount=920.50,
|
|
status="Matched",
|
|
flag="None",
|
|
reference_id="REF-2026-0014",
|
|
counterparty="Nomura",
|
|
currency="CHF",
|
|
booking_date=date(2026, 4, 17),
|
|
settlement_date=date(2026, 4, 25),
|
|
description="Basket trade",
|
|
),
|
|
Transaction(
|
|
transaction_id="TXN-015",
|
|
date=date(2026, 4, 18),
|
|
account="ACC-4455",
|
|
amount=29300.00,
|
|
status="Unmatched",
|
|
flag="Manual Review",
|
|
reference_id="REF-2026-0015",
|
|
counterparty="Mizuho",
|
|
currency="USD",
|
|
booking_date=date(2026, 4, 17),
|
|
settlement_date=date(2026, 4, 26),
|
|
description="Variance swap",
|
|
),
|
|
Transaction(
|
|
transaction_id="TXN-016",
|
|
date=date(2026, 4, 19),
|
|
account="ACC-2288",
|
|
amount=11500.75,
|
|
status="Matched",
|
|
flag="None",
|
|
reference_id="REF-2026-0016",
|
|
counterparty="RBC",
|
|
currency="CAD",
|
|
booking_date=date(2026, 4, 18),
|
|
settlement_date=date(2026, 4, 27),
|
|
description="CDS contract",
|
|
),
|
|
Transaction(
|
|
transaction_id="TXN-017",
|
|
date=date(2026, 4, 19),
|
|
account="ACC-3399",
|
|
amount=76800.00,
|
|
status="Unmatched",
|
|
flag="Threshold Breach",
|
|
reference_id="REF-2026-0017",
|
|
counterparty="Scotiabank",
|
|
currency="AUD",
|
|
booking_date=date(2026, 4, 18),
|
|
settlement_date=date(2026, 4, 28),
|
|
description="Total return swap",
|
|
),
|
|
Transaction(
|
|
transaction_id="TXN-018",
|
|
date=date(2026, 4, 20),
|
|
account="ACC-5566",
|
|
amount=4100.25,
|
|
status="Matched",
|
|
flag="None",
|
|
reference_id="REF-2026-0018",
|
|
counterparty="TD Bank",
|
|
currency="USD",
|
|
booking_date=date(2026, 4, 19),
|
|
settlement_date=date(2026, 4, 29),
|
|
description="Equity collar",
|
|
),
|
|
Transaction(
|
|
transaction_id="TXN-019",
|
|
date=date(2026, 4, 20),
|
|
account="ACC-7788",
|
|
amount=18600.00,
|
|
status="Pending",
|
|
flag="Manual Review",
|
|
reference_id="REF-2026-0019",
|
|
counterparty="MUFG",
|
|
currency="EUR",
|
|
booking_date=date(2026, 4, 19),
|
|
settlement_date=date(2026, 4, 30),
|
|
description="Volatility swap",
|
|
),
|
|
Transaction(
|
|
transaction_id="TXN-020",
|
|
date=date(2026, 4, 21),
|
|
account="ACC-9900",
|
|
amount=8250.50,
|
|
status="Matched",
|
|
flag="None",
|
|
reference_id="REF-2026-0020",
|
|
counterparty="Sumitomo Mitsui",
|
|
currency="GBP",
|
|
booking_date=date(2026, 4, 20),
|
|
settlement_date=date(2026, 5, 1),
|
|
description="Knock-out option",
|
|
),
|
|
]
|
|
|
|
|
|
def list_transactions(
|
|
status: StatusType | None = None, flag: FlagType | None = None
|
|
) -> list[Transaction]:
|
|
results = TRANSACTIONS
|
|
if status:
|
|
results = [item for item in results if item.status == status]
|
|
if flag:
|
|
results = [item for item in results if item.flag == flag]
|
|
return results
|
|
|
|
|
|
def get_transaction_by_id(transaction_id: str) -> Transaction | None:
|
|
for item in TRANSACTIONS:
|
|
if item.transaction_id == transaction_id:
|
|
return item
|
|
return None
|
|
|
|
|
|
def add_transaction(transaction: Transaction) -> bool:
|
|
if get_transaction_by_id(transaction.transaction_id) is not None:
|
|
return False
|
|
TRANSACTIONS.append(transaction)
|
|
return True
|
|
|
|
|
|
def delete_transaction_by_id(transaction_id: str) -> bool:
|
|
for index, item in enumerate(TRANSACTIONS):
|
|
if item.transaction_id == transaction_id:
|
|
TRANSACTIONS.pop(index)
|
|
return True
|
|
return False
|
|
|
|
|
|
def get_summary() -> ReconSummary:
|
|
return ReconSummary(
|
|
total=len(TRANSACTIONS),
|
|
matched=sum(1 for item in TRANSACTIONS if item.status == "Matched"),
|
|
unmatched=sum(1 for item in TRANSACTIONS if item.status == "Unmatched"),
|
|
pending=sum(1 for item in TRANSACTIONS if item.status == "Pending"),
|
|
flagged=sum(1 for item in TRANSACTIONS if item.flag != "None"),
|
|
)
|