Step 1: Add PricingConfig model and PricingRepository
- 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
This commit is contained in:
parent
82c4d0168e
commit
32ce27180d
5 changed files with 291 additions and 0 deletions
|
|
@ -14,6 +14,7 @@ from .enums import (
|
|||
from .exchange import Exchange
|
||||
from .invite import Invite
|
||||
from .price_history import PriceHistory
|
||||
from .pricing_config import PricingConfig
|
||||
|
||||
# Export role configuration
|
||||
from .role_config import ROLE_ADMIN, ROLE_DEFINITIONS, ROLE_REGULAR
|
||||
|
|
@ -34,6 +35,7 @@ __all__ = [
|
|||
"InviteStatus",
|
||||
"Permission",
|
||||
"PriceHistory",
|
||||
"PricingConfig",
|
||||
"Role",
|
||||
"RoleConfig",
|
||||
"TradeDirection",
|
||||
|
|
|
|||
44
backend/models/pricing_config.py
Normal file
44
backend/models/pricing_config.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
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),
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue