Changed InterestMode enum implementation

This commit is contained in:
Sam Germain
2021-07-07 21:04:38 -06:00
parent 86888dbbf0
commit a368dfa7b5
3 changed files with 16 additions and 22 deletions

View File

@@ -52,6 +52,7 @@ def migrate_trades_table(decl_base, inspector, engine, table_back_name: str, col
interest_rate = get_column_def(cols, 'interest_rate', '0.0')
liquidation_price = get_column_def(cols, 'liquidation_price', 'null')
is_short = get_column_def(cols, 'is_short', 'False')
interest_mode = get_column_def(cols, 'interest_mode', 'null')
# If ticker-interval existed use that, else null.
if has_column(cols, 'ticker_interval'):
timeframe = get_column_def(cols, 'timeframe', 'ticker_interval')
@@ -88,7 +89,7 @@ def migrate_trades_table(decl_base, inspector, engine, table_back_name: str, col
stoploss_order_id, stoploss_last_update,
max_rate, min_rate, sell_reason, sell_order_status, strategy,
timeframe, open_trade_value, close_profit_abs,
leverage, interest_rate, liquidation_price, is_short
leverage, interest_rate, liquidation_price, is_short, interest_mode
)
select id, lower(exchange),
case
@@ -113,7 +114,8 @@ def migrate_trades_table(decl_base, inspector, engine, table_back_name: str, col
{strategy} strategy, {timeframe} timeframe,
{open_trade_value} open_trade_value, {close_profit_abs} close_profit_abs,
{leverage} leverage, {interest_rate} interest_rate,
{liquidation_price} liquidation_price, {is_short} is_short
{liquidation_price} liquidation_price, {is_short} is_short,
{interest_mode} interest_mode
from {table_back_name}
"""))

View File

@@ -612,8 +612,6 @@ class LocalTrade():
# If nothing was borrowed
if self.has_no_leverage:
return zero
elif not self.interest_mode:
raise OperationalException(f"Leverage not available on {self.exchange} using freqtrade")
open_date = self.open_date.replace(tzinfo=None)
now = (self.close_date or datetime.now(timezone.utc)).replace(tzinfo=None)
@@ -624,7 +622,7 @@ class LocalTrade():
rate = Decimal(interest_rate or self.interest_rate)
borrowed = Decimal(self.borrowed)
return self.interest_mode.value(borrowed, rate, hours)
return self.interest_mode(borrowed=borrowed, rate=rate, hours=hours)
def calc_close_trade_value(self, rate: Optional[float] = None,
fee: Optional[float] = None,