Spaces:
Sleeping
Sleeping
from enum import Enum | |
from pydantic import BaseModel, Field | |
class TradeDirection(str, Enum): | |
LONG = "long" | |
SHORT = "short" | |
class RecommendationType(str, Enum): | |
RECOMMENDED = "It is recommended to enter the transaction." | |
NOT_RECOMMENDED = "It is not recommended to enter into a transaction." | |
CAUTIOUS = "Entering the trade with caution" | |
class TakeProfitPoints(BaseModel): | |
first: float = Field(..., description="First take profit") | |
second: float = Field(..., description="Second take profit") | |
third: float = Field(..., description="Third take profit") | |
class TradeSuggestion(BaseModel): | |
symbol: str | |
direction: TradeDirection | |
entry_price: float | |
recommended_leverage: int | |
take_profit: TakeProfitPoints | |
recommendation: RecommendationType | |
current_price: float | |
trade_amount: float | |
def is_entry_better_than_current(self) -> bool: | |
return ( | |
self.entry_price <= self.current_price | |
if self.direction == TradeDirection.LONG | |
else self.entry_price >= self.current_price | |
) | |
def potential_profit_percentage(self) -> float: | |
if self.direction == TradeDirection.LONG: | |
return ( | |
((self.take_profit.third - self.entry_price) / self.entry_price) | |
* 100 | |
* self.recommended_leverage | |
) | |
return ( | |
((self.entry_price - self.take_profit.third) / self.entry_price) | |
* 100 | |
* self.recommended_leverage | |
) | |
def to_prompt_dict(self) -> dict: | |
return { | |
"symbol": self.symbol, | |
"direction": self.direction.value, | |
"entry_price": f"${self.entry_price:.2f}", | |
"leverage": f"{self.recommended_leverage}x", | |
"take_profit_1": f"${self.take_profit.first:.2f}", | |
"take_profit_2": f"${self.take_profit.second:.2f}", | |
"take_profit_3": f"${self.take_profit.third:.2f}", | |
"recommendation": self.recommendation.value, | |
"current_price": f"${self.current_price:.2f}", | |
"trade_amount": f"${self.trade_amount:.2f}", | |
"potential_profit": f"{self.potential_profit_percentage:.2f}%", | |
} | |