Step 5: Update exchange price endpoint to use new pricing config

- Update ExchangeConfigResponse schema with direction-specific fields
- Remove premium_percentage from PriceResponse (now in config)
- Update price endpoint to load pricing config from database
- Update frontend to use direction-specific min/max and calculate premium
- Update tests to seed pricing config
- Add logic to clamp amount when direction changes
This commit is contained in:
counterweight 2025-12-26 20:20:23 +01:00
parent d838d1be96
commit d317939ad0
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
5 changed files with 145 additions and 44 deletions

View file

@ -17,21 +17,27 @@ class PriceHistoryResponse(BaseModel):
class ExchangeConfigResponse(BaseModel):
"""Exchange configuration for the frontend."""
eur_min: int
eur_max: int
eur_min_buy: int
eur_max_buy: int
eur_min_sell: int
eur_max_sell: int
eur_increment: int
premium_percentage: int
premium_buy: int
premium_sell: int
small_trade_threshold_eur: int
small_trade_extra_premium: int
class PriceResponse(BaseModel):
"""Current BTC/EUR price for trading.
Note: The actual agreed price depends on trade direction (buy/sell)
and is calculated by the frontend using market_price and premium_percentage.
and is calculated by the frontend using market_price and premium values.
Premium calculation: base premium for direction + extra premium if
trade <= threshold.
"""
market_price: float # Raw price from exchange
premium_percentage: int
timestamp: datetime
is_stale: bool