total amount passed to edge should consider open trades too

This commit is contained in:
misagh 2018-12-03 19:45:00 +01:00
parent a5414b8437
commit b5192193fd
2 changed files with 13 additions and 1 deletions

View File

@ -305,7 +305,8 @@ class FreqtradeBot(object):
return self.edge.stake_amount(
pair,
self.wallets.get_free(self.config['stake_currency']),
self.wallets.get_total(self.config['stake_currency'])
self.wallets.get_total(self.config['stake_currency']) +
Trade.calc_total_open_trades_in_stake_currency()
)
else:
stake_amount = self.config['stake_amount']

View File

@ -14,6 +14,7 @@ from sqlalchemy.exc import NoSuchModuleError
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.scoping import scoped_session
from sqlalchemy.orm.session import sessionmaker
from sqlalchemy import func
from sqlalchemy.pool import StaticPool
from freqtrade import OperationalException
@ -349,3 +350,13 @@ class Trade(_DECL_BASE):
)
profit_percent = (close_trade_price / open_trade_price) - 1
return float(f"{profit_percent:.8f}")
def calc_total_open_trades_in_stake_currency() -> float:
"""
Calculates total invested amount in open trades
in stake currency
"""
total_open_stake_amount = Trade.session.query(func.sum(Trade.stake_amount))\
.filter(Trade.is_open.is_(True))\
.scalar()
return total_open_stake_amount or 0