fix: Remove agreed_price from price API response
The agreed_price depends on trade direction (buy/sell) and must be calculated on the frontend. Returning a buy-side-only agreed_price from the API was misleading and unused. Frontend already calculates the direction-aware price correctly.
This commit is contained in:
parent
1008eea2d9
commit
bf57fc6b77
7 changed files with 640 additions and 270 deletions
|
|
@ -61,10 +61,13 @@ class ExchangeConfigResponse(BaseModel):
|
|||
|
||||
|
||||
class PriceResponse(BaseModel):
|
||||
"""Current BTC/EUR price with premium applied."""
|
||||
"""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.
|
||||
"""
|
||||
|
||||
market_price: float # Raw price from exchange
|
||||
agreed_price: float # Price with premium applied
|
||||
premium_percentage: int
|
||||
timestamp: datetime
|
||||
is_stale: bool
|
||||
|
|
@ -115,13 +118,6 @@ def apply_premium_for_direction(
|
|||
return market_price * (1 - premium_percentage / 100)
|
||||
|
||||
|
||||
def apply_premium(market_price: float, premium_percentage: int) -> float:
|
||||
"""Apply buy-side premium (for price display)."""
|
||||
return apply_premium_for_direction(
|
||||
market_price, premium_percentage, TradeDirection.BUY
|
||||
)
|
||||
|
||||
|
||||
def calculate_sats_amount(
|
||||
eur_cents: int,
|
||||
price_eur_per_btc: float,
|
||||
|
|
@ -204,7 +200,7 @@ async def get_exchange_price(
|
|||
|
||||
The response includes:
|
||||
- market_price: The raw price from the exchange
|
||||
- agreed_price: The price with admin premium applied
|
||||
- premium_percentage: The premium to apply to trades
|
||||
- is_stale: Whether the price is older than 5 minutes
|
||||
- config: Trading configuration (min/max EUR, increment)
|
||||
"""
|
||||
|
|
@ -237,7 +233,6 @@ async def get_exchange_price(
|
|||
return ExchangePriceResponse(
|
||||
price=PriceResponse(
|
||||
market_price=price_value,
|
||||
agreed_price=apply_premium(price_value, PREMIUM_PERCENTAGE),
|
||||
premium_percentage=PREMIUM_PERCENTAGE,
|
||||
timestamp=timestamp,
|
||||
is_stale=False,
|
||||
|
|
@ -250,9 +245,6 @@ async def get_exchange_price(
|
|||
return ExchangePriceResponse(
|
||||
price=PriceResponse(
|
||||
market_price=cached_price.price,
|
||||
agreed_price=apply_premium(
|
||||
cached_price.price, PREMIUM_PERCENTAGE
|
||||
),
|
||||
premium_percentage=PREMIUM_PERCENTAGE,
|
||||
timestamp=cached_price.timestamp,
|
||||
is_stale=True,
|
||||
|
|
@ -271,7 +263,6 @@ async def get_exchange_price(
|
|||
return ExchangePriceResponse(
|
||||
price=PriceResponse(
|
||||
market_price=cached_price.price,
|
||||
agreed_price=apply_premium(cached_price.price, PREMIUM_PERCENTAGE),
|
||||
premium_percentage=PREMIUM_PERCENTAGE,
|
||||
timestamp=cached_price.timestamp,
|
||||
is_stale=is_price_stale(cached_price.timestamp),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue