- Create PricingConfig model with all required fields (premium settings, trade limits) - Implement PricingRepository with singleton pattern (get_current, create_or_update) - Add comprehensive tests for repository functionality - Export model and repository in __init__.py files
44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
from datetime import UTC, datetime
|
|
|
|
from sqlalchemy import DateTime, Integer
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from database import Base
|
|
|
|
|
|
class PricingConfig(Base):
|
|
"""Pricing configuration for exchange trades.
|
|
|
|
Singleton pattern: Only one record should exist in the database.
|
|
Updates modify the existing record rather than creating new ones.
|
|
"""
|
|
|
|
__tablename__ = "pricing_config"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
|
|
# Premium settings
|
|
premium_buy: Mapped[int] = mapped_column(Integer, nullable=False) # -100 to 100
|
|
premium_sell: Mapped[int] = mapped_column(Integer, nullable=False) # -100 to 100
|
|
small_trade_threshold_eur: Mapped[int] = mapped_column(
|
|
Integer, nullable=False
|
|
) # EUR cents, e.g., 20000 = €200
|
|
small_trade_extra_premium: Mapped[int] = mapped_column(
|
|
Integer, nullable=False
|
|
) # -100 to 100
|
|
|
|
# Trade amount limits (EUR cents)
|
|
eur_min_buy: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
eur_max_buy: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
eur_min_sell: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
eur_max_sell: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
|
|
# Timestamps
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), default=lambda: datetime.now(UTC)
|
|
)
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True),
|
|
default=lambda: datetime.now(UTC),
|
|
onupdate=lambda: datetime.now(UTC),
|
|
)
|