Simplify forcesell method by using freqtrade methods
This commit is contained in:
parent
add78414e4
commit
85e71275d3
@ -11,6 +11,7 @@ from typing import Any, Dict, List, Optional, Tuple, Union
|
|||||||
import arrow
|
import arrow
|
||||||
from numpy import NAN, mean
|
from numpy import NAN, mean
|
||||||
|
|
||||||
|
from freqtrade.constants import CANCEL_REASON
|
||||||
from freqtrade.exceptions import (ExchangeError,
|
from freqtrade.exceptions import (ExchangeError,
|
||||||
PricingError)
|
PricingError)
|
||||||
from freqtrade.exchange import timeframe_to_minutes, timeframe_to_msecs
|
from freqtrade.exchange import timeframe_to_minutes, timeframe_to_msecs
|
||||||
@ -453,26 +454,19 @@ class RPC:
|
|||||||
"""
|
"""
|
||||||
def _exec_forcesell(trade: Trade) -> None:
|
def _exec_forcesell(trade: Trade) -> None:
|
||||||
# Check if there is there is an open order
|
# Check if there is there is an open order
|
||||||
|
fully_canceled = False
|
||||||
if trade.open_order_id:
|
if trade.open_order_id:
|
||||||
order = self._freqtrade.exchange.fetch_order(trade.open_order_id, trade.pair)
|
order = self._freqtrade.exchange.fetch_order(trade.open_order_id, trade.pair)
|
||||||
|
|
||||||
# Cancel open LIMIT_BUY orders and close trade
|
if order['side'] == 'buy':
|
||||||
if order and order['status'] == 'open' \
|
fully_canceled = self._freqtrade.handle_cancel_buy(
|
||||||
and order['type'] == 'limit' \
|
trade, order, CANCEL_REASON['FORCE_SELL'])
|
||||||
and order['side'] == 'buy':
|
|
||||||
self._freqtrade.exchange.cancel_order(trade.open_order_id, trade.pair)
|
|
||||||
trade.close(order.get('price') or trade.open_rate)
|
|
||||||
# Do the best effort, if we don't know 'filled' amount, don't try selling
|
|
||||||
if order['filled'] is None:
|
|
||||||
return
|
|
||||||
trade.amount = order['filled']
|
|
||||||
|
|
||||||
# Ignore trades with an attached LIMIT_SELL order
|
if order['side'] == 'sell':
|
||||||
if order and order['status'] == 'open' \
|
# Cancel order - so it is placed anew with a fresh price.
|
||||||
and order['type'] == 'limit' \
|
self._freqtrade.handle_cancel_sell(trade, order, CANCEL_REASON['FORCE_SELL'])
|
||||||
and order['side'] == 'sell':
|
|
||||||
return
|
|
||||||
|
|
||||||
|
if not fully_canceled:
|
||||||
# Get current rate and execute sell
|
# Get current rate and execute sell
|
||||||
current_rate = self._freqtrade.get_sell_rate(trade.pair, False)
|
current_rate = self._freqtrade.get_sell_rate(trade.pair, False)
|
||||||
self._freqtrade.execute_sell(trade, current_rate, SellType.FORCE_SELL)
|
self._freqtrade.execute_sell(trade, current_rate, SellType.FORCE_SELL)
|
||||||
|
Loading…
Reference in New Issue
Block a user