Update "Query" type
This commit is contained in:
parent
db4f4498dc
commit
b65cff0adc
@ -1305,7 +1305,7 @@ class Trade(ModelBase, LocalTrade):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_trades(trade_filter=None, include_orders: bool = True) -> Query:
|
def get_trades(trade_filter=None, include_orders: bool = True) -> Query['Trade']:
|
||||||
"""
|
"""
|
||||||
Helper function to query Trades using filters.
|
Helper function to query Trades using filters.
|
||||||
NOTE: Not supported in Backtesting.
|
NOTE: Not supported in Backtesting.
|
||||||
|
@ -373,13 +373,13 @@ class RPC:
|
|||||||
|
|
||||||
def _rpc_trade_history(self, limit: int, offset: int = 0, order_by_id: bool = False) -> Dict:
|
def _rpc_trade_history(self, limit: int, offset: int = 0, order_by_id: bool = False) -> Dict:
|
||||||
""" Returns the X last trades """
|
""" Returns the X last trades """
|
||||||
order_by = Trade.id if order_by_id else Trade.close_date.desc()
|
order_by: Any = Trade.id if order_by_id else Trade.close_date.desc()
|
||||||
if limit:
|
if limit:
|
||||||
trades = Trade.get_trades([Trade.is_open.is_(False)]).order_by(
|
trades = Trade.get_trades([Trade.is_open.is_(False)]).order_by(
|
||||||
order_by).limit(limit).offset(offset)
|
order_by).limit(limit).offset(offset)
|
||||||
else:
|
else:
|
||||||
trades = Trade.get_trades([Trade.is_open.is_(False)]).order_by(
|
trades = Trade.get_trades([Trade.is_open.is_(False)]).order_by(
|
||||||
Trade.close_date.desc()).all()
|
Trade.close_date.desc())
|
||||||
|
|
||||||
output = [trade.to_json() for trade in trades]
|
output = [trade.to_json() for trade in trades]
|
||||||
|
|
||||||
@ -401,7 +401,7 @@ class RPC:
|
|||||||
return 'losses'
|
return 'losses'
|
||||||
else:
|
else:
|
||||||
return 'draws'
|
return 'draws'
|
||||||
trades: List[Trade] = Trade.get_trades([Trade.is_open.is_(False)], include_orders=False)
|
trades = Trade.get_trades([Trade.is_open.is_(False)], include_orders=False)
|
||||||
# Sell reason
|
# Sell reason
|
||||||
exit_reasons = {}
|
exit_reasons = {}
|
||||||
for trade in trades:
|
for trade in trades:
|
||||||
@ -785,7 +785,8 @@ class RPC:
|
|||||||
# check if valid pair
|
# check if valid pair
|
||||||
|
|
||||||
# check if pair already has an open pair
|
# check if pair already has an open pair
|
||||||
trade: Trade = Trade.get_trades([Trade.is_open.is_(True), Trade.pair == pair]).first()
|
trade: Optional[Trade] = Trade.get_trades(
|
||||||
|
[Trade.is_open.is_(True), Trade.pair == pair]).first()
|
||||||
is_short = (order_side == SignalDirection.SHORT)
|
is_short = (order_side == SignalDirection.SHORT)
|
||||||
if trade:
|
if trade:
|
||||||
is_short = trade.is_short
|
is_short = trade.is_short
|
||||||
|
@ -1055,10 +1055,14 @@ class Telegram(RPCHandler):
|
|||||||
query.answer()
|
query.answer()
|
||||||
query.edit_message_text(text="Force exit canceled.")
|
query.edit_message_text(text="Force exit canceled.")
|
||||||
return
|
return
|
||||||
trade: Trade = Trade.get_trades(trade_filter=Trade.id == trade_id).first()
|
trade: Optional[Trade] = Trade.get_trades(trade_filter=Trade.id == trade_id).first()
|
||||||
query.answer()
|
query.answer()
|
||||||
query.edit_message_text(text=f"Manually exiting Trade #{trade_id}, {trade.pair}")
|
if trade:
|
||||||
|
query.edit_message_text(
|
||||||
|
text=f"Manually exiting Trade #{trade_id}, {trade.pair}")
|
||||||
self._force_exit_action(trade_id)
|
self._force_exit_action(trade_id)
|
||||||
|
else:
|
||||||
|
query.edit_message_text(text=f"Trade {trade_id} not found.")
|
||||||
|
|
||||||
def _force_enter_action(self, pair, price: Optional[float], order_side: SignalDirection):
|
def _force_enter_action(self, pair, price: Optional[float], order_side: SignalDirection):
|
||||||
if pair != 'cancel':
|
if pair != 'cancel':
|
||||||
|
Loading…
Reference in New Issue
Block a user