Revert price_to_precision to rounding up

This commit is contained in:
Matthias 2020-01-14 20:16:20 +01:00
parent d7957bd791
commit bea4ad8eff

View File

@ -7,6 +7,7 @@ import inspect
import logging import logging
from copy import deepcopy from copy import deepcopy
from datetime import datetime, timezone from datetime import datetime, timezone
from math import ceil
from random import randint from random import randint
from typing import Any, Dict, List, Optional, Tuple from typing import Any, Dict, List, Optional, Tuple
@ -14,7 +15,7 @@ import arrow
import ccxt import ccxt
import ccxt.async_support as ccxt_async import ccxt.async_support as ccxt_async
from ccxt.base.decimal_to_precision import (ROUND, ROUND_DOWN, ROUND_UP, from ccxt.base.decimal_to_precision import (ROUND, ROUND_DOWN, ROUND_UP,
TRUNCATE, decimal_to_precision) TRUNCATE, TICK_SIZE, decimal_to_precision)
from pandas import DataFrame from pandas import DataFrame
from freqtrade.data.converter import parse_ticker_dataframe from freqtrade.data.converter import parse_ticker_dataframe
@ -383,15 +384,27 @@ class Exchange:
def price_to_precision(self, pair, price: float) -> float: def price_to_precision(self, pair, price: float) -> float:
''' '''
Returns the price buying or selling with to the precision the Exchange accepts Returns the price rounded up to the precision the Exchange accepts.
Reimplementation of ccxt internal methods - ensuring we can test the result is correct Partial Reimplementation of ccxt internal method decimal_to_precision(),
based on our definitions. which does not support rounding up
TODO: If ccxt supports ROUND_UP for decimal_to_precision(), we could remove this and
align with amount_to_precision().
Rounds up
''' '''
if self.markets[pair]['precision']['price']: if self.markets[pair]['precision']['price']:
price = float(decimal_to_precision(price, rounding_mode=ROUND, # price = float(decimal_to_precision(price, rounding_mode=ROUND,
precision=self.markets[pair]['precision']['price'], # precision=self.markets[pair]['precision']['price'],
counting_mode=self.precisionMode, # counting_mode=self.precisionMode,
)) # ))
if self.precisionMode == TICK_SIZE:
precision = self.markets[pair]['precision']['price']
missing = price % precision
if missing != 0:
price = price - missing + precision
else:
symbol_prec = self.markets[pair]['precision']['price']
big_price = price * pow(10, symbol_prec)
price = ceil(big_price) / pow(10, symbol_prec)
return price return price
def dry_run_order(self, pair: str, ordertype: str, side: str, amount: float, def dry_run_order(self, pair: str, ordertype: str, side: str, amount: float,