- 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
43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
from __future__ import annotations
|
||
|
||
from collections.abc import Sequence
|
||
from datetime import date, datetime
|
||
|
||
from sqlalchemy import delete, insert, select
|
||
from sqlalchemy.ext.asyncio import AsyncSession
|
||
|
||
from app.db.models import NonWorkingDay
|
||
|
||
|
||
class CalendarRepository:
|
||
def __init__(self, session: AsyncSession) -> None:
|
||
self.session = session
|
||
|
||
async def replace_year(self, year: int, days: Sequence[date], user: str) -> None:
|
||
"""Нерабочие дни года целиком: старые удаляются, новые вставляются.
|
||
Коммит — на вызывающей стороне."""
|
||
await self.session.execute(
|
||
delete(NonWorkingDay).where(
|
||
NonWorkingDay.day >= date(year, 1, 1),
|
||
NonWorkingDay.day <= date(year, 12, 31),
|
||
)
|
||
)
|
||
if days:
|
||
await self.session.execute(
|
||
insert(NonWorkingDay),
|
||
[{"day": d, "created_by": user, "updated_by": user} for d in days],
|
||
)
|
||
|
||
async def list_between(
|
||
self, start: date, end: date
|
||
) -> list[tuple[date, str, datetime]]:
|
||
"""(день, кто загрузил, когда) с start по end включительно."""
|
||
result = await self.session.execute(
|
||
select(
|
||
NonWorkingDay.day, NonWorkingDay.updated_by, NonWorkingDay.updated_at
|
||
)
|
||
.where(NonWorkingDay.day >= start, NonWorkingDay.day <= end)
|
||
.order_by(NonWorkingDay.day)
|
||
)
|
||
return [tuple(row) for row in result.all()]
|