DRRK/app/repositories/reference.py
Raykov-MS c1c73e96f5 Add funding rates, positions, business calendar and xlsx export
- funding_rate table and "Фондирование" page: rate from date, history, rate on date (D27)
- positions by issue: BUY - SELL per portfolio, "Остатки" page (D29)
- quotes are loaded only for securities with an open position (D10)
- business calendar from xmlcalendar.ru: yearly file upload, report date
  and update job use previous working day (D30)
- xlsx download for positions, quotes and funding rate history
- manual operation type as radio buttons
- QUIK instruments with purchase marks ("МТС 2Р-18_1") match the issue,
  file name kept in operation.instrument (D17)
- migrations d3a6f8b1c254, e7b2c9d4a813, f1c4a7e9b352
- project.md: decisions and questions after customer meetings
2026-10-29 11:20:15 +03:00

38 lines
1.3 KiB
Python

from __future__ import annotations
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from app.db.models import Currency, OperationType, Portfolio
class ReferenceRepository:
def __init__(self, session: AsyncSession) -> None:
self.session = session
async def get_currency_id(self, code: str) -> int | None:
result = await self.session.execute(
select(Currency.id).where(Currency.code == code)
)
return result.scalar_one_or_none()
async def currency_ids(self) -> dict[str, int]:
result = await self.session.execute(select(Currency.code, Currency.id))
return {code: id_ for code, id_ in result.all()}
async def operation_type_ids(self) -> dict[str, int]:
result = await self.session.execute(
select(OperationType.code, OperationType.id)
)
return {code: id_ for code, id_ in result.all()}
async def get_portfolio_id(self, code: str) -> int | None:
result = await self.session.execute(
select(Portfolio.id).where(Portfolio.code == code)
)
return result.scalar_one_or_none()
async def list_portfolios(self) -> list[Portfolio]:
result = await self.session.execute(select(Portfolio).order_by(Portfolio.id))
return list(result.scalars().all())