mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
total amount passed to edge should consider open trades too
This commit is contained in:
parent
a5414b8437
commit
b5192193fd
|
@ -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']
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user