Introuce WalletDry - supporting dry-run wallets
This commit is contained in:
parent
52b212db64
commit
fda8f7e305
@ -25,7 +25,7 @@ from freqtrade.rpc import RPCManager, RPCMessageType
|
|||||||
from freqtrade.pairlist.pairlistmanager import PairListManager
|
from freqtrade.pairlist.pairlistmanager import PairListManager
|
||||||
from freqtrade.state import State
|
from freqtrade.state import State
|
||||||
from freqtrade.strategy.interface import IStrategy, SellType
|
from freqtrade.strategy.interface import IStrategy, SellType
|
||||||
from freqtrade.wallets import Wallets
|
from freqtrade.wallets import Wallets, WalletsDry
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -62,6 +62,12 @@ class FreqtradeBot:
|
|||||||
|
|
||||||
self.exchange = ExchangeResolver(self.config['exchange']['name'], self.config).exchange
|
self.exchange = ExchangeResolver(self.config['exchange']['name'], self.config).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.wallets = Wallets(self.config, self.exchange)
|
||||||
self.dataprovider = DataProvider(self.config, self.exchange)
|
self.dataprovider = DataProvider(self.config, self.exchange)
|
||||||
|
|
||||||
@ -78,9 +84,6 @@ class FreqtradeBot:
|
|||||||
|
|
||||||
self.active_pair_whitelist = self._refresh_whitelist()
|
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
|
# Set initial bot state from config
|
||||||
initial_state = self.config.get('initial_state')
|
initial_state = self.config.get('initial_state')
|
||||||
self.state = State[initial_state.upper()] if initial_state else State.STOPPED
|
self.state = State[initial_state.upper()] if initial_state else State.STOPPED
|
||||||
|
@ -331,7 +331,13 @@ class Telegram(RPC):
|
|||||||
try:
|
try:
|
||||||
result = self._rpc_balance(self._config['stake_currency'],
|
result = self._rpc_balance(self._config['stake_currency'],
|
||||||
self._config.get('fiat_display_currency', ''))
|
self._config.get('fiat_display_currency', ''))
|
||||||
|
|
||||||
output = ''
|
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']:
|
for currency in result['currencies']:
|
||||||
if currency['est_stake'] > 0.0001:
|
if currency['est_stake'] > 0.0001:
|
||||||
curr_output = "*{currency}:*\n" \
|
curr_output = "*{currency}:*\n" \
|
||||||
|
@ -28,9 +28,6 @@ class Wallets:
|
|||||||
|
|
||||||
def get_free(self, currency) -> float:
|
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)
|
balance = self._wallets.get(currency)
|
||||||
if balance and balance.free:
|
if balance and balance.free:
|
||||||
return balance.free
|
return balance.free
|
||||||
@ -39,9 +36,6 @@ class Wallets:
|
|||||||
|
|
||||||
def get_used(self, currency) -> float:
|
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)
|
balance = self._wallets.get(currency)
|
||||||
if balance and balance.used:
|
if balance and balance.used:
|
||||||
return balance.used
|
return balance.used
|
||||||
@ -50,9 +44,6 @@ class Wallets:
|
|||||||
|
|
||||||
def get_total(self, currency) -> float:
|
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)
|
balance = self._wallets.get(currency)
|
||||||
if balance and balance.total:
|
if balance and balance.total:
|
||||||
return balance.total
|
return balance.total
|
||||||
@ -75,3 +66,35 @@ class Wallets:
|
|||||||
|
|
||||||
def get_all_balances(self) -> Dict[str, Any]:
|
def get_all_balances(self) -> Dict[str, Any]:
|
||||||
return self._wallets
|
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
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user