From 29347a693187cbce26f2d75babca002dfec9ddda Mon Sep 17 00:00:00 2001 From: misagh Date: Sat, 24 Nov 2018 16:37:28 +0100 Subject: [PATCH] adding get_free to wallet --- freqtrade/freqtradebot.py | 2 +- freqtrade/tests/conftest.py | 7 +++---- freqtrade/wallets.py | 16 ++++++++++++---- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index c93811cae..0e77a31c0 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -337,7 +337,7 @@ class FreqtradeBot(object): else: stake_amount = self.config['stake_amount'] - avaliable_amount = self.wallets.wallets[self.config['stake_currency']].free + avaliable_amount = self.wallets.get_free(self.config['stake_currency']) if stake_amount == constants.UNLIMITED_STAKE_AMOUNT: open_trades = len(Trade.query.filter(Trade.is_open.is_(True)).all()) diff --git a/freqtrade/tests/conftest.py b/freqtrade/tests/conftest.py index cdd71fc9a..63655126c 100644 --- a/freqtrade/tests/conftest.py +++ b/freqtrade/tests/conftest.py @@ -14,7 +14,6 @@ from telegram import Chat, Message, Update from freqtrade.exchange.exchange_helpers import parse_ticker_dataframe from freqtrade.exchange import Exchange from freqtrade.edge import Edge -from freqtrade.wallets import Wallet from freqtrade.freqtradebot import FreqtradeBot logging.getLogger('').setLevel(logging.INFO) @@ -46,9 +45,9 @@ def get_patched_exchange(mocker, config, api_mock=None) -> Exchange: return exchange -def patch_wallet(mocker, currency='BTC', free=999.9) -> None: - mocker.patch('freqtrade.wallets.Wallet', MagicMock( - return_value=Wallet('bittrex', currency, free, 100, 1000) +def patch_wallet(mocker, free=999.9) -> None: + mocker.patch('freqtrade.wallets.Wallets.get_free', MagicMock( + return_value=free )) diff --git a/freqtrade/wallets.py b/freqtrade/wallets.py index 4415478d3..b8b37907d 100644 --- a/freqtrade/wallets.py +++ b/freqtrade/wallets.py @@ -26,12 +26,20 @@ class Wallets(object): def __init__(self, exchange: Exchange) -> None: self.exchange = exchange - if self.exchange._conf['dry_run']: - self.wallets: Dict[str, Any] = {'BTC': Wallet('Bittrex', 'BTC', 999.99, 100, 1000)} - else: - self.wallets: Dict[str, Any] = {} + self.wallets: Dict[str, Any] = {} self.update() + def get_free(self, currency) -> float: + + if self.exchange._conf['dry_run']: + return 999.9 + + balance = self.wallets.get(currency) + if balance and balance['free']: + return balance['free'] + else: + return 0 + def update(self) -> None: balances = self.exchange.get_balances()