DRRK/alembic/versions/d3a6f8b1c254_funding_rate.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

80 lines
2.2 KiB
Python

"""ставки фондирования
Revision ID: d3a6f8b1c254
Revises: a4e81c6f2b97
Create Date: 2026-10-23 00:00:00
funding_rate (D27).
"""
from typing import Sequence, Union
import sqlalchemy as sa
from alembic import op
from app.core.config import settings
# revision identifiers, used by Alembic.
revision: str = "d3a6f8b1c254"
down_revision: Union[str, None] = "a4e81c6f2b97"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
_schema = settings.DATABASE_SCHEMA or None
# Типы зафиксированы в ревизии, как и в начальной миграции.
_BIGINT_PK = sa.BigInteger().with_variant(sa.Integer(), "sqlite")
_PERCENT = sa.Numeric(12, 6)
def _fk(table_column: str) -> str:
return f"{_schema}.{table_column}" if _schema else table_column
def upgrade() -> None:
"""Upgrade schema."""
op.create_table(
"funding_rate",
sa.Column("id", _BIGINT_PK, sa.Identity(), primary_key=True),
sa.Column(
"portfolio_id",
sa.BigInteger(),
sa.ForeignKey(_fk("portfolio.id")),
nullable=False,
),
sa.Column(
"currency_id",
sa.BigInteger(),
sa.ForeignKey(_fk("currency.id")),
nullable=False,
),
sa.Column("effective_from", sa.Date(), nullable=False),
sa.Column("rate", _PERCENT, nullable=False),
sa.Column(
"created_at",
sa.DateTime(timezone=True),
server_default=sa.func.now(),
nullable=False,
),
sa.Column("created_by", sa.String(255), nullable=False),
sa.Column(
"updated_at",
sa.DateTime(timezone=True),
server_default=sa.func.now(),
nullable=False,
),
sa.Column("updated_by", sa.String(255), nullable=False),
sa.UniqueConstraint(
"portfolio_id",
"currency_id",
"effective_from",
name="uq_funding_rate_portfolio_currency_date",
),
schema=_schema,
)
def downgrade() -> None:
"""Downgrade schema."""
op.drop_table("funding_rate", schema=_schema)