From dced167ea2d93a7c0d46960b0ace6f4625809500 Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Thu, 16 Sep 2021 23:23:36 -0600 Subject: [PATCH] fixed some stuff in the leverage brackets binance test --- freqtrade/exchange/binance.py | 2 +- tests/exchange/test_binance.py | 117 +++++++++++++++++++-------------- 2 files changed, 70 insertions(+), 49 deletions(-) diff --git a/freqtrade/exchange/binance.py b/freqtrade/exchange/binance.py index 17e865d64..769073052 100644 --- a/freqtrade/exchange/binance.py +++ b/freqtrade/exchange/binance.py @@ -131,7 +131,7 @@ class Binance(Exchange): if self.trading_mode == TradingMode.FUTURES: try: if self._config['dry_run']: - leverage_brackets_path = Path('data') / 'leverage_brackets.json' + leverage_brackets_path = Path('freqtrade/data') / 'leverage_brackets.json' with open(leverage_brackets_path) as json_file: leverage_brackets = json.load(json_file) else: diff --git a/tests/exchange/test_binance.py b/tests/exchange/test_binance.py index f0642fda9..03b1d5044 100644 --- a/tests/exchange/test_binance.py +++ b/tests/exchange/test_binance.py @@ -2,6 +2,9 @@ from datetime import datetime, timezone from random import randint from unittest.mock import MagicMock, PropertyMock +import json +from pathlib import Path + import ccxt import pytest @@ -203,58 +206,76 @@ def test_get_max_leverage_binance(default_conf, mocker, pair, nominal_value, max def test_fill_leverage_brackets_binance(default_conf, mocker): api_mock = MagicMock() - api_mock.load_leverage_brackets = MagicMock(return_value={ - 'ADA/BUSD': [[0.0, 0.025], - [100000.0, 0.05], - [500000.0, 0.1], - [1000000.0, 0.15], - [2000000.0, 0.25], - [5000000.0, 0.5]], - 'BTC/USDT': [[0.0, 0.004], - [50000.0, 0.005], - [250000.0, 0.01], - [1000000.0, 0.025], - [5000000.0, 0.05], - [20000000.0, 0.1], - [50000000.0, 0.125], - [100000000.0, 0.15], - [200000000.0, 0.25], - [300000000.0, 0.5]], - "ZEC/USDT": [[0.0, 0.01], - [5000.0, 0.025], - [25000.0, 0.05], - [100000.0, 0.1], - [250000.0, 0.125], - [1000000.0, 0.5]], + # api_mock.load_leverage_brackets = MagicMock(return_value={ + # 'ADA/BUSD': [[0.0, 0.025], + # [100000.0, 0.05], + # [500000.0, 0.1], + # [1000000.0, 0.15], + # [2000000.0, 0.25], + # [5000000.0, 0.5]], + # 'BTC/USDT': [[0.0, 0.004], + # [50000.0, 0.005], + # [250000.0, 0.01], + # [1000000.0, 0.025], + # [5000000.0, 0.05], + # [20000000.0, 0.1], + # [50000000.0, 0.125], + # [100000000.0, 0.15], + # [200000000.0, 0.25], + # [300000000.0, 0.5]], + # "ZEC/USDT": [[0.0, 0.01], + # [5000.0, 0.025], + # [25000.0, 0.05], + # [100000.0, 0.1], + # [250000.0, 0.125], + # [1000000.0, 0.5]], - }) + # }) exchange = get_patched_exchange(mocker, default_conf, api_mock, id="binance") + exchange.trading_mode = TradingMode.FUTURES exchange.fill_leverage_brackets() - assert exchange._leverage_brackets == { - 'ADA/BUSD': [[0.0, 0.025], - [100000.0, 0.05], - [500000.0, 0.1], - [1000000.0, 0.15], - [2000000.0, 0.25], - [5000000.0, 0.5]], - 'BTC/USDT': [[0.0, 0.004], - [50000.0, 0.005], - [250000.0, 0.01], - [1000000.0, 0.025], - [5000000.0, 0.05], - [20000000.0, 0.1], - [50000000.0, 0.125], - [100000000.0, 0.15], - [200000000.0, 0.25], - [300000000.0, 0.5]], - "ZEC/USDT": [[0.0, 0.01], - [5000.0, 0.025], - [25000.0, 0.05], - [100000.0, 0.1], - [250000.0, 0.125], - [1000000.0, 0.5]], - } + leverage_brackets_path = Path('freqtrade/data') / 'leverage_brackets.json' + with open(leverage_brackets_path) as json_file: + leverage_brackets = json.load(json_file) + + for pair, brackets in leverage_brackets.items(): + leverage_brackets[pair] = [ + [ + min_amount, + float(margin_req) + ] for [ + min_amount, + margin_req + ] in brackets + ] + + assert exchange._leverage_brackets == leverage_brackets + + # assert exchange._leverage_brackets == { + # 'ADA/BUSD': [[0.0, 0.025], + # [100000.0, 0.05], + # [500000.0, 0.1], + # [1000000.0, 0.15], + # [2000000.0, 0.25], + # [5000000.0, 0.5]], + # 'BTC/USDT': [[0.0, 0.004], + # [50000.0, 0.005], + # [250000.0, 0.01], + # [1000000.0, 0.025], + # [5000000.0, 0.05], + # [20000000.0, 0.1], + # [50000000.0, 0.125], + # [100000000.0, 0.15], + # [200000000.0, 0.25], + # [300000000.0, 0.5]], + # "ZEC/USDT": [[0.0, 0.01], + # [5000.0, 0.025], + # [25000.0, 0.05], + # [100000.0, 0.1], + # [250000.0, 0.125], + # [1000000.0, 0.5]], + # } api_mock = MagicMock() api_mock.load_leverage_brackets = MagicMock()