Use Mapped for LocalTrade

this won't initialize sqlalchemy, as the base class is not inheriting from sqlalchemy.
This commit is contained in:
Matthias 2023-02-28 07:24:20 +01:00
parent d175ab495b
commit 0f914cf2bd

View File

@ -288,76 +288,76 @@ class LocalTrade():
bt_trades_open_pp: Dict[str, List['LocalTrade']] = defaultdict(list) bt_trades_open_pp: Dict[str, List['LocalTrade']] = defaultdict(list)
bt_open_open_trade_count: int = 0 bt_open_open_trade_count: int = 0
total_profit: float = 0 total_profit: float = 0
realized_profit: float = 0 realized_profit: Mapped[float] = 0 # type: ignore
id: int = 0 id: Mapped[int] = 0 # type: ignore
orders: List[Order] = [] orders: Mapped[List[Order]] = [] # type: ignore
exchange: str = '' exchange: Mapped[str] = '' # type: ignore
pair: str = '' pair: Mapped[str] = '' # type: ignore
base_currency: str = '' base_currency: Mapped[Optional[str]] = '' # type: ignore
stake_currency: str = '' stake_currency: Mapped[Optional[str]] = '' # type: ignore
is_open: bool = True is_open: Mapped[bool] = True # type: ignore
fee_open: float = 0.0 fee_open: Mapped[float] = 0.0 # type: ignore
fee_open_cost: Optional[float] = None fee_open_cost: Mapped[Optional[float]] = None # type: ignore
fee_open_currency: str = '' fee_open_currency: Mapped[Optional[str]] = '' # type: ignore
fee_close: float = 0.0 fee_close: Mapped[Optional[float]] = 0.0 # type: ignore
fee_close_cost: Optional[float] = None fee_close_cost: Mapped[Optional[float]] = None # type: ignore
fee_close_currency: str = '' fee_close_currency: Mapped[Optional[str]] = '' # type: ignore
open_rate: float = 0.0 open_rate: Mapped[float] = 0.0 # type: ignore
open_rate_requested: Optional[float] = None open_rate_requested: Mapped[Optional[float]] = None # type: ignore
# open_trade_value - calculated via _calc_open_trade_value # open_trade_value - calculated via _calc_open_trade_value
open_trade_value: float = 0.0 open_trade_value: Mapped[float] = 0.0 # type: ignore
close_rate: Optional[float] = None close_rate: Mapped[Optional[float]] = None # type: ignore
close_rate_requested: Optional[float] = None close_rate_requested: Mapped[Optional[float]] = None # type: ignore
close_profit: Optional[float] = None close_profit: Mapped[Optional[float]] = None # type: ignore
close_profit_abs: Optional[float] = None close_profit_abs: Mapped[Optional[float]] = None # type: ignore
stake_amount: float = 0.0 stake_amount: Mapped[float] = 0.0 # type: ignore
max_stake_amount: float = 0.0 max_stake_amount: Mapped[Optional[float]] = 0.0 # type: ignore
amount: float = 0.0 amount: Mapped[float] = 0.0 # type: ignore
amount_requested: Optional[float] = None amount_requested: Mapped[Optional[float]] = None # type: ignore
open_date: datetime open_date: Mapped[datetime]
close_date: Optional[datetime] = None close_date: Mapped[Optional[datetime]] = None # type: ignore
open_order_id: Optional[str] = None open_order_id: Mapped[Optional[str]] = None # type: ignore
# absolute value of the stop loss # absolute value of the stop loss
stop_loss: float = 0.0 stop_loss: Mapped[float] = 0.0 # type: ignore
# percentage value of the stop loss # percentage value of the stop loss
stop_loss_pct: float = 0.0 stop_loss_pct: Mapped[Optional[float]] = 0.0 # type: ignore
# absolute value of the initial stop loss # absolute value of the initial stop loss
initial_stop_loss: float = 0.0 initial_stop_loss: Mapped[Optional[float]] = 0.0 # type: ignore
# percentage value of the initial stop loss # percentage value of the initial stop loss
initial_stop_loss_pct: Optional[float] = None initial_stop_loss_pct: Mapped[Optional[float]] = None # type: ignore
# stoploss order id which is on exchange # stoploss order id which is on exchange
stoploss_order_id: Optional[str] = None stoploss_order_id: Mapped[Optional[str]] = None # type: ignore
# last update time of the stoploss order on exchange # last update time of the stoploss order on exchange
stoploss_last_update: Optional[datetime] = None stoploss_last_update: Mapped[Optional[datetime]] = None # type: ignore
# absolute value of the highest reached price # absolute value of the highest reached price
max_rate: float = 0.0 max_rate: Mapped[Optional[float]] = None # type: ignore
# Lowest price reached # Lowest price reached
min_rate: float = 0.0 min_rate: Mapped[Optional[float]] = None # type: ignore
exit_reason: str = '' exit_reason: Mapped[Optional[str]] = '' # type: ignore
exit_order_status: str = '' exit_order_status: Mapped[Optional[str]] = '' # type: ignore
strategy: str = '' strategy: Mapped[Optional[str]] = '' # type: ignore
enter_tag: Optional[str] = None enter_tag: Mapped[Optional[str]] = None # type: ignore
timeframe: Optional[int] = None timeframe: Mapped[Optional[int]] = None # type: ignore
trading_mode: TradingMode = TradingMode.SPOT trading_mode: Mapped[TradingMode] = TradingMode.SPOT # type: ignore
amount_precision: Optional[float] = None amount_precision: Mapped[Optional[float]] = None # type: ignore
price_precision: Optional[float] = None price_precision: Mapped[Optional[float]] = None # type: ignore
precision_mode: Optional[int] = None precision_mode: Mapped[Optional[int]] = None # type: ignore
contract_size: Optional[float] = None contract_size: Mapped[Optional[float]] = None # type: ignore
# Leverage trading properties # Leverage trading properties
liquidation_price: Optional[float] = None liquidation_price: Mapped[Optional[float]] = None # type: ignore
is_short: bool = False is_short: Mapped[bool] = False # type: ignore
leverage: float = 1.0 leverage: Mapped[float] = 1.0 # type: ignore
# Margin trading properties # Margin trading properties
interest_rate: float = 0.0 interest_rate: Mapped[float] = 0.0 # type: ignore
# Futures properties # Futures properties
funding_fees: Optional[float] = None funding_fees: Mapped[Optional[float]] = None # type: ignore
@property @property
def stoploss_or_liquidation(self) -> float: def stoploss_or_liquidation(self) -> float:
@ -1175,7 +1175,7 @@ class Trade(ModelBase, LocalTrade):
""" """
__tablename__ = 'trades' __tablename__ = 'trades'
query: ClassVar[_QueryDescriptorType] query: ClassVar[_QueryDescriptorType]
session: ClassVar[SessionType] = None session: ClassVar[SessionType]
use_db: bool = True use_db: bool = True
@ -1197,7 +1197,7 @@ class Trade(ModelBase, LocalTrade):
fee_close_cost: Mapped[Optional[float]] = mapped_column(Float(), nullable=True) fee_close_cost: Mapped[Optional[float]] = mapped_column(Float(), nullable=True)
fee_close_currency: Mapped[Optional[str]] = mapped_column(String(25), nullable=True) fee_close_currency: Mapped[Optional[str]] = mapped_column(String(25), nullable=True)
open_rate: Mapped[float] = mapped_column(Float()) open_rate: Mapped[float] = mapped_column(Float())
open_rate_requested: Mapped[float] = mapped_column(Float(), nullable=True) open_rate_requested: Mapped[Optional[float]] = mapped_column(Float(), nullable=True)
# open_trade_value - calculated via _calc_open_trade_value # open_trade_value - calculated via _calc_open_trade_value
open_trade_value = mapped_column(Float()) open_trade_value = mapped_column(Float())
close_rate: Mapped[Optional[float]] = mapped_column(Float()) close_rate: Mapped[Optional[float]] = mapped_column(Float())
@ -1246,7 +1246,7 @@ class Trade(ModelBase, LocalTrade):
liquidation_price: Mapped[Optional[float]] = mapped_column(Float(), nullable=True) liquidation_price: Mapped[Optional[float]] = mapped_column(Float(), nullable=True)
# Margin Trading Properties # Margin Trading Properties
interest_rate: Mapped[Optional[float]] = mapped_column(Float(), nullable=False, default=0.0) interest_rate: Mapped[float] = mapped_column(Float(), nullable=False, default=0.0)
# Futures properties # Futures properties
funding_fees: Mapped[Optional[float]] = mapped_column(Float(), nullable=True, default=None) funding_fees: Mapped[Optional[float]] = mapped_column(Float(), nullable=True, default=None)