Spaces:
Sleeping
Sleeping
File size: 2,259 Bytes
02e0144 55db3a6 02e0144 55db3a6 02e0144 55db3a6 02e0144 55db3a6 02e0144 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
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
@property
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
)
@property
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}%",
}
|