Add docstrings, simplify some code
This commit is contained in:
@@ -495,10 +495,16 @@ class LocalTrade:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def open_orders(self) -> List[Order]:
|
def open_orders(self) -> List[Order]:
|
||||||
|
"""
|
||||||
|
All open orders for this trade excluding stoploss orders
|
||||||
|
"""
|
||||||
return [o for o in self.orders if o.ft_is_open and o.ft_order_side != 'stoploss']
|
return [o for o in self.orders if o.ft_is_open and o.ft_order_side != 'stoploss']
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def has_open_orders(self) -> int:
|
def has_open_orders(self) -> int:
|
||||||
|
"""
|
||||||
|
True if there are open orders for this trade excluding stoploss orders
|
||||||
|
"""
|
||||||
open_orders_wo_sl = [
|
open_orders_wo_sl = [
|
||||||
o for o in self.orders
|
o for o in self.orders
|
||||||
if o.ft_order_side not in ['stoploss'] and o.ft_is_open
|
if o.ft_order_side not in ['stoploss'] and o.ft_is_open
|
||||||
|
|||||||
+12
-13
@@ -298,7 +298,7 @@ class RPC:
|
|||||||
]
|
]
|
||||||
|
|
||||||
# exemple: '*.**.**' trying to enter, exit and exit with 3 different orders
|
# exemple: '*.**.**' trying to enter, exit and exit with 3 different orders
|
||||||
active_attempt_side_symbols_str = '.'.join(map(str, active_attempt_side_symbols))
|
active_attempt_side_symbols_str = '.'.join(active_attempt_side_symbols)
|
||||||
|
|
||||||
detail_trade = [
|
detail_trade = [
|
||||||
f'{trade.id} {direction_str}',
|
f'{trade.id} {direction_str}',
|
||||||
@@ -787,7 +787,7 @@ class RPC:
|
|||||||
|
|
||||||
def __exec_force_exit(self, trade: Trade, ordertype: Optional[str],
|
def __exec_force_exit(self, trade: Trade, ordertype: Optional[str],
|
||||||
amount: Optional[float] = None) -> bool:
|
amount: Optional[float] = None) -> bool:
|
||||||
# Check if there is there is open orders
|
# Check if there is there are open orders
|
||||||
trade_entry_cancelation_registry = []
|
trade_entry_cancelation_registry = []
|
||||||
for oo in trade.open_orders:
|
for oo in trade.open_orders:
|
||||||
trade_entry_cancelation_res = {'order_id': oo.order_id, 'cancel_state': False}
|
trade_entry_cancelation_res = {'order_id': oo.order_id, 'cancel_state': False}
|
||||||
@@ -904,10 +904,10 @@ class RPC:
|
|||||||
if trade:
|
if trade:
|
||||||
is_short = trade.is_short
|
is_short = trade.is_short
|
||||||
if not self._freqtrade.strategy.position_adjustment_enable:
|
if not self._freqtrade.strategy.position_adjustment_enable:
|
||||||
raise RPCException(f'position for {pair} already open - id: {trade.id}')
|
raise RPCException(f"position for {pair} already open - id: {trade.id}")
|
||||||
if trade.has_open_orders:
|
if trade.has_open_orders:
|
||||||
raise RPCException(f'position for {pair} already open - id: {trade.id} '
|
raise RPCException(f"position for {pair} already open - id: {trade.id} "
|
||||||
f'and has open order {trade.open_orders_ids}')
|
f"and has open order {','.join(trade.open_orders_ids)}")
|
||||||
else:
|
else:
|
||||||
if Trade.get_open_trade_count() >= self._config['max_open_trades']:
|
if Trade.get_open_trade_count() >= self._config['max_open_trades']:
|
||||||
raise RPCException("Maximum number of trades is reached.")
|
raise RPCException("Maximum number of trades is reached.")
|
||||||
@@ -956,7 +956,7 @@ class RPC:
|
|||||||
raise RPCException("Order not found.")
|
raise RPCException("Order not found.")
|
||||||
self._freqtrade.handle_cancel_order(
|
self._freqtrade.handle_cancel_order(
|
||||||
order, open_order.order_id, trade, CANCEL_REASON['USER_CANCEL'])
|
order, open_order.order_id, trade, CANCEL_REASON['USER_CANCEL'])
|
||||||
Trade.commit()
|
Trade.commit()
|
||||||
|
|
||||||
def _rpc_delete(self, trade_id: int) -> Dict[str, Union[str, int]]:
|
def _rpc_delete(self, trade_id: int) -> Dict[str, Union[str, int]]:
|
||||||
"""
|
"""
|
||||||
@@ -971,13 +971,12 @@ class RPC:
|
|||||||
raise RPCException('invalid argument')
|
raise RPCException('invalid argument')
|
||||||
|
|
||||||
# Try cancelling regular order if that exists
|
# Try cancelling regular order if that exists
|
||||||
if trade.has_open_orders:
|
for open_order in trade.open_orders:
|
||||||
for open_order in trade.open_orders:
|
try:
|
||||||
try:
|
self._freqtrade.exchange.cancel_order(open_order.order_id, trade.pair)
|
||||||
self._freqtrade.exchange.cancel_order(open_order.order_id, trade.pair)
|
c_count += 1
|
||||||
c_count += 1
|
except (ExchangeError):
|
||||||
except (ExchangeError):
|
pass
|
||||||
pass
|
|
||||||
|
|
||||||
# cancel stoploss on exchange ...
|
# cancel stoploss on exchange ...
|
||||||
if (self._freqtrade.strategy.order_types.get('stoploss_on_exchange')
|
if (self._freqtrade.strategy.order_types.get('stoploss_on_exchange')
|
||||||
|
|||||||
Reference in New Issue
Block a user