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
|
||||
from numpy import NAN, mean
|
||||
|
||||
from freqtrade.constants import CANCEL_REASON
|
||||
from freqtrade.exceptions import (ExchangeError,
|
||||
PricingError)
|
||||
from freqtrade.exchange import timeframe_to_minutes, timeframe_to_msecs
|
||||
@ -453,29 +454,22 @@ class RPC:
|
||||
"""
|
||||
def _exec_forcesell(trade: Trade) -> None:
|
||||
# Check if there is there is an open order
|
||||
fully_canceled = False
|
||||
if trade.open_order_id:
|
||||
order = self._freqtrade.exchange.fetch_order(trade.open_order_id, trade.pair)
|
||||
|
||||
# Cancel open LIMIT_BUY orders and close trade
|
||||
if order and order['status'] == 'open' \
|
||||
and order['type'] == 'limit' \
|
||||
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']
|
||||
if order['side'] == 'buy':
|
||||
fully_canceled = self._freqtrade.handle_cancel_buy(
|
||||
trade, order, CANCEL_REASON['FORCE_SELL'])
|
||||
|
||||
# Ignore trades with an attached LIMIT_SELL order
|
||||
if order and order['status'] == 'open' \
|
||||
and order['type'] == 'limit' \
|
||||
and order['side'] == 'sell':
|
||||
return
|
||||
if order['side'] == 'sell':
|
||||
# Cancel order - so it is placed anew with a fresh price.
|
||||
self._freqtrade.handle_cancel_sell(trade, order, CANCEL_REASON['FORCE_SELL'])
|
||||
|
||||
# Get current rate and execute sell
|
||||
current_rate = self._freqtrade.get_sell_rate(trade.pair, False)
|
||||
self._freqtrade.execute_sell(trade, current_rate, SellType.FORCE_SELL)
|
||||
if not fully_canceled:
|
||||
# Get current rate and execute sell
|
||||
current_rate = self._freqtrade.get_sell_rate(trade.pair, False)
|
||||
self._freqtrade.execute_sell(trade, current_rate, SellType.FORCE_SELL)
|
||||
# ---- EOF def _exec_forcesell ----
|
||||
|
||||
if self._freqtrade.state != State.RUNNING:
|
||||
|
Loading…
Reference in New Issue
Block a user