amount to contract precision to test_utils
This commit is contained in:
@@ -17,7 +17,6 @@ from freqtrade.exchange import (Binance, Bittrex, Exchange, Kraken, market_is_ac
|
|||||||
timeframe_to_prev_date)
|
timeframe_to_prev_date)
|
||||||
from freqtrade.exchange.common import (API_FETCH_ORDER_RETRY_COUNT, API_RETRY_COUNT,
|
from freqtrade.exchange.common import (API_FETCH_ORDER_RETRY_COUNT, API_RETRY_COUNT,
|
||||||
calculate_backoff, remove_exchange_credentials)
|
calculate_backoff, remove_exchange_credentials)
|
||||||
from freqtrade.exchange.exchange import amount_to_contract_precision
|
|
||||||
from freqtrade.resolvers.exchange_resolver import ExchangeResolver
|
from freqtrade.resolvers.exchange_resolver import ExchangeResolver
|
||||||
from freqtrade.util import dt_now, dt_ts
|
from freqtrade.util import dt_now, dt_ts
|
||||||
from tests.conftest import (EXMS, generate_test_data_raw, get_mock_coro, get_patched_exchange,
|
from tests.conftest import (EXMS, generate_test_data_raw, get_mock_coro, get_patched_exchange,
|
||||||
@@ -4449,20 +4448,6 @@ def test_amount_to_contract_precision(
|
|||||||
assert result_size == expected_fut
|
assert result_size == expected_fut
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('amount,precision,precision_mode,contract_size,expected', [
|
|
||||||
(1.17, 1.0, 4, 0.01, 1.17), # Tick size
|
|
||||||
(1.17, 1.0, 2, 0.01, 1.17), #
|
|
||||||
(1.16, 1.0, 4, 0.01, 1.16), #
|
|
||||||
(1.16, 1.0, 2, 0.01, 1.16), #
|
|
||||||
(1.13, 1.0, 2, 0.01, 1.13), #
|
|
||||||
(10.988, 1.0, 2, 10, 10),
|
|
||||||
(10.988, 1.0, 4, 10, 10),
|
|
||||||
])
|
|
||||||
def test_amount_to_contract_precision2(amount, precision, precision_mode, contract_size, expected):
|
|
||||||
res = amount_to_contract_precision(amount, precision, precision_mode, contract_size)
|
|
||||||
assert pytest.approx(res) == expected
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('exchange_name,open_rate,is_short,trading_mode,margin_mode', [
|
@pytest.mark.parametrize('exchange_name,open_rate,is_short,trading_mode,margin_mode', [
|
||||||
# Bittrex
|
# Bittrex
|
||||||
('bittrex', 2.0, False, 'spot', None),
|
('bittrex', 2.0, False, 'spot', None),
|
||||||
|
|||||||
@@ -6,9 +6,10 @@ from ccxt import DECIMAL_PLACES, ROUND, ROUND_UP, TICK_SIZE, TRUNCATE
|
|||||||
|
|
||||||
from freqtrade.enums import RunMode
|
from freqtrade.enums import RunMode
|
||||||
from freqtrade.exceptions import OperationalException
|
from freqtrade.exceptions import OperationalException
|
||||||
from freqtrade.exchange import (amount_to_precision, date_minus_candles, price_to_precision,
|
from freqtrade.exchange import (amount_to_contract_precision, amount_to_precision,
|
||||||
timeframe_to_minutes, timeframe_to_msecs, timeframe_to_next_date,
|
date_minus_candles, price_to_precision, timeframe_to_minutes,
|
||||||
timeframe_to_prev_date, timeframe_to_seconds)
|
timeframe_to_msecs, timeframe_to_next_date, timeframe_to_prev_date,
|
||||||
|
timeframe_to_seconds)
|
||||||
from freqtrade.exchange.check_exchange import check_exchange
|
from freqtrade.exchange.check_exchange import check_exchange
|
||||||
from tests.conftest import log_has_re
|
from tests.conftest import log_has_re
|
||||||
|
|
||||||
@@ -259,3 +260,18 @@ def test_amount_to_precision(amount, precision_mode, precision, expected,):
|
|||||||
def test_price_to_precision(price, precision_mode, precision, expected, rounding_mode):
|
def test_price_to_precision(price, precision_mode, precision, expected, rounding_mode):
|
||||||
assert price_to_precision(
|
assert price_to_precision(
|
||||||
price, precision, precision_mode, rounding_mode=rounding_mode) == expected
|
price, precision, precision_mode, rounding_mode=rounding_mode) == expected
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('amount,precision,precision_mode,contract_size,expected', [
|
||||||
|
(1.17, 1.0, 4, 0.01, 1.17), # Tick size
|
||||||
|
(1.17, 1.0, 2, 0.01, 1.17), #
|
||||||
|
(1.16, 1.0, 4, 0.01, 1.16), #
|
||||||
|
(1.16, 1.0, 2, 0.01, 1.16), #
|
||||||
|
(1.13, 1.0, 2, 0.01, 1.13), #
|
||||||
|
(10.988, 1.0, 2, 10, 10),
|
||||||
|
(10.988, 1.0, 4, 10, 10),
|
||||||
|
])
|
||||||
|
def test_amount_to_contract_precision_standalone(amount, precision, precision_mode, contract_size,
|
||||||
|
expected):
|
||||||
|
res = amount_to_contract_precision(amount, precision, precision_mode, contract_size)
|
||||||
|
assert pytest.approx(res) == expected
|
||||||
|
|||||||
Reference in New Issue
Block a user