Avoid online call when asking for /status.

This commit is contained in:
Matthias 2022-09-28 06:47:46 +02:00
parent a06372c7b2
commit 7c84edbc23
2 changed files with 4 additions and 5 deletions

View File

@ -25,7 +25,7 @@ from freqtrade.exceptions import ExchangeError, PricingError
from freqtrade.exchange import timeframe_to_minutes, timeframe_to_msecs from freqtrade.exchange import timeframe_to_minutes, timeframe_to_msecs
from freqtrade.loggers import bufferHandler from freqtrade.loggers import bufferHandler
from freqtrade.misc import decimals_per_coin, shorten_date from freqtrade.misc import decimals_per_coin, shorten_date
from freqtrade.persistence import PairLocks, Trade from freqtrade.persistence import Order, PairLocks, Trade
from freqtrade.persistence.models import PairLock from freqtrade.persistence.models import PairLock
from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist
from freqtrade.rpc.fiat_convert import CryptoToFiatConverter from freqtrade.rpc.fiat_convert import CryptoToFiatConverter
@ -166,9 +166,9 @@ class RPC:
else: else:
results = [] results = []
for trade in trades: for trade in trades:
order = None order: Optional[Order] = None
if trade.open_order_id: if trade.open_order_id:
order = self._freqtrade.exchange.fetch_order(trade.open_order_id, trade.pair) order = trade.select_order_by_order_id(trade.open_order_id)
# calculate profit and send message to user # calculate profit and send message to user
if trade.is_open: if trade.is_open:
try: try:
@ -219,7 +219,7 @@ class RPC:
stoploss_entry_dist=stoploss_entry_dist, stoploss_entry_dist=stoploss_entry_dist,
stoploss_entry_dist_ratio=round(stoploss_entry_dist_ratio, 8), stoploss_entry_dist_ratio=round(stoploss_entry_dist_ratio, 8),
open_order='({} {} rem={:.8f})'.format( open_order='({} {} rem={:.8f})'.format(
order['type'], order['side'], order['remaining'] order.order_type, order.side, order.remaining
) if order else None, ) if order else None,
)) ))
results.append(trade_dict) results.append(trade_dict)

View File

@ -45,7 +45,6 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
freqtradebot.enter_positions() freqtradebot.enter_positions()
trades = Trade.get_open_trades() trades = Trade.get_open_trades()
trades[0].open_order_id = None
freqtradebot.exit_positions(trades) freqtradebot.exit_positions(trades)
results = rpc._rpc_trade_status() results = rpc._rpc_trade_status()