Skip to content

Commit ccbc48b

Browse files
committed
refactor: improve method ordering
1 parent dde6001 commit ccbc48b

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

freqtrade/freqtradebot.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,44 +1479,6 @@ def handle_stoploss_on_exchange(self, trade: Trade) -> bool:
14791479

14801480
return False
14811481

1482-
def handle_trailing_stoploss_on_exchange(self, trade: Trade, order: CcxtOrder) -> None:
1483-
"""
1484-
Check to see if stoploss on exchange should be updated
1485-
in case of trailing stoploss on exchange
1486-
:param trade: Corresponding Trade
1487-
:param order: Current on exchange stoploss order
1488-
:return: None
1489-
"""
1490-
stoploss_norm = self.exchange.price_to_precision(
1491-
trade.pair,
1492-
trade.stoploss_or_liquidation,
1493-
rounding_mode=ROUND_DOWN if trade.is_short else ROUND_UP,
1494-
)
1495-
1496-
if self.exchange.stoploss_adjust(stoploss_norm, order, side=trade.exit_side):
1497-
# we check if the update is necessary
1498-
update_beat = self.strategy.order_types.get("stoploss_on_exchange_interval", 60)
1499-
upd_req = datetime.now(UTC) - timedelta(seconds=update_beat)
1500-
if trade.stoploss_last_update_utc and upd_req >= trade.stoploss_last_update_utc:
1501-
# cancelling the current stoploss on exchange first
1502-
logger.info(
1503-
f"Cancelling current stoploss on exchange for pair {trade.pair} "
1504-
f"(orderid:{order['id']}) in order to add another one ..."
1505-
)
1506-
1507-
self.cancel_stoploss_on_exchange(trade)
1508-
if not trade.is_open:
1509-
logger.warning(
1510-
f"Trade {trade} is closed, not creating trailing stoploss order."
1511-
)
1512-
return
1513-
1514-
# Create new stoploss order
1515-
if not self.create_stoploss_order(trade=trade, stop_price=stoploss_norm):
1516-
logger.warning(
1517-
f"Could not create trailing stoploss order for pair {trade.pair}."
1518-
)
1519-
15201482
def manage_trade_stoploss_orders(self, trade: Trade, stoploss_orders: list[CcxtOrder]):
15211483
"""
15221484
Perform required actions according to existing stoploss orders of trade
@@ -1558,6 +1520,44 @@ def manage_trade_stoploss_orders(self, trade: Trade, stoploss_orders: list[CcxtO
15581520

15591521
return
15601522

1523+
def handle_trailing_stoploss_on_exchange(self, trade: Trade, order: CcxtOrder) -> None:
1524+
"""
1525+
Check to see if stoploss on exchange should be updated
1526+
in case of trailing stoploss on exchange
1527+
:param trade: Corresponding Trade
1528+
:param order: Current on exchange stoploss order
1529+
:return: None
1530+
"""
1531+
stoploss_norm = self.exchange.price_to_precision(
1532+
trade.pair,
1533+
trade.stoploss_or_liquidation,
1534+
rounding_mode=ROUND_DOWN if trade.is_short else ROUND_UP,
1535+
)
1536+
1537+
if self.exchange.stoploss_adjust(stoploss_norm, order, side=trade.exit_side):
1538+
# we check if the update is necessary
1539+
update_beat = self.strategy.order_types.get("stoploss_on_exchange_interval", 60)
1540+
upd_req = datetime.now(UTC) - timedelta(seconds=update_beat)
1541+
if trade.stoploss_last_update_utc and upd_req >= trade.stoploss_last_update_utc:
1542+
# cancelling the current stoploss on exchange first
1543+
logger.info(
1544+
f"Cancelling current stoploss on exchange for pair {trade.pair} "
1545+
f"(orderid:{order['id']}) in order to add another one ..."
1546+
)
1547+
1548+
self.cancel_stoploss_on_exchange(trade)
1549+
if not trade.is_open:
1550+
logger.warning(
1551+
f"Trade {trade} is closed, not creating trailing stoploss order."
1552+
)
1553+
return
1554+
1555+
# Create new stoploss order
1556+
if not self.create_stoploss_order(trade=trade, stop_price=stoploss_norm):
1557+
logger.warning(
1558+
f"Could not create trailing stoploss order for pair {trade.pair}."
1559+
)
1560+
15611561
def manage_open_orders(self) -> None:
15621562
"""
15631563
Management of open orders on exchange. Unfilled orders might be cancelled if timeout

0 commit comments

Comments
 (0)