Merge pull request #1741 from freqtrade/abstract_count
rpc Count should be in rpc.py
This commit is contained in:
commit
4bb5345e13
@ -454,12 +454,17 @@ class RPC(object):
|
|||||||
for pair, rate, count in pair_rates
|
for pair, rate, count in pair_rates
|
||||||
]
|
]
|
||||||
|
|
||||||
def _rpc_count(self) -> List[Trade]:
|
def _rpc_count(self) -> Dict[str, float]:
|
||||||
""" Returns the number of trades running """
|
""" Returns the number of trades running """
|
||||||
if self._freqtrade.state != State.RUNNING:
|
if self._freqtrade.state != State.RUNNING:
|
||||||
raise RPCException('trader is not running')
|
raise RPCException('trader is not running')
|
||||||
|
|
||||||
return Trade.get_open_trades()
|
trades = Trade.get_open_trades()
|
||||||
|
return {
|
||||||
|
'current': len(trades),
|
||||||
|
'max': float(self._freqtrade.config['max_open_trades']),
|
||||||
|
'total_stake': sum((trade.open_rate * trade.amount) for trade in trades)
|
||||||
|
}
|
||||||
|
|
||||||
def _rpc_whitelist(self) -> Dict:
|
def _rpc_whitelist(self) -> Dict:
|
||||||
""" Returns the currently active whitelist"""
|
""" Returns the currently active whitelist"""
|
||||||
|
@ -456,12 +456,10 @@ class Telegram(RPC):
|
|||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
trades = self._rpc_count()
|
counts = self._rpc_count()
|
||||||
message = tabulate({
|
message = tabulate({k: [v] for k, v in counts.items()},
|
||||||
'current': [len(trades)],
|
headers=['current', 'max', 'total stake'],
|
||||||
'max': [self._config['max_open_trades']],
|
tablefmt='simple')
|
||||||
'total stake': [sum((trade.open_rate * trade.amount) for trade in trades)]
|
|
||||||
}, headers=['current', 'max', 'total stake'], tablefmt='simple')
|
|
||||||
message = "<pre>{}</pre>".format(message)
|
message = "<pre>{}</pre>".format(message)
|
||||||
logger.debug(message)
|
logger.debug(message)
|
||||||
self._send_msg(message, parse_mode=ParseMode.HTML)
|
self._send_msg(message, parse_mode=ParseMode.HTML)
|
||||||
|
@ -581,15 +581,13 @@ def test_rpc_count(mocker, default_conf, ticker, fee, markets) -> None:
|
|||||||
patch_get_signal(freqtradebot, (True, False))
|
patch_get_signal(freqtradebot, (True, False))
|
||||||
rpc = RPC(freqtradebot)
|
rpc = RPC(freqtradebot)
|
||||||
|
|
||||||
trades = rpc._rpc_count()
|
counts = rpc._rpc_count()
|
||||||
nb_trades = len(trades)
|
assert counts["current"] == 0
|
||||||
assert nb_trades == 0
|
|
||||||
|
|
||||||
# Create some test data
|
# Create some test data
|
||||||
freqtradebot.create_trade()
|
freqtradebot.create_trade()
|
||||||
trades = rpc._rpc_count()
|
counts = rpc._rpc_count()
|
||||||
nb_trades = len(trades)
|
assert counts["current"] == 1
|
||||||
assert nb_trades == 1
|
|
||||||
|
|
||||||
|
|
||||||
def test_rpcforcebuy(mocker, default_conf, ticker, fee, markets, limit_buy_order) -> None:
|
def test_rpcforcebuy(mocker, default_conf, ticker, fee, markets, limit_buy_order) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user