Improve some type safety

This commit is contained in:
Matthias
2024-02-24 08:06:06 +01:00
committed by Joe Schr
parent 7d9ecb7bea
commit f3f4a659e8
2 changed files with 9 additions and 9 deletions
+4 -4
View File
@@ -986,7 +986,7 @@ class FreqtradeBot(LoggingMixin):
return enter_limit_requested, stake_amount, leverage return enter_limit_requested, stake_amount, leverage
def _notify_enter(self, trade: Trade, order: Order, order_type: str, def _notify_enter(self, trade: Trade, order: Order, order_type: Optional[str],
fill: bool = False, sub_trade: bool = False) -> None: fill: bool = False, sub_trade: bool = False) -> None:
""" """
Sends rpc notification when a entry order occurred. Sends rpc notification when a entry order occurred.
@@ -1010,7 +1010,7 @@ class FreqtradeBot(LoggingMixin):
'direction': 'Short' if trade.is_short else 'Long', 'direction': 'Short' if trade.is_short else 'Long',
'limit': open_rate, # Deprecated (?) 'limit': open_rate, # Deprecated (?)
'open_rate': open_rate, 'open_rate': open_rate,
'order_type': order_type, 'order_type': order_type or 'unknown',
'stake_amount': trade.stake_amount, 'stake_amount': trade.stake_amount,
'stake_currency': self.config['stake_currency'], 'stake_currency': self.config['stake_currency'],
'base_currency': self.exchange.get_pair_base_currency(trade.pair), 'base_currency': self.exchange.get_pair_base_currency(trade.pair),
@@ -1775,7 +1775,7 @@ class FreqtradeBot(LoggingMixin):
return True return True
def _notify_exit(self, trade: Trade, order_type: str, fill: bool = False, def _notify_exit(self, trade: Trade, order_type: Optional[str], fill: bool = False,
sub_trade: bool = False, order: Optional[Order] = None) -> None: sub_trade: bool = False, order: Optional[Order] = None) -> None:
""" """
Sends rpc notification when a sell occurred. Sends rpc notification when a sell occurred.
@@ -1807,7 +1807,7 @@ class FreqtradeBot(LoggingMixin):
'gain': gain, 'gain': gain,
'limit': order_rate, # Deprecated 'limit': order_rate, # Deprecated
'order_rate': order_rate, 'order_rate': order_rate,
'order_type': order_type, 'order_type': order_type or 'unknown',
'amount': amount, 'amount': amount,
'open_rate': trade.open_rate, 'open_rate': trade.open_rate,
'close_rate': order_rate, 'close_rate': order_rate,
+5 -5
View File
@@ -73,8 +73,7 @@ class Order(ModelBase):
order_id: Mapped[str] = mapped_column(String(255), nullable=False, index=True) order_id: Mapped[str] = mapped_column(String(255), nullable=False, index=True)
status: Mapped[Optional[str]] = mapped_column(String(255), nullable=True) status: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
symbol: Mapped[Optional[str]] = mapped_column(String(25), nullable=True) symbol: Mapped[Optional[str]] = mapped_column(String(25), nullable=True)
# TODO: type: order_type type is Optional[str] order_type: Mapped[Optional[str]] = mapped_column(String(50), nullable=True)
order_type: Mapped[str] = mapped_column(String(50), nullable=True)
side: Mapped[str] = mapped_column(String(25), nullable=True) side: Mapped[str] = mapped_column(String(25), nullable=True)
price: Mapped[Optional[float]] = mapped_column(Float(), nullable=True) price: Mapped[Optional[float]] = mapped_column(Float(), nullable=True)
average: Mapped[Optional[float]] = mapped_column(Float(), nullable=True) average: Mapped[Optional[float]] = mapped_column(Float(), nullable=True)
@@ -815,6 +814,7 @@ class LocalTrade:
order.funding_fee = self.funding_fee_running order.funding_fee = self.funding_fee_running
# Reset running funding fees # Reset running funding fees
self.funding_fee_running = 0.0 self.funding_fee_running = 0.0
order_type = order.order_type.upper() if order.order_type else None
if order.ft_order_side == self.entry_side: if order.ft_order_side == self.entry_side:
# Update open rate and actual amount # Update open rate and actual amount
@@ -822,20 +822,20 @@ class LocalTrade:
self.amount = order.safe_amount_after_fee self.amount = order.safe_amount_after_fee
if self.is_open: if self.is_open:
payment = "SELL" if self.is_short else "BUY" payment = "SELL" if self.is_short else "BUY"
logger.info(f'{order.order_type.upper()}_{payment} has been fulfilled for {self}.') logger.info(f'{order_type}_{payment} has been fulfilled for {self}.')
self.recalc_trade_from_orders() self.recalc_trade_from_orders()
elif order.ft_order_side == self.exit_side: elif order.ft_order_side == self.exit_side:
if self.is_open: if self.is_open:
payment = "BUY" if self.is_short else "SELL" payment = "BUY" if self.is_short else "SELL"
# * On margin shorts, you buy a little bit more than the amount (amount + interest) # * On margin shorts, you buy a little bit more than the amount (amount + interest)
logger.info(f'{order.order_type.upper()}_{payment} has been fulfilled for {self}.') logger.info(f'{order_type}_{payment} has been fulfilled for {self}.')
elif order.ft_order_side == 'stoploss' and order.status not in ('open', ): elif order.ft_order_side == 'stoploss' and order.status not in ('open', ):
self.close_rate_requested = self.stop_loss self.close_rate_requested = self.stop_loss
self.exit_reason = ExitType.STOPLOSS_ON_EXCHANGE.value self.exit_reason = ExitType.STOPLOSS_ON_EXCHANGE.value
if self.is_open and order.safe_filled > 0: if self.is_open and order.safe_filled > 0:
logger.info(f'{order.order_type.upper()} is hit for {self}.') logger.info(f'{order_type} is hit for {self}.')
else: else:
raise ValueError(f'Unknown order type: {order.order_type}') raise ValueError(f'Unknown order type: {order.order_type}')