Merge pull request #4228 from baartch/develop

Extending the Telegram Bot command /status with the possibility to query specific trade_ids
This commit is contained in:
Matthias
2021-01-19 20:08:49 +01:00
committed by GitHub
5 changed files with 39 additions and 9 deletions

View File

@@ -145,13 +145,17 @@ class RPC:
}
return val
def _rpc_trade_status(self) -> List[Dict[str, Any]]:
def _rpc_trade_status(self, trade_ids: List[int] = []) -> List[Dict[str, Any]]:
"""
Below follows the RPC backend it is prefixed with rpc_ to raise awareness that it is
a remotely exposed function
"""
# Fetch open trade
trades = Trade.get_open_trades()
# Fetch open trades
if trade_ids:
trades = Trade.get_trades(trade_filter=Trade.id.in_(trade_ids)).all()
else:
trades = Trade.get_open_trades()
if not trades:
raise RPCException('no active trade')
else:

View File

@@ -277,7 +277,14 @@ class Telegram(RPCHandler):
return
try:
results = self._rpc._rpc_trade_status()
# Check if there's at least one numerical ID provided.
# If so, try to get only these trades.
trade_ids = []
if context.args and len(context.args) > 0:
trade_ids = [int(i) for i in context.args if i.isnumeric()]
results = self._rpc._rpc_trade_status(trade_ids=trade_ids)
messages = []
for r in results:
@@ -815,7 +822,9 @@ class Telegram(RPCHandler):
"Optionally takes a rate at which to buy.` \n")
message = ("*/start:* `Starts the trader`\n"
"*/stop:* `Stops the trader`\n"
"*/status [table]:* `Lists all open trades`\n"
"*/status <trade_id>|[table]:* `Lists all open trades`\n"
" *<trade_id> :* `Lists one or more specific trades.`\n"
" `Separate multiple <trade_id> with a blank space.`\n"
" *table :* `will display trades in a table`\n"
" `pending buy orders are marked with an asterisk (*)`\n"
" `pending sell orders are marked with a double asterisk (**)`\n"