Introuce WalletDry - supporting dry-run wallets

This commit is contained in:
Matthias 2019-12-15 09:38:18 +01:00
parent 52b212db64
commit fda8f7e305
3 changed files with 46 additions and 14 deletions

View File

@ -25,7 +25,7 @@ from freqtrade.rpc import RPCManager, RPCMessageType
from freqtrade.pairlist.pairlistmanager import PairListManager
from freqtrade.state import State
from freqtrade.strategy.interface import IStrategy, SellType
from freqtrade.wallets import Wallets
from freqtrade.wallets import Wallets, WalletsDry
logger = logging.getLogger(__name__)
@ -62,7 +62,13 @@ class FreqtradeBot:
self.exchange = ExchangeResolver(self.config['exchange']['name'], self.config).exchange
self.wallets = Wallets(self.config, self.exchange)
persistence.init(self.config.get('db_url', None),
clean_open_orders=self.config.get('dry_run', False))
if self.config['dry_run']:
self.wallets = WalletsDry(self.config, self.exchange)
else:
self.wallets = Wallets(self.config, self.exchange)
self.dataprovider = DataProvider(self.config, self.exchange)
# Attach Dataprovider to Strategy baseclass
@ -78,9 +84,6 @@ class FreqtradeBot:
self.active_pair_whitelist = self._refresh_whitelist()
persistence.init(self.config.get('db_url', None),
clean_open_orders=self.config.get('dry_run', False))
# Set initial bot state from config
initial_state = self.config.get('initial_state')
self.state = State[initial_state.upper()] if initial_state else State.STOPPED

View File

@ -331,7 +331,13 @@ class Telegram(RPC):
try:
result = self._rpc_balance(self._config['stake_currency'],
self._config.get('fiat_display_currency', ''))
output = ''
if self._config['dry_run']:
output += (
f"Simulated balances - starting capital: "
f"`{self._config['dry_run_wallet']}` {self._config['stake_currency']}.\n"
)
for currency in result['currencies']:
if currency['est_stake'] > 0.0001:
curr_output = "*{currency}:*\n" \

View File

@ -28,9 +28,6 @@ class Wallets:
def get_free(self, currency) -> float:
if self._config['dry_run']:
return self._config.get('dry_run_wallet', constants.DRY_RUN_WALLET)
balance = self._wallets.get(currency)
if balance and balance.free:
return balance.free
@ -39,9 +36,6 @@ class Wallets:
def get_used(self, currency) -> float:
if self._config['dry_run']:
return self._config.get('dry_run_wallet', constants.DRY_RUN_WALLET)
balance = self._wallets.get(currency)
if balance and balance.used:
return balance.used
@ -50,9 +44,6 @@ class Wallets:
def get_total(self, currency) -> float:
if self._config['dry_run']:
return self._config.get('dry_run_wallet', constants.DRY_RUN_WALLET)
balance = self._wallets.get(currency)
if balance and balance.total:
return balance.total
@ -75,3 +66,35 @@ class Wallets:
def get_all_balances(self) -> Dict[str, Any]:
return self._wallets
class WalletsDry(Wallets):
def __init__(self, config: dict, exchange: Exchange) -> None:
self.start_cap = config['dry_run_wallet']
super().__init__(config, exchange)
def update(self) -> None:
""" Update does not do anything in dry-mode..."""
from freqtrade.persistence import Trade
closed_trades = Trade.get_trades(Trade.is_open.is_(False)).all()
print(len(closed_trades))
tot_profit = sum([trade.calc_profit() for trade in closed_trades])
current_stake = self.start_cap + tot_profit
self._wallets[self._config['stake_currency']] = Wallet(
self._config['stake_currency'],
current_stake,
0,
current_stake
)
open_trades = Trade.get_trades(Trade.is_open.is_(True)).all()
for trade in open_trades:
curr = trade.pair.split('/')[0]
trade.amount
self._wallets[curr] = Wallet(
curr,
trade.amount,
0,
trade.amount
)