Revert having price_rounding_mode as configuration

This commit is contained in:
Matthias 2023-03-26 10:17:01 +02:00
parent 1132fa6093
commit 01dfb1cba8
3 changed files with 6 additions and 31 deletions

View File

@ -5,8 +5,6 @@ bot constants
""" """
from typing import Any, Dict, List, Literal, Tuple from typing import Any, Dict, List, Literal, Tuple
from ccxt import ROUND, ROUND_DOWN, ROUND_UP, TRUNCATE
from freqtrade.enums import CandleType, PriceType, RPCMessageType from freqtrade.enums import CandleType, PriceType, RPCMessageType
@ -52,8 +50,6 @@ DEFAULT_DATAFRAME_COLUMNS = ['date', 'open', 'high', 'low', 'close', 'volume']
# it has wide consequences for stored trades files # it has wide consequences for stored trades files
DEFAULT_TRADES_COLUMNS = ['timestamp', 'id', 'type', 'side', 'price', 'amount', 'cost'] DEFAULT_TRADES_COLUMNS = ['timestamp', 'id', 'type', 'side', 'price', 'amount', 'cost']
TRADING_MODES = ['spot', 'margin', 'futures'] TRADING_MODES = ['spot', 'margin', 'futures']
PRICE_ROUND_MODES = [TRUNCATE, ROUND, ROUND_UP, ROUND_DOWN]
DEFAULT_PRICE_ROUND_MODE = ROUND_UP
MARGIN_MODES = ['cross', 'isolated', ''] MARGIN_MODES = ['cross', 'isolated', '']
LAST_BT_RESULT_FN = '.last_result.json' LAST_BT_RESULT_FN = '.last_result.json'
@ -480,9 +476,7 @@ CONF_SCHEMA = {
'outdated_offset': {'type': 'integer', 'minimum': 1}, 'outdated_offset': {'type': 'integer', 'minimum': 1},
'markets_refresh_interval': {'type': 'integer'}, 'markets_refresh_interval': {'type': 'integer'},
'ccxt_config': {'type': 'object'}, 'ccxt_config': {'type': 'object'},
'ccxt_async_config': {'type': 'object'}, 'ccxt_async_config': {'type': 'object'}
'price_rounding_mode': {'type': 'integer', 'enum': PRICE_ROUND_MODES,
'default': DEFAULT_PRICE_ROUND_MODE}
}, },
'required': ['name'] 'required': ['name']
}, },

View File

@ -143,9 +143,7 @@ class Exchange:
if config.get('margin_mode') if config.get('margin_mode')
else MarginMode.NONE else MarginMode.NONE
) )
self.liquidation_buffer = config.get("liquidation_buffer", 0.05) self.liquidation_buffer = config.get('liquidation_buffer', 0.05)
self._price_rounding_mode = exchange_config.get("price_rounding_mode",
DEFAULT_PRICE_ROUND_MODE)
# Deep merge ft_has with default ft_has options # Deep merge ft_has with default ft_has options
self._ft_has = deep_merge_dicts(self._ft_has, deepcopy(self._ft_has_default)) self._ft_has = deep_merge_dicts(self._ft_has, deepcopy(self._ft_has_default))
@ -732,13 +730,14 @@ class Exchange:
""" """
return amount_to_precision(amount, self.get_precision_amount(pair), self.precisionMode) return amount_to_precision(amount, self.get_precision_amount(pair), self.precisionMode)
def price_to_precision(self, pair: str, price: float) -> float: def price_to_precision(self, pair: str, price: float, rounding_mode: int) -> float:
""" """
Returns the price rounded to the precision the Exchange accepts. Returns the price rounded to the precision the Exchange accepts.
The default price_rounding_mode in conf is ROUND_UP The default price_rounding_mode in conf is ROUND.
Must use ROUND_UP / ROUND_DOWN for stoploss calculations.
""" """
return price_to_precision(price, self.get_precision_price(pair), return price_to_precision(price, self.get_precision_price(pair),
self.precisionMode, self._price_rounding_mode) self.precisionMode, rounding_mode)
def price_get_one_pip(self, pair: str, price: float) -> float: def price_get_one_pip(self, pair: str, price: float) -> float:
""" """

View File

@ -5328,21 +5328,3 @@ def test_price_to_precision_with_default_conf(default_conf, mocker):
prec_price = patched_ex.price_to_precision("XRP/USDT", 1.0000000101) prec_price = patched_ex.price_to_precision("XRP/USDT", 1.0000000101)
assert prec_price == 1.00000002 assert prec_price == 1.00000002
@pytest.mark.parametrize(
"rounding_mode, price, expected_price",
[
(TRUNCATE, 1.0000000199, 1.00000001),
(ROUND, 1.0000000149, 1.00000001),
(ROUND, 1.0000000151, 1.00000002),
(ROUND_UP, 1.0000000101, 1.00000002),
],
)
def test_price_to_precision_rounding_mode_from_conf(
default_conf, mocker, rounding_mode, price, expected_price
):
conf = copy.deepcopy(default_conf)
conf["exchange"]["price_rounding_mode"] = rounding_mode
patched_ex = get_patched_exchange(mocker, conf)
prec_price = patched_ex.price_to_precision("XRP/USDT", price)
assert prec_price == expected_price