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:
commit
20591b539a
@ -113,7 +113,7 @@ Telegram is not mandatory. However, this is a great way to control your bot. Mor
|
|||||||
- `/start`: Starts the trader.
|
- `/start`: Starts the trader.
|
||||||
- `/stop`: Stops the trader.
|
- `/stop`: Stops the trader.
|
||||||
- `/stopbuy`: Stop entering new trades.
|
- `/stopbuy`: Stop entering new trades.
|
||||||
- `/status [table]`: Lists all open trades.
|
- `/status <trade_id>|[table]`: Lists all or specific open trades.
|
||||||
- `/profit`: Lists cumulative profit from all finished trades
|
- `/profit`: Lists cumulative profit from all finished trades
|
||||||
- `/forcesell <trade_id>|all`: Instantly sells the given trade (Ignoring `minimum_roi`).
|
- `/forcesell <trade_id>|all`: Instantly sells the given trade (Ignoring `minimum_roi`).
|
||||||
- `/performance`: Show performance of each finished trade grouped by pair
|
- `/performance`: Show performance of each finished trade grouped by pair
|
||||||
|
@ -137,6 +137,7 @@ official commands. You can ask at any moment for help with `/help`.
|
|||||||
| `/show_config` | Shows part of the current configuration with relevant settings to operation
|
| `/show_config` | Shows part of the current configuration with relevant settings to operation
|
||||||
| `/logs [limit]` | Show last log messages.
|
| `/logs [limit]` | Show last log messages.
|
||||||
| `/status` | Lists all open trades
|
| `/status` | Lists all open trades
|
||||||
|
| `/status <trade_id>` | Lists one or more specific trade. Separate multiple <trade_id> with a blank space.
|
||||||
| `/status table` | List all open trades in a table format. Pending buy orders are marked with an asterisk (*) Pending sell orders are marked with a double asterisk (**)
|
| `/status table` | List all open trades in a table format. Pending buy orders are marked with an asterisk (*) Pending sell orders are marked with a double asterisk (**)
|
||||||
| `/trades [limit]` | List all recently closed trades in a table format.
|
| `/trades [limit]` | List all recently closed trades in a table format.
|
||||||
| `/delete <trade_id>` | Delete a specific trade from the Database. Tries to close open orders. Requires manual handling of this trade on the exchange.
|
| `/delete <trade_id>` | Delete a specific trade from the Database. Tries to close open orders. Requires manual handling of this trade on the exchange.
|
||||||
|
@ -145,13 +145,17 @@ class RPC:
|
|||||||
}
|
}
|
||||||
return val
|
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
|
Below follows the RPC backend it is prefixed with rpc_ to raise awareness that it is
|
||||||
a remotely exposed function
|
a remotely exposed function
|
||||||
"""
|
"""
|
||||||
# Fetch open trade
|
# Fetch open trades
|
||||||
trades = Trade.get_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:
|
if not trades:
|
||||||
raise RPCException('no active trade')
|
raise RPCException('no active trade')
|
||||||
else:
|
else:
|
||||||
|
@ -277,7 +277,14 @@ class Telegram(RPCHandler):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
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 = []
|
messages = []
|
||||||
for r in results:
|
for r in results:
|
||||||
@ -815,7 +822,9 @@ class Telegram(RPCHandler):
|
|||||||
"Optionally takes a rate at which to buy.` \n")
|
"Optionally takes a rate at which to buy.` \n")
|
||||||
message = ("*/start:* `Starts the trader`\n"
|
message = ("*/start:* `Starts the trader`\n"
|
||||||
"*/stop:* `Stops 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"
|
" *table :* `will display trades in a table`\n"
|
||||||
" `pending buy orders are marked with an asterisk (*)`\n"
|
" `pending buy orders are marked with an asterisk (*)`\n"
|
||||||
" `pending sell orders are marked with a double asterisk (**)`\n"
|
" `pending sell orders are marked with a double asterisk (**)`\n"
|
||||||
|
@ -205,13 +205,14 @@ def test_telegram_status(default_conf, update, mocker) -> None:
|
|||||||
assert msg_mock.call_count == 1
|
assert msg_mock.call_count == 1
|
||||||
|
|
||||||
context = MagicMock()
|
context = MagicMock()
|
||||||
# /status table 2 3
|
# /status table
|
||||||
context.args = ["table", "2", "3"]
|
context.args = ["table"]
|
||||||
telegram._status(update=update, context=context)
|
telegram._status(update=update, context=context)
|
||||||
assert status_table.call_count == 1
|
assert status_table.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
def test_status_handle(default_conf, update, ticker, fee, mocker) -> None:
|
def test_status_handle(default_conf, update, ticker, fee, mocker) -> None:
|
||||||
|
default_conf['max_open_trades'] = 3
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Exchange',
|
'freqtrade.exchange.Exchange',
|
||||||
fetch_ticker=ticker,
|
fetch_ticker=ticker,
|
||||||
@ -252,8 +253,23 @@ def test_status_handle(default_conf, update, ticker, fee, mocker) -> None:
|
|||||||
assert 'Close Rate' not in ''.join(lines)
|
assert 'Close Rate' not in ''.join(lines)
|
||||||
assert 'Close Profit' not in ''.join(lines)
|
assert 'Close Profit' not in ''.join(lines)
|
||||||
|
|
||||||
assert msg_mock.call_count == 1
|
assert msg_mock.call_count == 3
|
||||||
assert 'ETH/BTC' in msg_mock.call_args_list[0][0][0]
|
assert 'ETH/BTC' in msg_mock.call_args_list[0][0][0]
|
||||||
|
assert 'LTC/BTC' in msg_mock.call_args_list[1][0][0]
|
||||||
|
|
||||||
|
msg_mock.reset_mock()
|
||||||
|
context = MagicMock()
|
||||||
|
context.args = ["2", "3"]
|
||||||
|
|
||||||
|
telegram._status(update=update, context=context)
|
||||||
|
|
||||||
|
lines = msg_mock.call_args_list[0][0][0].split('\n')
|
||||||
|
assert '' not in lines
|
||||||
|
assert 'Close Rate' not in ''.join(lines)
|
||||||
|
assert 'Close Profit' not in ''.join(lines)
|
||||||
|
|
||||||
|
assert msg_mock.call_count == 2
|
||||||
|
assert 'LTC/BTC' in msg_mock.call_args_list[0][0][0]
|
||||||
|
|
||||||
|
|
||||||
def test_status_table_handle(default_conf, update, ticker, fee, mocker) -> None:
|
def test_status_table_handle(default_conf, update, ticker, fee, mocker) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user