From bea4ad8effa97626de4ae51d7f0e6c06c963a00f Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 14 Jan 2020 20:16:20 +0100 Subject: [PATCH] Revert price_to_precision to rounding up --- freqtrade/exchange/exchange.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index dd6f257fe..a7243d4d2 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -7,6 +7,7 @@ import inspect import logging from copy import deepcopy from datetime import datetime, timezone +from math import ceil from random import randint from typing import Any, Dict, List, Optional, Tuple @@ -14,7 +15,7 @@ import arrow import ccxt import ccxt.async_support as ccxt_async 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 freqtrade.data.converter import parse_ticker_dataframe @@ -383,15 +384,27 @@ class Exchange: def price_to_precision(self, pair, price: float) -> float: ''' - Returns the price buying or selling with to the precision the Exchange accepts - Reimplementation of ccxt internal methods - ensuring we can test the result is correct - based on our definitions. + Returns the price rounded up to the precision the Exchange accepts. + Partial Reimplementation of ccxt internal method decimal_to_precision(), + 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']: - price = float(decimal_to_precision(price, rounding_mode=ROUND, - precision=self.markets[pair]['precision']['price'], - counting_mode=self.precisionMode, - )) + # price = float(decimal_to_precision(price, rounding_mode=ROUND, + # precision=self.markets[pair]['precision']['price'], + # 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 def dry_run_order(self, pair: str, ordertype: str, side: str, amount: float,