add tests for balance from get-tickers

This commit is contained in:
Matthias
2019-11-14 20:12:41 +01:00
parent 8c64be3cfd
commit 62d50f512d
5 changed files with 75 additions and 58 deletions

View File

@@ -355,29 +355,18 @@ def test_rpc_balance_handle_error(default_conf, mocker):
mocker.patch.multiple(
'freqtrade.exchange.Exchange',
get_balances=MagicMock(return_value=mock_balance),
get_ticker=MagicMock(side_effect=TemporaryError('Could not load ticker due to xxx'))
get_tickers=MagicMock(side_effect=TemporaryError('Could not load ticker due to xxx'))
)
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
patch_get_signal(freqtradebot, (True, False))
rpc = RPC(freqtradebot)
rpc._fiat_converter = CryptoToFiatConverter()
result = rpc._rpc_balance(default_conf['fiat_display_currency'])
assert prec_satoshi(result['total'], 12)
assert prec_satoshi(result['value'], 180000)
assert 'USD' == result['symbol']
assert result['currencies'] == [{
'currency': 'BTC',
'free': 10.0,
'balance': 12.0,
'used': 2.0,
'est_btc': 12.0,
}]
assert result['total'] == 12.0
with pytest.raises(RPCException, match="Error getting current tickers."):
rpc._rpc_balance(default_conf['fiat_display_currency'])
def test_rpc_balance_handle(default_conf, mocker):
def test_rpc_balance_handle(default_conf, mocker, tickers):
mock_balance = {
'BTC': {
'free': 10.0,
@@ -389,7 +378,7 @@ def test_rpc_balance_handle(default_conf, mocker):
'total': 5.0,
'used': 4.0,
},
'PAX': {
'USDT': {
'free': 5.0,
'total': 10.0,
'used': 5.0,
@@ -405,10 +394,9 @@ def test_rpc_balance_handle(default_conf, mocker):
mocker.patch.multiple(
'freqtrade.exchange.Exchange',
get_balances=MagicMock(return_value=mock_balance),
get_ticker=MagicMock(
side_effect=lambda p, r: {'bid': 100} if p == "BTC/PAX" else {'bid': 0.01}),
get_tickers=tickers,
get_valid_pair_combination=MagicMock(
side_effect=lambda a, b: f"{b}/{a}" if a == "PAX" else f"{a}/{b}")
side_effect=lambda a, b: f"{b}/{a}" if a == "USDT" else f"{a}/{b}")
)
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
@@ -417,8 +405,8 @@ def test_rpc_balance_handle(default_conf, mocker):
rpc._fiat_converter = CryptoToFiatConverter()
result = rpc._rpc_balance(default_conf['fiat_display_currency'])
assert prec_satoshi(result['total'], 12.15)
assert prec_satoshi(result['value'], 182250)
assert prec_satoshi(result['total'], 12.309096315)
assert prec_satoshi(result['value'], 184636.44472997)
assert 'USD' == result['symbol']
assert result['currencies'] == [
{'currency': 'BTC',
@@ -430,16 +418,16 @@ def test_rpc_balance_handle(default_conf, mocker):
{'free': 1.0,
'balance': 5.0,
'currency': 'ETH',
'est_btc': 0.05,
'est_btc': 0.30794,
'used': 4.0
},
{'free': 5.0,
'balance': 10.0,
'currency': 'PAX',
'est_btc': 0.1,
'currency': 'USDT',
'est_btc': 0.0011563153318162476,
'used': 5.0}
]
assert result['total'] == 12.15
assert result['total'] == 12.309096315331816
def test_rpc_start(mocker, default_conf) -> None:

View File

@@ -461,29 +461,10 @@ def test_profit_handle(default_conf, update, ticker, ticker_sell_up, fee,
assert '*Best Performing:* `ETH/BTC: 6.20%`' in msg_mock.call_args_list[-1][0][0]
def test_telegram_balance_handle(default_conf, update, mocker, rpc_balance) -> None:
def mock_ticker(symbol, refresh):
if symbol == 'BTC/USDT':
return {
'bid': 10000.00,
'ask': 10000.00,
'last': 10000.00,
}
elif symbol == 'XRP/BTC':
return {
'bid': 0.00001,
'ask': 0.00001,
'last': 0.00001,
}
return {
'bid': 0.1,
'ask': 0.1,
'last': 0.1,
}
def test_telegram_balance_handle(default_conf, update, mocker, rpc_balance, tickers) -> None:
mocker.patch('freqtrade.exchange.Exchange.get_balances', return_value=rpc_balance)
mocker.patch('freqtrade.exchange.Exchange.get_ticker', side_effect=mock_ticker)
mocker.patch('freqtrade.exchange.Exchange.get_tickers', tickers)
mocker.patch('freqtrade.exchange.Exchange.get_valid_pair_combination',
side_effect=lambda a, b: f"{a}/{b}")