position size fixed

This commit is contained in:
misagh 2018-11-28 15:36:32 +01:00
parent 159ac6e657
commit e9305b6592
3 changed files with 33 additions and 4 deletions

View File

@ -159,11 +159,16 @@ class Edge():
return True
def stake_amount(self, pair: str, capital: float) -> float:
def stake_amount(self, pair: str, free_capital: float, total_capital: float) -> float:
stoploss = self._cached_pairs[pair].stoploss
available_capital = capital * self._capital_percentage
available_capital = total_capital * self._capital_percentage
allowed_capital_at_risk = round(available_capital * self._allowed_risk, 15)
position_size = abs(round((allowed_capital_at_risk / stoploss), 15))
max_position_size = abs(round((allowed_capital_at_risk / stoploss), 15))
position_size = min(max_position_size, free_capital)
logger.info(
'position size is %s for pair %s, stoploss %s and available capital of %s.',
position_size, pair, stoploss, available_capital
)
return position_size
def stoploss(self, pair: str) -> float:

View File

@ -334,7 +334,9 @@ class FreqtradeBot(object):
"""
if self.edge:
stake_amount = self.edge.stake_amount(
pair, self.wallets.get_free(self.config['stake_currency'])
pair,
self.wallets.get_free(self.config['stake_currency']),
self.wallets.get_total(self.config['stake_currency'])
)
return stake_amount
else:

View File

@ -40,6 +40,28 @@ class Wallets(object):
else:
return 0
def get_used(self, currency) -> float:
if self.exchange._conf['dry_run']:
return 999.9
balance = self.wallets.get(currency)
if balance and balance.used:
return balance.used
else:
return 0
def get_total(self, currency) -> float:
if self.exchange._conf['dry_run']:
return 999.9
balance = self.wallets.get(currency)
if balance and balance.total:
return balance.total
else:
return 0
def update(self) -> None:
balances = self.exchange.get_balances()