Revert price_to_precision to rounding up
This commit is contained in:
parent
d7957bd791
commit
bea4ad8eff
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user