Repository: freqtrade/freqtrade

Issue:
Wrong sell price for cheap currencies on Binance
  * Python Version: Python 3.6.3 and Python 3.6.5
  * CCXT version: ccxt==1.17.363 and ccxt==1.17.376
  * Branch: Develop
  * Last Commit ID: f9bbeb79fa20beb629d14fc3e02e069d973e6fc0
  
## Describe the problem:

Market (on Binance) hit stoploss, but the bot tries to sell at a price higher than current price:

![image](https://user-images.githubusercontent.com/3164764/47255819-b3a58a00-d476-11e8-9d27-e3006f4e98e9.png)
![image 1](https://user-images.githubusercontent.com/3164764/47255887-6d045f80-d477-11e8-8329-36639b2ef51f.png)

I have added some debug loggers and it seems that the price is correct up to ccxt:

```
2018-10-20 14:43:22,018 - freqtrade.freqtradebot - INFO - Sell order timeout for Trade(id=13, pair=TRX/BTC, amount=2702.00000000, open_rate=0.00000400, open_since=2 days ago).
2018-10-20 14:43:25,051 - freqtrade.freqtradebot - DEBUG - Handling Trade(id=13, pair=TRX/BTC, amount=2702.00000000, open_rate=0.00000400, open_since=2 days ago) ...
2018-10-20 14:43:25,312 - freqtrade.freqtradebot - DEBUG - Sell rate: 3.73e-06 ...
2018-10-20 14:43:25,313 - freqtrade.freqtradebot - INFO - checking sell
2018-10-20 14:43:25,313 - freqtrade.strategy.interface - DEBUG - Stop loss hit.
2018-10-20 14:43:25,313 - freqtrade.freqtradebot - DEBUG - sell_rate: 3.73e-06
2018-10-20 14:43:25,313 - freqtrade.freqtradebot - DEBUG - trade: Trade(id=13, pair=TRX/BTC, amount=2702.00000000, open_rate=0.00000400, open_since=2 days ago)
2018-10-20 14:43:25,314 - freqtrade.exchange - DEBUG - Rate for sell in exchange/__init__py: 3.73e-06
2018-10-20 14:43:25,314 - freqtrade.exchange - DEBUG - Price in symbol_price_prec 3.73e-06
2018-10-20 14:43:25,314 - freqtrade.exchange - DEBUG - Rate for sell in exchange/__init__py: 3.73e-06
2018-10-20 14:43:26,589 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': sell, 'exchange': 'Binance', 'pair': 'TRX/BTC', 'gain': 'loss', 'market_url': 'https://www.binance.com/tradeDetail.html?symbol=TRX_BTC', 'limit': 3.73e-06, 'amount': 2702.0, 'open_rate': 4e-06, 'current_rate': 3.73e-06, 'profit_amount': -0.00075043, 'profit_percent': -0.06936309, 'stake_currency': 'BTC', 'fiat_currency': 'CZK'}
2018-10-20 14:43:34,159 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=13, pair=TRX/BTC, amount=2702.00000000, open_rate=0.00000400, open_since=2 days ago)
```

However, with following test case, i was not able to reproduce this directly in ccxt (the buy and sell were placed correctly):

```
Python 3.6.5 (default, Mar 31 2018, 19:45:04) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ccxt
>>> ct = ccxt.binance({'apiKey': '',
...             'secret': ''
...                   })
>>> mark = ct.loadMarkets()
>>> pair='VET/BTC'
>>> amount=5555
>>> price=0.00000178
>>> print(ct.amountToPrecision(pair, amount))
5555
>>> from math import floor, ceil
>>> def symbol_price_prec(pair, price):
...     if ct.markets[pair]['precision']['price']:
...         symbol_prec = ct.markets[pair]['precision']['price']
...         big_price = price * pow(10, symbol_prec)
...         price = ceil(big_price) / pow(10, symbol_prec)
...     return price
... 
>>> print(ct.price_to_precision(pair, price))
0.00000178
>>> print(symbol_price_prec(pair, price))    
1.78e-06
>>> 
>>> ct.create_limit_buy_order(pair, amount, price)
{'info': {'symbol': 'VETBTC', 'orderId': 8882953, 'clientOrderId': '', 'transactTime': 1540036365145, 'price': '0.00000178', 'origQty': '5555.00000000', 'executedQty': '0.00000000', 'cummulativeQuoteQty': '0.00000000', 'status': 'NEW', 'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'BUY'}, 'id': '8882953', 'timestamp': 1540036365145, 'datetime': '2018-10-20T11:52:45.145Z', 'lastTradeTimestamp': None, 'symbol': 'VET/BTC', 'type': 'limit', 'side': 'buy', 'price': 1.78e-06, 'amount': 5555.0, 'cost': 0.0, 'average': None, 'filled': 0.0, 'remaining': 5555.0, 'status': 'open', 'fee': None, 'trades': None}
>>> ct.create_limit_sell_order(pair, amount, price)
{'info': {'symbol': 'VETBTC', 'orderId': 8882977, 'clientOrderId': '', 'transactTime': 1540036426869, 'price': '0.00000178', 'origQty': '5555.00000000', 'executedQty': '5555.00000000', 'cummulativeQuoteQty': '0.00988790', 'status': 'FILLED', 'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'SELL'}, 'id': '8882977', 'timestamp': 1540036426869, 'datetime': '2018-10-20T11:53:46.869Z', 'lastTradeTimestamp': None, 'symbol': 'VET/BTC', 'type': 'limit', 'side': 'sell', 'price': 1.78e-06, 'amount': 5555.0, 'cost': 0.0098879, 'average': 1.78e-06, 'filled': 5555.0, 'remaining': 0.0, 'status': 'closed', 'fee': None, 'trades': None}
>>> 
```



### Steps to reproduce:

  1. Set bot on some cheap currency (less than 0.00001).
  2. Wait for stoploss
  3. Price on market is wrong

Tested on Binance  

### Observed Results:

  * Price of the bid posted on market was 4e-06
  * Price of the bid posted on market should be 3.73e-06

Wrong sell price for cheap currencies on Binance
  * Python Version: Python 3.6.3 and Python 3.6.5
  * CCXT version: ccxt==1.17.363 and ccxt==1.17.376
  * Branch: Develop
  * Last Commit ID: f9bbeb79fa20beb629d14fc3e02e069d973e6fc0
  
## Describe the problem:

Market (on Binance) hit stoploss, but the bot tries to sell at a price higher than current price:

![image](https://user-images.githubusercontent.com/3164764/47255819-b3a58a00-d476-11e8-9d27-e3006f4e98e9.png)
![image 1](https://user-images.githubusercontent.com/3164764/47255887-6d045f80-d477-11e8-8329-36639b2ef51f.png)

I have added some debug loggers and it seems that the price is correct up to ccxt:

```
2018-10-20 14:43:22,018 - freqtrade.freqtradebot - INFO - Sell order timeout for Trade(id=13, pair=TRX/BTC, amount=2702.00000000, open_rate=0.00000400, open_since=2 days ago).
2018-10-20 14:43:25,051 - freqtrade.freqtradebot - DEBUG - Handling Trade(id=13, pair=TRX/BTC, amount=2702.00000000, open_rate=0.00000400, open_since=2 days ago) ...
2018-10-20 14:43:25,312 - freqtrade.freqtradebot - DEBUG - Sell rate: 3.73e-06 ...
2018-10-20 14:43:25,313 - freqtrade.freqtradebot - INFO - checking sell
2018-10-20 14:43:25,313 - freqtrade.strategy.interface - DEBUG - Stop loss hit.
2018-10-20 14:43:25,313 - freqtrade.freqtradebot - DEBUG - sell_rate: 3.73e-06
2018-10-20 14:43:25,313 - freqtrade.freqtradebot - DEBUG - trade: Trade(id=13, pair=TRX/BTC, amount=2702.00000000, open_rate=0.00000400, open_since=2 days ago)
2018-10-20 14:43:25,314 - freqtrade.exchange - DEBUG - Rate for sell in exchange/__init__py: 3.73e-06
2018-10-20 14:43:25,314 - freqtrade.exchange - DEBUG - Price in symbol_price_prec 3.73e-06
2018-10-20 14:43:25,314 - freqtrade.exchange - DEBUG - Rate for sell in exchange/__init__py: 3.73e-06
2018-10-20 14:43:26,589 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': sell, 'exchange': 'Binance', 'pair': 'TRX/BTC', 'gain': 'loss', 'market_url': 'https://www.binance.com/tradeDetail.html?symbol=TRX_BTC', 'limit': 3.73e-06, 'amount': 2702.0, 'open_rate': 4e-06, 'current_rate': 3.73e-06, 'profit_amount': -0.00075043, 'profit_percent': -0.06936309, 'stake_currency': 'BTC', 'fiat_currency': 'CZK'}
2018-10-20 14:43:34,159 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=13, pair=TRX/BTC, amount=2702.00000000, open_rate=0.00000400, open_since=2 days ago)
```

However, with following test case, i was not able to reproduce this directly in ccxt (the buy and sell were placed correctly):

```
Python 3.6.5 (default, Mar 31 2018, 19:45:04) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ccxt
>>> ct = ccxt.binance({'apiKey': '',
...             'secret': ''
...                   })
>>> mark = ct.loadMarkets()
>>> pair='VET/BTC'
>>> amount=5555
>>> price=0.00000178
>>> print(ct.amountToPrecision(pair, amount))
5555
>>> from math import floor, ceil
>>> def symbol_price_prec(pair, price):
...     if ct.markets[pair]['precision']['price']:
...         symbol_prec = ct.markets[pair]['precision']['price']
...         big_price = price * pow(10, symbol_prec)
...         price = ceil(big_price) / pow(10, symbol_prec)
...     return price
... 
>>> print(ct.price_to_precision(pair, price))
0.00000178
>>> print(symbol_price_prec(pair, price))    
1.78e-06
>>> 
>>> ct.create_limit_buy_order(pair, amount, price)
{'info': {'symbol': 'VETBTC', 'orderId': 8882953, 'clientOrderId': '', 'transactTime': 1540036365145, 'price': '0.00000178', 'origQty': '5555.00000000', 'executedQty': '0.00000000', 'cummulativeQuoteQty': '0.00000000', 'status': 'NEW', 'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'BUY'}, 'id': '8882953', 'timestamp': 1540036365145, 'datetime': '2018-10-20T11:52:45.145Z', 'lastTradeTimestamp': None, 'symbol': 'VET/BTC', 'type': 'limit', 'side': 'buy', 'price': 1.78e-06, 'amount': 5555.0, 'cost': 0.0, 'average': None, 'filled': 0.0, 'remaining': 5555.0, 'status': 'open', 'fee': None, 'trades': None}
>>> ct.create_limit_sell_order(pair, amount, price)
{'info': {'symbol': 'VETBTC', 'orderId': 8882977, 'clientOrderId': '', 'transactTime': 1540036426869, 'price': '0.00000178', 'origQty': '5555.00000000', 'executedQty': '5555.00000000', 'cummulativeQuoteQty': '0.00988790', 'status': 'FILLED', 'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'SELL'}, 'id': '8882977', 'timestamp': 1540036426869, 'datetime': '2018-10-20T11:53:46.869Z', 'lastTradeTimestamp': None, 'symbol': 'VET/BTC', 'type': 'limit', 'side': 'sell', 'price': 1.78e-06, 'amount': 5555.0, 'cost': 0.0098879, 'average': 1.78e-06, 'filled': 5555.0, 'remaining': 0.0, 'status': 'closed', 'fee': None, 'trades': None}
>>> 
```



### Steps to reproduce:

  1. Set bot on some cheap currency (less than 0.00001).
  2. Wait for stoploss
  3. Price on market is wrong

Tested on Binance  

### Observed Results:

  * Price of the bid posted on market was 4e-06
  * Price of the bid posted on market should be 3.73e-06



Discussion:
> 2018-10-20 14:43:25,314 - freqtrade.exchange - DEBUG - Rate for sell in exchange/__init__py: 3.73e-06

did you insert this line after `rate = self.symbol_price_prec(pair, rate)`? 

if yes, please extend it to also show `type(rate)` - maybe there is somehow a odd type involved causing "something" to fail ... 

also, please change the line `return self._api.create_limit_sell_order(pair, amount, rate)` to the following lines:
```python
ret = self._api.create_limit_sell_order(pair, amount, rate)
logger.debug("ccxt return: %s", ret)
return ret
```
Code:
```
        try:
            # Set the precision for amount and price(rate) as accepted by the exchange
            logger.debug("Rate for sell in exchange/__init__py: %s",rate)
            amount = self.symbol_amount_prec(pair, amount)
            rate = self.symbol_price_prec(pair, rate)
            logger.debug("Rate for sell in exchange/__init__py: %s",rate)

            logger.debug("Parameters for create_limit_sell_order. pair: %s, amount: %s, rate: %s",pair,amount,rate)
            logger.debug("type(rate): %s",type(rate))
            ret = self._api.create_limit_sell_order(pair, amount, rate)
            logger.debug("ccxt return: %s", ret)
            return ret
```

output:

```
2018-10-20 18:07:12,287 - freqtrade.exchange - DEBUG - Rate for sell in exchange/__init__py: 1.78e-06
2018-10-20 18:07:12,288 - freqtrade.exchange - DEBUG - Price in symbol_price_prec 1.78e-06
2018-10-20 18:07:12,288 - freqtrade.exchange - DEBUG - Rate for sell in exchange/__init__py: 1.78e-06
2018-10-20 18:07:12,288 - freqtrade.exchange - DEBUG - Parameters for create_limit_sell_order. pair: POE/BTC, amount: 5549.445, rate: 1.78e-06
2018-10-20 18:07:12,288 - freqtrade.exchange - DEBUG - type(rate): <class 'float'>
2018-10-20 18:07:12,793 - freqtrade.exchange - DEBUG - ccxt return: {'info': {'symbol': 'POEBTC', 'orderId': 21744127, 'clientOrderId': '', 'transactTime': 1540051632660, 'price': '0.00000200', 'origQty': '5549.00000000', 'executedQty': '0.00000000', 'cummulativeQuoteQty': '0.00000000', 'status': 'NEW', 'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'SELL'}, 'id': '21744127', 'timestamp': 1540051632660, 'datetime': '2018-10-20T16:07:12.660Z', 'lastTradeTimestamp': None, 'symbol': 'POE/BTC', 'type': 'limit', 'side': 'sell', 'price': 2e-06, 'amount': 5549.0, 'cost': 0.0, 'average': None, 'filled': 0.0, 'remaining': 5549.0, 'status': 'open', 'fee': None, 'trades': None}

Request: POST https://api.binance.com/api/v3/order {'X-MBX-APIKEY': '', 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'python-requests/2.19.1', 'Accept-Encoding': 'gzip, deflate'} timestamp=1540051632520&recvWindow=5000&symbol=POEBTC&quantity=5549&type=LIMIT&side=SELL&newOrderRespType=RESULT&price=0.000002&timeInForce=GTC&signature=

Response: POST https://api.binance.com/api/v3/order 200 {'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Date': 'Sat, 20 Oct 2018 16:07:12 GMT', 'Server': 'nginx', 'Content-Encoding': 'gzip', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains', 'X-Frame-Options': 'SAMEORIGIN', 'X-Xss-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Security-Policy': "default-src 'self'", 'X-Content-Security-Policy': "default-src 'self'", 'X-WebKit-CSP': "default-src 'self'", 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Cache': 'Miss from cloudfront', 'Via': '1.1 2e8f70eb03b681aa6bd8c18fff081f80.cloudfront.net (CloudFront)', 'X-Amz-Cf-Id': ''} {"symbol":"POEBTC","orderId":21744127,"clientOrderId":"","transactTime":1540051632660,"price":"0.00000200","origQty":"5549.00000000","executedQty":"0.00000000","cummulativeQuoteQty":"0.00000000","status":"NEW","timeInForce":"GTC","type":"LIMIT","side":"SELL"}
```
I struggle to make sense of this - which is really not your fault...

`rate: 1.78e-06` shows that we do pass in 1.78e-06.

however ccxt reqeust then shows `&price=0.000002` - clearly rounded.

Yes - the amount changes to the int amount but that's expected as it was created as part of fees - the residual is called "binance dust" - and the only way i found to avoid this is to have BNB in your account (so fees go off of that asset).

I have added this:
```
        try:
            # Set the precision for amount and price(rate) as accepted by the exchange
            logger.debug("Rate for sell in exchange/__init__py: %s",rate)
            amount = self.symbol_amount_prec(pair, amount)
            rate = self.symbol_price_prec(pair, rate)
            logger.debug("Rate for sell in exchange/__init__py: %s",rate)

            logger.debug("Parameters for create_limit_sell_order. pair: %s, amount: %s, rate: %s",pair,amount,rate)
            logger.debug("type(rate): %s",type(rate))
            ret = self._api.create_limit_sell_order(pair, amount, rate)
            logger.debug("ccxt return: %s", ret)
            logger.debug("Current price precision for POE/BTC: %s",self._api.markets['POE/BTC']['precision']['price'])
            logger.debug("Current price limits for POE/BTC: %s",self._api.markets['POE/BTC']['limits']['price'])
            return ret
```

But still getting this:

```
2018-10-20 19:22:28,630 - freqtrade.exchange - DEBUG - Rate for sell in exchange/__init__py: 1.77e-06
2018-10-20 19:22:28,630 - freqtrade.exchange - DEBUG - Price in symbol_price_prec 1.77e-06
2018-10-20 19:22:28,630 - freqtrade.exchange - DEBUG - Rate for sell in exchange/__init__py: 1.77e-06
2018-10-20 19:22:28,630 - freqtrade.exchange - DEBUG - Parameters for create_limit_sell_order. pair: POE/BTC, amount: 5549.445, rate: 1.77e-06
2018-10-20 19:22:28,630 - freqtrade.exchange - DEBUG - type(rate): <class 'float'>

Request: POST https://api.binance.com/api/v3/order {'X-MBX-APIKEY': '', 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'python-requests/2.19.1', 'Accept-Encoding': 'gzip, deflate'} timestamp=1540056146646&recvWindow=5000&symbol=TRXBTC&quantity=2702&type=LIMIT&side=SELL&newOrderRespType=RESULT&price=0.000004&timeInForce=GTC&signature=

Response: POST https://api.binance.com/api/v3/order 200 {'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Date': 'Sat, 20 Oct 2018 17:22:26 GMT', 'Server': 'nginx', 'Content-Encoding': 'gzip', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains', 'X-Frame-Options': 'SAMEORIGIN', 'X-Xss-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Security-Policy': "default-src 'self'", 'X-Content-Security-Policy': "default-src 'self'", 'X-WebKit-CSP': "default-src 'self'", 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Cache': 'Miss from cloudfront', 'Via': '1.1 50f21cb925e6471490e080147e252d7d.cloudfront.net (CloudFront)', 'X-Amz-Cf-Id': ''} {"symbol":"TRXBTC","orderId":74954950,"clientOrderId":"","transactTime":1540056146788,"price":"0.00000400","origQty":"2702.00000000","executedQty":"0.00000000","cummulativeQuoteQty":"0.00000000","status":"NEW","timeInForce":"GTC","type":"LIMIT","side":"SELL"}
2018-10-20 19:22:29,140 - freqtrade.exchange - DEBUG - Current price precision for POE/BTC: 8
2018-10-20 19:22:29,140 - freqtrade.exchange - DEBUG - Current price limits for POE/BTC: {'min': 1.8e-07, 'max': 1.77e-05}
```
this request does not make sense... 
the log output shows `Parameters for create_limit_sell_order. pair: POE/BTC, amount: 5549.445, rate: 1.77e-06`

but the post-request is for `symbol=TRXBTC` ...


``` python
import ccxt
ct = ccxt.binance({'apiKey': 'a',
            'secret': 'b',
                   'verbose': True
                  })
mark = ct.loadMarkets()
pair='POE/BTC'
amount=5549.445
price=1.78e-06
print(f"Parameters for create_limit_sell_order. pair: {pair}, amount: {amount}, rate:{rate}")
ct.create_limit_buy_order(pair, amount, rate)

```


running the code above - i get the following output:

```
Parameters for create_limit_sell_order. pair: POE/BTC, amount: 5549.445, rate:1.78e-06

Request: POST https://api.binance.com/api/v3/order {'X-MBX-APIKEY': 'a', 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'python-requests/2.19.1', 'Accept-Encoding': 'gzip, deflate'} timestamp=1540056460821&recvWindow=5000&symbol=POEBTC&quantity=5549&type=LIMIT&side=BUY&newOrderRespType=RESULT&price=0.00000178&timeInForce=GTC&signature=a45768a6b4eb76b8cdd2c4bb8c87a32ad12c81f3814f7dda3bef90c6561a9cbd

Response: POST https://api.binance.com/api/v3/order 401 {'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Date': 'Sat, 20 Oct 2018 17:27:40 GMT', 'Server': 'nginx', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains', 'X-Frame-Options': 'SAMEORIGIN', 'X-Xss-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Security-Policy': "default-src 'self'", 'X-Content-Security-Policy': "default-src 'self'", 'X-WebKit-CSP': "default-src 'self'", 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 5c82476b8faa6db5077c339ee3b64cf0.cloudfront.net (CloudFront)', 'X-Amz-Cf-Id': 'bPVmbVkOpAe4Wzq3vVn6Cvev3B5al1XDCvVRm6uPxmzTXqkDMHe4dA=='} {"code":-2014,"msg":"API-key format invalid."}
```

i know my key is invalid, but it shows that the request is passed through ccxt unmodified... however your own logs show that the price is also correct in freqtrade 


I get the same results.
_Should i try to start it without DB? Is there any other caching/persistence implemented than database?_
nevermind, that does not make sense
also without DB will use the a inmemory sqlite3 database, as some persistance is needed, and i would honestly not know how persistance can affect this
Closing, issue was caused by setting of decimal context precision in freqtrade persistence api, which caused ccxt to round incorrectly.

Source of the issue:
https://github.com/freqtrade/freqtrade/blob/98240e0e48b2f4f61775e776dbc5f7713452bce8/freqtrade/persistence.py#L244

I would do a PR to remove it, but i am not sure if it does not break Bittrex support.

Code to reproduce (from https://github.com/ccxt/ccxt/blob/5a3fa3961472d80a5eb24e8a54a57f877d5cae78/python/ccxt/base/decimal_to_precision.py#L37):

```
import decimal
import numbers

# rounding mode
TRUNCATE = 0
ROUND = 1

# digits counting mode
DECIMAL_PLACES = 2
SIGNIFICANT_DIGITS = 3

# padding mode
NO_PADDING = 4
PAD_WITH_ZERO = 5

n=1.77e-06
precision=8

rounding_mode=ROUND
padding_mode=NO_PADDING
counting_mode=DECIMAL_PLACES

assert precision is not None and isinstance(precision, numbers.Integral)
assert rounding_mode in [TRUNCATE, ROUND]
assert counting_mode in [DECIMAL_PLACES, SIGNIFICANT_DIGITS]
assert padding_mode in [NO_PADDING, PAD_WITH_ZERO]

context = decimal.getcontext()

# If decimal.getcontext().prec is set to 8:
context.prec=8

precision = min(context.prec - 2, precision)

context.traps[decimal.Underflow] = True
context.rounding = decimal.ROUND_HALF_UP  # rounds 0.5 away from zero

dec = decimal.Decimal(str(n))
string = '{:f}'.format(dec)  # convert to string using .format to avoid engineering notation
precise = None

def power_of_10(x):
  return decimal.Decimal('10') ** (-x)

'{:f}'.format(dec.quantize(power_of_10(precision))) # ROUND_HALF_EVEN is default context
```

This produces result: '0.000002'
_Reopening until fix_
it won't break bittrex - it's a remainder of pre-ccxt times.
we handled api calls ourselfs - which could cause too high precision. ccxt does tat itself - so removing it should be straightforward - but will break a few tests as the precision raises ...


> 2018-10-20 14:43:25,314 - freqtrade.exchange - DEBUG - Rate for sell in exchange/__init__py: 3.73e-06

did you insert this line after `rate = self.symbol_price_prec(pair, rate)`? 

if yes, please extend it to also show `type(rate)` - maybe there is somehow a odd type involved causing "something" to fail ... 

also, please change the line `return self._api.create_limit_sell_order(pair, amount, rate)` to the following lines:
```python
ret = self._api.create_limit_sell_order(pair, amount, rate)
logger.debug("ccxt return: %s", ret)
return ret
```
Code:
```
        try:
            # Set the precision for amount and price(rate) as accepted by the exchange
            logger.debug("Rate for sell in exchange/__init__py: %s",rate)
            amount = self.symbol_amount_prec(pair, amount)
            rate = self.symbol_price_prec(pair, rate)
            logger.debug("Rate for sell in exchange/__init__py: %s",rate)

            logger.debug("Parameters for create_limit_sell_order. pair: %s, amount: %s, rate: %s",pair,amount,rate)
            logger.debug("type(rate): %s",type(rate))
            ret = self._api.create_limit_sell_order(pair, amount, rate)
            logger.debug("ccxt return: %s", ret)
            return ret
```

output:

```
2018-10-20 18:07:12,287 - freqtrade.exchange - DEBUG - Rate for sell in exchange/__init__py: 1.78e-06
2018-10-20 18:07:12,288 - freqtrade.exchange - DEBUG - Price in symbol_price_prec 1.78e-06
2018-10-20 18:07:12,288 - freqtrade.exchange - DEBUG - Rate for sell in exchange/__init__py: 1.78e-06
2018-10-20 18:07:12,288 - freqtrade.exchange - DEBUG - Parameters for create_limit_sell_order. pair: POE/BTC, amount: 5549.445, rate: 1.78e-06
2018-10-20 18:07:12,288 - freqtrade.exchange - DEBUG - type(rate): <class 'float'>
2018-10-20 18:07:12,793 - freqtrade.exchange - DEBUG - ccxt return: {'info': {'symbol': 'POEBTC', 'orderId': 21744127, 'clientOrderId': '', 'transactTime': 1540051632660, 'price': '0.00000200', 'origQty': '5549.00000000', 'executedQty': '0.00000000', 'cummulativeQuoteQty': '0.00000000', 'status': 'NEW', 'timeInForce': 'GTC', 'type': 'LIMIT', 'side': 'SELL'}, 'id': '21744127', 'timestamp': 1540051632660, 'datetime': '2018-10-20T16:07:12.660Z', 'lastTradeTimestamp': None, 'symbol': 'POE/BTC', 'type': 'limit', 'side': 'sell', 'price': 2e-06, 'amount': 5549.0, 'cost': 0.0, 'average': None, 'filled': 0.0, 'remaining': 5549.0, 'status': 'open', 'fee': None, 'trades': None}

Request: POST https://api.binance.com/api/v3/order {'X-MBX-APIKEY': '', 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'python-requests/2.19.1', 'Accept-Encoding': 'gzip, deflate'} timestamp=1540051632520&recvWindow=5000&symbol=POEBTC&quantity=5549&type=LIMIT&side=SELL&newOrderRespType=RESULT&price=0.000002&timeInForce=GTC&signature=

Response: POST https://api.binance.com/api/v3/order 200 {'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Date': 'Sat, 20 Oct 2018 16:07:12 GMT', 'Server': 'nginx', 'Content-Encoding': 'gzip', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains', 'X-Frame-Options': 'SAMEORIGIN', 'X-Xss-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Security-Policy': "default-src 'self'", 'X-Content-Security-Policy': "default-src 'self'", 'X-WebKit-CSP': "default-src 'self'", 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Cache': 'Miss from cloudfront', 'Via': '1.1 2e8f70eb03b681aa6bd8c18fff081f80.cloudfront.net (CloudFront)', 'X-Amz-Cf-Id': ''} {"symbol":"POEBTC","orderId":21744127,"clientOrderId":"","transactTime":1540051632660,"price":"0.00000200","origQty":"5549.00000000","executedQty":"0.00000000","cummulativeQuoteQty":"0.00000000","status":"NEW","timeInForce":"GTC","type":"LIMIT","side":"SELL"}
```
I struggle to make sense of this - which is really not your fault...

`rate: 1.78e-06` shows that we do pass in 1.78e-06.

however ccxt reqeust then shows `&price=0.000002` - clearly rounded.

Yes - the amount changes to the int amount but that's expected as it was created as part of fees - the residual is called "binance dust" - and the only way i found to avoid this is to have BNB in your account (so fees go off of that asset).

I have added this:
```
        try:
            # Set the precision for amount and price(rate) as accepted by the exchange
            logger.debug("Rate for sell in exchange/__init__py: %s",rate)
            amount = self.symbol_amount_prec(pair, amount)
            rate = self.symbol_price_prec(pair, rate)
            logger.debug("Rate for sell in exchange/__init__py: %s",rate)

            logger.debug("Parameters for create_limit_sell_order. pair: %s, amount: %s, rate: %s",pair,amount,rate)
            logger.debug("type(rate): %s",type(rate))
            ret = self._api.create_limit_sell_order(pair, amount, rate)
            logger.debug("ccxt return: %s", ret)
            logger.debug("Current price precision for POE/BTC: %s",self._api.markets['POE/BTC']['precision']['price'])
            logger.debug("Current price limits for POE/BTC: %s",self._api.markets['POE/BTC']['limits']['price'])
            return ret
```

But still getting this:

```
2018-10-20 19:22:28,630 - freqtrade.exchange - DEBUG - Rate for sell in exchange/__init__py: 1.77e-06
2018-10-20 19:22:28,630 - freqtrade.exchange - DEBUG - Price in symbol_price_prec 1.77e-06
2018-10-20 19:22:28,630 - freqtrade.exchange - DEBUG - Rate for sell in exchange/__init__py: 1.77e-06
2018-10-20 19:22:28,630 - freqtrade.exchange - DEBUG - Parameters for create_limit_sell_order. pair: POE/BTC, amount: 5549.445, rate: 1.77e-06
2018-10-20 19:22:28,630 - freqtrade.exchange - DEBUG - type(rate): <class 'float'>

Request: POST https://api.binance.com/api/v3/order {'X-MBX-APIKEY': '', 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'python-requests/2.19.1', 'Accept-Encoding': 'gzip, deflate'} timestamp=1540056146646&recvWindow=5000&symbol=TRXBTC&quantity=2702&type=LIMIT&side=SELL&newOrderRespType=RESULT&price=0.000004&timeInForce=GTC&signature=

Response: POST https://api.binance.com/api/v3/order 200 {'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Date': 'Sat, 20 Oct 2018 17:22:26 GMT', 'Server': 'nginx', 'Content-Encoding': 'gzip', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains', 'X-Frame-Options': 'SAMEORIGIN', 'X-Xss-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Security-Policy': "default-src 'self'", 'X-Content-Security-Policy': "default-src 'self'", 'X-WebKit-CSP': "default-src 'self'", 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Cache': 'Miss from cloudfront', 'Via': '1.1 50f21cb925e6471490e080147e252d7d.cloudfront.net (CloudFront)', 'X-Amz-Cf-Id': ''} {"symbol":"TRXBTC","orderId":74954950,"clientOrderId":"","transactTime":1540056146788,"price":"0.00000400","origQty":"2702.00000000","executedQty":"0.00000000","cummulativeQuoteQty":"0.00000000","status":"NEW","timeInForce":"GTC","type":"LIMIT","side":"SELL"}
2018-10-20 19:22:29,140 - freqtrade.exchange - DEBUG - Current price precision for POE/BTC: 8
2018-10-20 19:22:29,140 - freqtrade.exchange - DEBUG - Current price limits for POE/BTC: {'min': 1.8e-07, 'max': 1.77e-05}
```
this request does not make sense... 
the log output shows `Parameters for create_limit_sell_order. pair: POE/BTC, amount: 5549.445, rate: 1.77e-06`

but the post-request is for `symbol=TRXBTC` ...


``` python
import ccxt
ct = ccxt.binance({'apiKey': 'a',
            'secret': 'b',
                   'verbose': True
                  })
mark = ct.loadMarkets()
pair='POE/BTC'
amount=5549.445
price=1.78e-06
print(f"Parameters for create_limit_sell_order. pair: {pair}, amount: {amount}, rate:{rate}")
ct.create_limit_buy_order(pair, amount, rate)

```


running the code above - i get the following output:

```
Parameters for create_limit_sell_order. pair: POE/BTC, amount: 5549.445, rate:1.78e-06

Request: POST https://api.binance.com/api/v3/order {'X-MBX-APIKEY': 'a', 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'python-requests/2.19.1', 'Accept-Encoding': 'gzip, deflate'} timestamp=1540056460821&recvWindow=5000&symbol=POEBTC&quantity=5549&type=LIMIT&side=BUY&newOrderRespType=RESULT&price=0.00000178&timeInForce=GTC&signature=a45768a6b4eb76b8cdd2c4bb8c87a32ad12c81f3814f7dda3bef90c6561a9cbd

Response: POST https://api.binance.com/api/v3/order 401 {'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Date': 'Sat, 20 Oct 2018 17:27:40 GMT', 'Server': 'nginx', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains', 'X-Frame-Options': 'SAMEORIGIN', 'X-Xss-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Security-Policy': "default-src 'self'", 'X-Content-Security-Policy': "default-src 'self'", 'X-WebKit-CSP': "default-src 'self'", 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 5c82476b8faa6db5077c339ee3b64cf0.cloudfront.net (CloudFront)', 'X-Amz-Cf-Id': 'bPVmbVkOpAe4Wzq3vVn6Cvev3B5al1XDCvVRm6uPxmzTXqkDMHe4dA=='} {"code":-2014,"msg":"API-key format invalid."}
```

i know my key is invalid, but it shows that the request is passed through ccxt unmodified... however your own logs show that the price is also correct in freqtrade 


I get the same results.
_Should i try to start it without DB? Is there any other caching/persistence implemented than database?_
nevermind, that does not make sense
also without DB will use the a inmemory sqlite3 database, as some persistance is needed, and i would honestly not know how persistance can affect this
Closing, issue was caused by setting of decimal context precision in freqtrade persistence api, which caused ccxt to round incorrectly.

Source of the issue:
https://github.com/freqtrade/freqtrade/blob/98240e0e48b2f4f61775e776dbc5f7713452bce8/freqtrade/persistence.py#L244

I would do a PR to remove it, but i am not sure if it does not break Bittrex support.

Code to reproduce (from https://github.com/ccxt/ccxt/blob/5a3fa3961472d80a5eb24e8a54a57f877d5cae78/python/ccxt/base/decimal_to_precision.py#L37):

```
import decimal
import numbers

# rounding mode
TRUNCATE = 0
ROUND = 1

# digits counting mode
DECIMAL_PLACES = 2
SIGNIFICANT_DIGITS = 3

# padding mode
NO_PADDING = 4
PAD_WITH_ZERO = 5

n=1.77e-06
precision=8

rounding_mode=ROUND
padding_mode=NO_PADDING
counting_mode=DECIMAL_PLACES

assert precision is not None and isinstance(precision, numbers.Integral)
assert rounding_mode in [TRUNCATE, ROUND]
assert counting_mode in [DECIMAL_PLACES, SIGNIFICANT_DIGITS]
assert padding_mode in [NO_PADDING, PAD_WITH_ZERO]

context = decimal.getcontext()

# If decimal.getcontext().prec is set to 8:
context.prec=8

precision = min(context.prec - 2, precision)

context.traps[decimal.Underflow] = True
context.rounding = decimal.ROUND_HALF_UP  # rounds 0.5 away from zero

dec = decimal.Decimal(str(n))
string = '{:f}'.format(dec)  # convert to string using .format to avoid engineering notation
precise = None

def power_of_10(x):
  return decimal.Decimal('10') ** (-x)

'{:f}'.format(dec.quantize(power_of_10(precision))) # ROUND_HALF_EVEN is default context
```

This produces result: '0.000002'
_Reopening until fix_
it won't break bittrex - it's a remainder of pre-ccxt times.
we handled api calls ourselfs - which could cause too high precision. ccxt does tat itself - so removing it should be straightforward - but will break a few tests as the precision raises ...



Resolving patch:
diff --git a/freqtrade/persistence.py b/freqtrade/persistence.py
--- a/freqtrade/persistence.py
+++ b/freqtrade/persistence.py
@@ -4,7 +4,7 @@
 
 import logging
 from datetime import datetime
-from decimal import Decimal, getcontext
+from decimal import Decimal
 from typing import Any, Dict, Optional
 
 import arrow
@@ -241,7 +241,6 @@ def update(self, order: Dict) -> None:
 
         logger.info('Updating trade (id=%d) ...', self.id)
 
-        getcontext().prec = 8  # Bittrex do not go above 8 decimal
         if order_type == 'limit' and order['side'] == 'buy':
             # Update open rate and actual amount
             self.open_rate = Decimal(order['price'])
@@ -278,7 +277,6 @@ def calc_open_trade_price(
         If rate is not set self.fee will be used
         :return: Price in BTC of the open trade
         """
-        getcontext().prec = 8
 
         buy_trade = (Decimal(self.amount) * Decimal(self.open_rate))
         fees = buy_trade * Decimal(fee or self.fee_open)
@@ -296,7 +294,6 @@ def calc_close_trade_price(
         If rate is not set self.close_rate will be used
         :return: Price in BTC of the open trade
         """
-        getcontext().prec = 8
 
         if rate is None and not self.close_rate:
             return 0.0
@@ -336,7 +333,6 @@ def calc_profit_percent(
         :param fee: fee to use on the close rate (optional).
         :return: profit in percentage as float
         """
-        getcontext().prec = 8
 
         open_trade_price = self.calc_open_trade_price()
         close_trade_price = self.calc_close_trade_price(


Test patch:
diff --git a/freqtrade/tests/optimize/test_backtesting.py b/freqtrade/tests/optimize/test_backtesting.py
--- a/freqtrade/tests/optimize/test_backtesting.py
+++ b/freqtrade/tests/optimize/test_backtesting.py
@@ -534,7 +534,7 @@ def test_backtest(default_conf, fee, mocker) -> None:
 
     expected = pd.DataFrame(
         {'pair': [pair, pair],
-         'profit_percent': [0.00029975, 0.00056708],
+         'profit_percent': [0.00029977, 0.00056716],
          'profit_abs': [1.49e-06, 7.6e-07],
          'open_time': [Arrow(2018, 1, 29, 18, 40, 0).datetime,
                        Arrow(2018, 1, 30, 3, 30, 0).datetime],
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
@@ -725,7 +725,7 @@ def test_forcesell_handle(default_conf, update, ticker, fee,
         'open_rate': 1.099e-05,
         'current_rate': 1.172e-05,
         'profit_amount': 6.126e-05,
-        'profit_percent': 0.06110514,
+        'profit_percent': 0.0611052,
         'stake_currency': 'BTC',
         'fiat_currency': 'USD',
     } == last_msg
@@ -778,7 +778,7 @@ def test_forcesell_down_handle(default_conf, update, ticker, fee,
         'open_rate': 1.099e-05,
         'current_rate': 1.044e-05,
         'profit_amount': -5.492e-05,
-        'profit_percent': -0.05478343,
+        'profit_percent': -0.05478342,
         'stake_currency': 'BTC',
         'fiat_currency': 'USD',
     } == last_msg
@@ -823,7 +823,7 @@ def test_forcesell_all_handle(default_conf, update, ticker, fee, markets, mocker
         'open_rate': 1.099e-05,
         'current_rate': 1.098e-05,
         'profit_amount': -5.91e-06,
-        'profit_percent': -0.00589292,
+        'profit_percent': -0.00589291,
         'stake_currency': 'BTC',
         'fiat_currency': 'USD',
     } == msg
diff --git a/freqtrade/tests/test_freqtradebot.py b/freqtrade/tests/test_freqtradebot.py
--- a/freqtrade/tests/test_freqtradebot.py
+++ b/freqtrade/tests/test_freqtradebot.py
@@ -167,11 +167,6 @@ def test_gen_pair_whitelist_not_supported(mocker, default_conf, tickers) -> None
         freqtrade._gen_pair_whitelist(base_currency='BTC')
 
 
-@pytest.mark.skip(reason="Test not implemented")
-def test_refresh_whitelist() -> None:
-    pass
-
-
 def test_get_trade_stake_amount(default_conf, ticker, limit_buy_order, fee, mocker) -> None:
     patch_RPCManager(mocker)
     patch_exchange(mocker)
@@ -804,7 +799,7 @@ def test_handle_trade(default_conf, limit_buy_order, limit_sell_order,
     trade.update(limit_sell_order)
 
     assert trade.close_rate == 0.00001173
-    assert trade.close_profit == 0.06201057
+    assert trade.close_profit == 0.06201058
     assert trade.calc_profit() == 0.00006217
     assert trade.close_date is not None
 
@@ -1231,7 +1226,7 @@ def test_execute_sell_up(default_conf, ticker, fee, ticker_sell_up, markets, moc
         'open_rate': 1.099e-05,
         'current_rate': 1.172e-05,
         'profit_amount': 6.126e-05,
-        'profit_percent': 0.06110514,
+        'profit_percent': 0.0611052,
         'stake_currency': 'BTC',
         'fiat_currency': 'USD',
     } == last_msg
@@ -1277,7 +1272,7 @@ def test_execute_sell_down(default_conf, ticker, fee, ticker_sell_down, markets,
         'open_rate': 1.099e-05,
         'current_rate': 1.044e-05,
         'profit_amount': -5.492e-05,
-        'profit_percent': -0.05478343,
+        'profit_percent': -0.05478342,
         'stake_currency': 'BTC',
         'fiat_currency': 'USD',
     } == last_msg
@@ -1324,7 +1319,7 @@ def test_execute_sell_without_conf_sell_up(default_conf, ticker, fee,
         'open_rate': 1.099e-05,
         'current_rate': 1.172e-05,
         'profit_amount': 6.126e-05,
-        'profit_percent': 0.06110514,
+        'profit_percent': 0.0611052,
     } == last_msg
 
 
@@ -1370,7 +1365,7 @@ def test_execute_sell_without_conf_sell_down(default_conf, ticker, fee,
         'open_rate': 1.099e-05,
         'current_rate': 1.044e-05,
         'profit_amount': -5.492e-05,
-        'profit_percent': -0.05478343,
+        'profit_percent': -0.05478342,
     } == last_msg
 
 
diff --git a/freqtrade/tests/test_persistence.py b/freqtrade/tests/test_persistence.py
--- a/freqtrade/tests/test_persistence.py
+++ b/freqtrade/tests/test_persistence.py
@@ -113,7 +113,7 @@ def test_update_with_bittrex(limit_buy_order, limit_sell_order, fee):
     trade.update(limit_sell_order)
     assert trade.open_order_id is None
     assert trade.close_rate == 0.00001173
-    assert trade.close_profit == 0.06201057
+    assert trade.close_profit == 0.06201058
     assert trade.close_date is not None
 
 
@@ -129,16 +129,16 @@ def test_calc_open_close_trade_price(limit_buy_order, limit_sell_order, fee):
 
     trade.open_order_id = 'something'
     trade.update(limit_buy_order)
-    assert trade.calc_open_trade_price() == 0.001002500
+    assert trade.calc_open_trade_price() == 0.0010024999999225068
 
     trade.update(limit_sell_order)
-    assert trade.calc_close_trade_price() == 0.0010646656
+    assert trade.calc_close_trade_price() == 0.0010646656050132426
 
     # Profit in BTC
     assert trade.calc_profit() == 0.00006217
 
     # Profit in percent
-    assert trade.calc_profit_percent() == 0.06201057
+    assert trade.calc_profit_percent() == 0.06201058
 
 
 @pytest.mark.usefixtures("init_persistence")
@@ -207,10 +207,10 @@ def test_calc_open_trade_price(limit_buy_order, fee):
     trade.update(limit_buy_order)  # Buy @ 0.00001099
 
     # Get the open rate price with the standard fee rate
-    assert trade.calc_open_trade_price() == 0.001002500
+    assert trade.calc_open_trade_price() == 0.0010024999999225068
 
     # Get the open rate price with a custom fee rate
-    assert trade.calc_open_trade_price(fee=0.003) == 0.001003000
+    assert trade.calc_open_trade_price(fee=0.003) == 0.001002999999922468
 
 
 @pytest.mark.usefixtures("init_persistence")
@@ -226,14 +226,14 @@ def test_calc_close_trade_price(limit_buy_order, limit_sell_order, fee):
     trade.update(limit_buy_order)  # Buy @ 0.00001099
 
     # Get the close rate price with a custom close rate and a regular fee rate
-    assert trade.calc_close_trade_price(rate=0.00001234) == 0.0011200318
+    assert trade.calc_close_trade_price(rate=0.00001234) == 0.0011200318470471794
 
     # Get the close rate price with a custom close rate and a custom fee rate
-    assert trade.calc_close_trade_price(rate=0.00001234, fee=0.003) == 0.0011194704
+    assert trade.calc_close_trade_price(rate=0.00001234, fee=0.003) == 0.0011194704275749754
 
     # Test when we apply a Sell order, and ask price with a custom fee rate
     trade.update(limit_sell_order)
-    assert trade.calc_close_trade_price(fee=0.005) == 0.0010619972
+    assert trade.calc_close_trade_price(fee=0.005) == 0.0010619972701635854
 
 
 @pytest.mark.usefixtures("init_persistence")
@@ -281,17 +281,17 @@ def test_calc_profit_percent(limit_buy_order, limit_sell_order, fee):
     trade.update(limit_buy_order)  # Buy @ 0.00001099
 
     # Get percent of profit with a custom rate (Higher than open rate)
-    assert trade.calc_profit_percent(rate=0.00001234) == 0.1172387
+    assert trade.calc_profit_percent(rate=0.00001234) == 0.11723875
 
     # Get percent of profit with a custom rate (Lower than open rate)
-    assert trade.calc_profit_percent(rate=0.00000123) == -0.88863827
+    assert trade.calc_profit_percent(rate=0.00000123) == -0.88863828
 
     # Test when we apply a Sell order. Sell higher than open rate @ 0.00001173
     trade.update(limit_sell_order)
-    assert trade.calc_profit_percent() == 0.06201057
+    assert trade.calc_profit_percent() == 0.06201058
 
     # Test with a custom fee rate on the close trade
-    assert trade.calc_profit_percent(fee=0.003) == 0.0614782
+    assert trade.calc_profit_percent(fee=0.003) == 0.06147824
 
 
 def test_clean_dry_run_db(default_conf, fee):