Add "owned" fields to balance
This commit is contained in:
@@ -36,7 +36,9 @@ class Balance(BaseModel):
|
|||||||
free: float
|
free: float
|
||||||
balance: float
|
balance: float
|
||||||
used: float
|
used: float
|
||||||
|
bot_owned: Optional[float]
|
||||||
est_stake: float
|
est_stake: float
|
||||||
|
est_stake_bot: Optional[float]
|
||||||
stake: str
|
stake: str
|
||||||
# Starting with 2.x
|
# Starting with 2.x
|
||||||
side: str
|
side: str
|
||||||
|
|||||||
+18
-6
@@ -583,13 +583,16 @@ class RPC:
|
|||||||
}
|
}
|
||||||
|
|
||||||
def __balance_get_est_stake(
|
def __balance_get_est_stake(
|
||||||
self, coin: str, stake_currency: str, balance: Wallet, tickers) -> float:
|
self, coin: str, stake_currency: str, amount: float,
|
||||||
|
balance: Wallet, tickers) -> Tuple[float, float]:
|
||||||
est_stake = 0.0
|
est_stake = 0.0
|
||||||
|
est_bot_stake = 0.0
|
||||||
if coin == stake_currency:
|
if coin == stake_currency:
|
||||||
est_stake = balance.total
|
est_stake = balance.total
|
||||||
if self._config.get('trading_mode', TradingMode.SPOT) != TradingMode.SPOT:
|
if self._config.get('trading_mode', TradingMode.SPOT) != TradingMode.SPOT:
|
||||||
# in Futures, "total" includes the locked stake, and therefore all positions
|
# in Futures, "total" includes the locked stake, and therefore all positions
|
||||||
est_stake = balance.free
|
est_stake = balance.free
|
||||||
|
est_bot_stake = est_stake
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
pair = self._freqtrade.exchange.get_valid_pair_combination(coin, stake_currency)
|
pair = self._freqtrade.exchange.get_valid_pair_combination(coin, stake_currency)
|
||||||
@@ -598,11 +601,12 @@ class RPC:
|
|||||||
if pair.startswith(stake_currency) and not pair.endswith(stake_currency):
|
if pair.startswith(stake_currency) and not pair.endswith(stake_currency):
|
||||||
rate = 1.0 / rate
|
rate = 1.0 / rate
|
||||||
est_stake = rate * balance.total
|
est_stake = rate * balance.total
|
||||||
|
est_bot_stake = rate * amount
|
||||||
except (ExchangeError):
|
except (ExchangeError):
|
||||||
logger.warning(f"Could not get rate for pair {coin}.")
|
logger.warning(f"Could not get rate for pair {coin}.")
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
|
|
||||||
return est_stake
|
return est_stake, est_bot_stake
|
||||||
|
|
||||||
def _rpc_balance(self, stake_currency: str, fiat_display_currency: str) -> Dict:
|
def _rpc_balance(self, stake_currency: str, fiat_display_currency: str) -> Dict:
|
||||||
""" Returns current account balance per crypto """
|
""" Returns current account balance per crypto """
|
||||||
@@ -615,7 +619,7 @@ class RPC:
|
|||||||
raise RPCException('Error getting current tickers.')
|
raise RPCException('Error getting current tickers.')
|
||||||
|
|
||||||
open_trades: List[Trade] = Trade.get_open_trades()
|
open_trades: List[Trade] = Trade.get_open_trades()
|
||||||
open_assets = [t.base_currency for t in open_trades]
|
open_assets: Dict[str, Trade] = {t.safe_base_currency: t for t in open_trades}
|
||||||
self._freqtrade.wallets.update(require_update=False)
|
self._freqtrade.wallets.update(require_update=False)
|
||||||
starting_capital = self._freqtrade.wallets.get_starting_balance()
|
starting_capital = self._freqtrade.wallets.get_starting_balance()
|
||||||
starting_cap_fiat = self._fiat_converter.convert_amount(
|
starting_cap_fiat = self._fiat_converter.convert_amount(
|
||||||
@@ -625,21 +629,29 @@ class RPC:
|
|||||||
for coin, balance in self._freqtrade.wallets.get_all_balances().items():
|
for coin, balance in self._freqtrade.wallets.get_all_balances().items():
|
||||||
if not balance.total:
|
if not balance.total:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
trade = open_assets.get(coin, None)
|
||||||
|
is_bot_managed = coin == stake_currency or trade is not None
|
||||||
|
trade_amount = trade.amount if trade else 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
est_stake = self.__balance_get_est_stake(coin, stake_currency, balance, tickers)
|
est_stake, est_stake_bot = self.__balance_get_est_stake(
|
||||||
|
coin, stake_currency, trade_amount, balance, tickers)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
total += est_stake
|
total += est_stake
|
||||||
is_bot_managed = coin == stake_currency or coin in open_assets
|
|
||||||
if is_bot_managed:
|
if is_bot_managed:
|
||||||
total_bot += est_stake
|
total_bot += est_stake_bot
|
||||||
currencies.append({
|
currencies.append({
|
||||||
'currency': coin,
|
'currency': coin,
|
||||||
'free': balance.free,
|
'free': balance.free,
|
||||||
'balance': balance.total,
|
'balance': balance.total,
|
||||||
'used': balance.used,
|
'used': balance.used,
|
||||||
|
'bot_owned': trade_amount,
|
||||||
'est_stake': est_stake or 0,
|
'est_stake': est_stake or 0,
|
||||||
|
'est_stake_bot': est_stake_bot if is_bot_managed else 0,
|
||||||
'stake': stake_currency,
|
'stake': stake_currency,
|
||||||
'side': 'long',
|
'side': 'long',
|
||||||
'leverage': 1,
|
'leverage': 1,
|
||||||
|
|||||||
@@ -916,8 +916,7 @@ class Telegram(RPCHandler):
|
|||||||
output = ''
|
output = ''
|
||||||
if self._config['dry_run']:
|
if self._config['dry_run']:
|
||||||
output += "*Warning:* Simulated balances in Dry Mode.\n"
|
output += "*Warning:* Simulated balances in Dry Mode.\n"
|
||||||
starting_cap = round_coin_value(
|
starting_cap = round_coin_value(result['starting_capital'], self._config['stake_currency'])
|
||||||
result['starting_capital'], self._config['stake_currency'])
|
|
||||||
output += f"Starting capital: `{starting_cap}`"
|
output += f"Starting capital: `{starting_cap}`"
|
||||||
starting_cap_fiat = round_coin_value(
|
starting_cap_fiat = round_coin_value(
|
||||||
result['starting_capital_fiat'], self._config['fiat_display_currency']
|
result['starting_capital_fiat'], self._config['fiat_display_currency']
|
||||||
@@ -938,13 +937,17 @@ class Telegram(RPCHandler):
|
|||||||
f"\t`Est. {curr['stake']}: "
|
f"\t`Est. {curr['stake']}: "
|
||||||
f"{round_coin_value(curr['est_stake'], curr['stake'], False)}`\n")
|
f"{round_coin_value(curr['est_stake'], curr['stake'], False)}`\n")
|
||||||
else:
|
else:
|
||||||
|
est_stake = round_coin_value(
|
||||||
|
curr['est_stake' if full_result else 'est_stake_bot'], curr['stake'], False)
|
||||||
|
|
||||||
curr_output = (
|
curr_output = (
|
||||||
f"*{curr['currency']}:*\n"
|
f"*{curr['currency']}:*\n"
|
||||||
f"\t`Available: {curr['free']:.8f}`\n"
|
f"\t`Available: {curr['free']:.8f}`\n"
|
||||||
f"\t`Balance: {curr['balance']:.8f}`\n"
|
f"\t`Balance: {curr['balance']:.8f}`\n"
|
||||||
f"\t`Pending: {curr['used']:.8f}`\n"
|
f"\t`Pending: {curr['used']:.8f}`\n"
|
||||||
f"\t`Est. {curr['stake']}: "
|
f"\t`Bot Owned: {curr['bot_owned']:.8f}`\n"
|
||||||
f"{round_coin_value(curr['est_stake'], curr['stake'], False)}`\n")
|
f"\t`Est. {curr['stake']}: {est_stake}`\n")
|
||||||
|
|
||||||
elif curr['est_stake'] <= balance_dust_level:
|
elif curr['est_stake'] <= balance_dust_level:
|
||||||
total_dust_balance += curr['est_stake']
|
total_dust_balance += curr['est_stake']
|
||||||
total_dust_currencies += 1
|
total_dust_currencies += 1
|
||||||
|
|||||||
Reference in New Issue
Block a user