Repository: freqtrade/freqtrade

Issue:
Unable to create trade in USDT, FT does not see the available balance on binance
## Step 2: Describe your environment
  * Using Docker
  * Branch: Master 
  * Last Commit ID: 07b4afedf77b86138389fae6fd37738efdbbe8b9
  
**## Problem:**

Set trade stake CCY as USDT, have $27 of them on my balance, stake amount is 10.
But as per logs, bot does not see them

Also, when checking balance at telegram, it does see a balance
[Telegram balance](https://monosnap.com/file/cK5aA10wNsvcN3Iie9yrcH0MhkAmic)

### Logs:

  ```
2019-02-05 02:06:11,772 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:06:16,767 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:06:21,768 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:06:26,772 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:06:31,769 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:06:36,774 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:06:41,779 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:06:46,783 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:06:51,788 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:06:56,838 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:07:01,796 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:07:06,807 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:07:11,804 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:07:16,812 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:07:21,816 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:07:26,822 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:07:31,824 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:07:36,829 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:07:41,839 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:07:46,836 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:07:51,837 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:07:56,842 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:08:01,848 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:08:06,852 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:08:11,863 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:08:16,862 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:08:21,870 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:08:26,875 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:08:31,879 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
2019-02-05 02:08:36,881 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000000 USDT) is lower than stake amount(10.000000 USDT)
  ```

Config:
  ```
{
    "max_open_trades": 1,
    "stake_currency": "USDT",
    "stake_amount": 10,
    "fiat_display_currency": "USD",
    "dry_run": false,
    "ticker_interval": "5m",
    "trailing_stop": false,
    "trailing_stop_positive": 0.005,
    "trailing_stop_positive_offset": 0.0051,
    "minimal_roi": {
        "60":  0.01,
        "30":  0.03,
        "20":  0.04,
        "0":  0.08
    },
    "stoploss": -0.10,
    "unfilledtimeout": {
        "buy": 10,
        "sell": 30
    },
    "bid_strategy": {
        "ask_last_balance": 1.0,
        "use_order_book": false,
        "order_book_top": 1,
        "check_depth_of_market": {
            "enabled": false,
            "bids_to_ask_delta": 1
        }
    },
    "ask_strategy":{
        "use_order_book": false,
        "order_book_min": 1,
        "order_book_max": 9
    },
    "exchange": {
        "name": "binance",
        "key": "",
        "secret": "",
        "ccxt_config": {"enableRateLimit": true},
        "ccxt_async_config": {
            "enableRateLimit": false
        },
        "pair_whitelist": [
            "BTC/USDT",
            "LTC/USDT",
            "ETH/USDT",
            "ETC/USDT"
        ],
        "pair_blacklist": [
            "DOGE/BTC",
            "BNB/BTC",
            "BNB/USDT"
        ]
    },
    "experimental": {
        "use_sell_signal": true,
        "sell_profit_only": true,
        "ignore_roi_if_buy_signal": false
    },
    "edge": {
        "enabled": false,
        "process_throttle_secs": 3600,
        "calculate_since_number_of_days": 7,
        "capital_available_percentage": 0.5,
        "allowed_risk": 0.01,
        "stoploss_range_min": -0.01,
        "stoploss_range_max": -0.1,
        "stoploss_range_step": -0.01,
        "minimum_winrate": 0.60,
        "minimum_expectancy": 0.20,
        "min_trade_number": 10,
        "max_trade_duration_minute": 1440,
        "remove_pumps": false
    },
    "initial_state": "running",
    "internals": {
        "process_throttle_secs": 5
    }
}
  ```



Discussion:
@xmatthias very similar issue happens with BTC trading.
1) It places the trade WAVE/BTC and then closed it. So 1st trade worked fine.
2) Once the trade was closed, the balance of BTC is 0.00216049
The stake is 0.0015.
Config the same as above.

So it looks like again bot does not see the balance.

Logs:
```
2019-02-10 10:43:06,981 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000654 BTC) is lower than stake amount(0.001500 BTC)
2019-02-10 10:43:11,983 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000654 BTC) is lower than stake amount(0.001500 BTC)
2019-02-10 10:43:16,985 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000654 BTC) is lower than stake amount(0.001500 BTC)
2019-02-10 10:43:22,006 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000654 BTC) is lower than stake amount(0.001500 BTC)
2019-02-10 10:43:27,011 - freqtrade.freqtradebot - WARNING - Unable to create trade: Available balance(0.000654 BTC) is lower than stake amount(0.001500 BTC)
```

do the logs between the sell of the first trade - and the 2nd trade contain`Wallets synced ...` ? 


Sorry, restarted the bot. I will monitor and share the logs if this happens again
other question then - what type of sell-signal triggered the sell of WAVE/BTC? 
this should be visible in the telegram message ...
ROI one
Dear all,

I think I have the same issue on Binance BTC/USDT.
When I ask for /balance, I just obtain 'all balances are zero'. Nevertheless, I have 0.0022 BTC.
Despite it is almost nothing, FT should see it, no ? :-)

Tell me if you need something to debug.

Regards
Xavier
"all balances are zero" sounds like the bot is running in dry-run ... ? 
@xmatthias : sorry, I dis not know that dry run do not provide balance.
Sorry for the noise.
@xaviermiss no problem, dry-run does not require your exchange keys - and simulates balances for trading - however does not return on /balance - since that would be misleading.
Maybe balances should not simply be written in the /balance message in case of Dry Run...
they are not - but "all balances are zero" is written. But a hint on "because of Dry-run" would for sure be helpful
> they are not - but "all balances are zero" is written. But a hint on "because of Dry-run" would for sure be helpful

Or a more correct phrase, something like "Running in Dry Run, balances are not available" or "N/A (running in Dry Run mode)"... Because actually balances are not zeroes in the Dry Run mode.

Resolving patch:
diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py
--- a/freqtrade/rpc/rpc.py
+++ b/freqtrade/rpc/rpc.py
@@ -298,7 +298,10 @@ def _rpc_balance(self, fiat_display_currency: str) -> Dict:
                 'est_btc': est_btc,
             })
         if total == 0.0:
-            raise RPCException('all balances are zero')
+            if self._freqtrade.config.get('dry_run', False):
+                raise RPCException('Running in Dry Run, balances are not available.')
+            else:
+                raise RPCException('All balances are zero.')
 
         symbol = fiat_display_currency
         value = self._fiat_converter.convert_amount(total, 'BTC',


Test patch:
diff --git a/freqtrade/tests/rpc/test_rpc_telegram.py b/freqtrade/tests/rpc/test_rpc_telegram.py
--- a/freqtrade/tests/rpc/test_rpc_telegram.py
+++ b/freqtrade/tests/rpc/test_rpc_telegram.py
@@ -559,10 +559,32 @@ def test_balance_handle_empty_response(default_conf, update, mocker) -> None:
 
     telegram = Telegram(freqtradebot)
 
+    freqtradebot.config['dry_run'] = False
     telegram._balance(bot=MagicMock(), update=update)
     result = msg_mock.call_args_list[0][0][0]
     assert msg_mock.call_count == 1
-    assert 'all balances are zero' in result
+    assert 'All balances are zero.' in result
+
+
+def test_balance_handle_empty_response_dry(default_conf, update, mocker) -> None:
+    mocker.patch('freqtrade.exchange.Exchange.get_balances', return_value={})
+
+    msg_mock = MagicMock()
+    mocker.patch.multiple(
+        'freqtrade.rpc.telegram.Telegram',
+        _init=MagicMock(),
+        _send_msg=msg_mock
+    )
+
+    freqtradebot = get_patched_freqtradebot(mocker, default_conf)
+    patch_get_signal(freqtradebot, (True, False))
+
+    telegram = Telegram(freqtradebot)
+
+    telegram._balance(bot=MagicMock(), update=update)
+    result = msg_mock.call_args_list[0][0][0]
+    assert msg_mock.call_count == 1
+    assert "Running in Dry Run, balances are not available." in result
 
 
 def test_balance_handle_too_large_response(default_conf, update, mocker) -> None: