Added changes suggested in pull request, fixed breaking changes,
can run the bot again
This commit is contained in:
parent
20dcd9a1a2
commit
67341aa4f2
@ -45,14 +45,15 @@ def migrate_trades_table(decl_base, inspector, engine, table_back_name: str, col
|
|||||||
stoploss_last_update = get_column_def(cols, 'stoploss_last_update', 'null')
|
stoploss_last_update = get_column_def(cols, 'stoploss_last_update', 'null')
|
||||||
max_rate = get_column_def(cols, 'max_rate', '0.0')
|
max_rate = get_column_def(cols, 'max_rate', '0.0')
|
||||||
min_rate = get_column_def(cols, 'min_rate', 'null')
|
min_rate = get_column_def(cols, 'min_rate', 'null')
|
||||||
close_reason = get_column_def(cols, 'close_reason', 'null')
|
sell_reason = get_column_def(cols, 'sell_reason', 'null')
|
||||||
strategy = get_column_def(cols, 'strategy', 'null')
|
strategy = get_column_def(cols, 'strategy', 'null')
|
||||||
|
|
||||||
leverage = get_column_def(cols, 'leverage', '0.0')
|
leverage = get_column_def(cols, 'leverage', '0.0')
|
||||||
borrowed = get_column_def(cols, 'borrowed', '0.0')
|
borrowed = get_column_def(cols, 'borrowed', '0.0')
|
||||||
borrowed_currency = get_column_def(cols, 'borrowed_currency', 'null')
|
borrowed_currency = get_column_def(cols, 'borrowed_currency', 'null')
|
||||||
|
collateral_currency = get_column_def(cols, 'collateral_currency', 'null')
|
||||||
interest_rate = get_column_def(cols, 'interest_rate', '0.0')
|
interest_rate = get_column_def(cols, 'interest_rate', '0.0')
|
||||||
min_stoploss = get_column_def(cols, 'min_stoploss', 'null')
|
liquidation_price = get_column_def(cols, 'liquidation_price', 'null')
|
||||||
is_short = get_column_def(cols, 'is_short', 'False')
|
is_short = get_column_def(cols, 'is_short', 'False')
|
||||||
# If ticker-interval existed use that, else null.
|
# If ticker-interval existed use that, else null.
|
||||||
if has_column(cols, 'ticker_interval'):
|
if has_column(cols, 'ticker_interval'):
|
||||||
@ -87,9 +88,9 @@ def migrate_trades_table(decl_base, inspector, engine, table_back_name: str, col
|
|||||||
stake_amount, amount, amount_requested, open_date, close_date, open_order_id,
|
stake_amount, amount, amount_requested, open_date, close_date, open_order_id,
|
||||||
stop_loss, stop_loss_pct, initial_stop_loss, initial_stop_loss_pct,
|
stop_loss, stop_loss_pct, initial_stop_loss, initial_stop_loss_pct,
|
||||||
stoploss_order_id, stoploss_last_update,
|
stoploss_order_id, stoploss_last_update,
|
||||||
max_rate, min_rate, close_reason, close_order_status, strategy,
|
max_rate, min_rate, sell_reason, close_order_status, strategy,
|
||||||
timeframe, open_trade_value, close_profit_abs,
|
timeframe, open_trade_value, close_profit_abs,
|
||||||
leverage, borrowed, borrowed_currency, interest_rate, min_stoploss, is_short
|
leverage, borrowed, borrowed_currency, collateral_currency, interest_rate, liquidation_price, is_short
|
||||||
)
|
)
|
||||||
select id, lower(exchange),
|
select id, lower(exchange),
|
||||||
case
|
case
|
||||||
@ -109,12 +110,13 @@ def migrate_trades_table(decl_base, inspector, engine, table_back_name: str, col
|
|||||||
{initial_stop_loss} initial_stop_loss,
|
{initial_stop_loss} initial_stop_loss,
|
||||||
{initial_stop_loss_pct} initial_stop_loss_pct,
|
{initial_stop_loss_pct} initial_stop_loss_pct,
|
||||||
{stoploss_order_id} stoploss_order_id, {stoploss_last_update} stoploss_last_update,
|
{stoploss_order_id} stoploss_order_id, {stoploss_last_update} stoploss_last_update,
|
||||||
{max_rate} max_rate, {min_rate} min_rate, {close_reason} close_reason,
|
{max_rate} max_rate, {min_rate} min_rate, {sell_reason} sell_reason,
|
||||||
{close_order_status} close_order_status,
|
{close_order_status} close_order_status,
|
||||||
{strategy} strategy, {timeframe} timeframe,
|
{strategy} strategy, {timeframe} timeframe,
|
||||||
{open_trade_value} open_trade_value, {close_profit_abs} close_profit_abs,
|
{open_trade_value} open_trade_value, {close_profit_abs} close_profit_abs,
|
||||||
{leverage} leverage, {borrowed} borrowed, {borrowed_currency} borrowed_currency,
|
{leverage} leverage, {borrowed} borrowed, {borrowed_currency} borrowed_currency,
|
||||||
{interest_rate} interest_rate, {min_stoploss} min_stoploss, {is_short} is_short
|
{collateral_currency} collateral_currency, {interest_rate} interest_rate,
|
||||||
|
{liquidation_price} liquidation_price, {is_short} is_short
|
||||||
from {table_back_name}
|
from {table_back_name}
|
||||||
"""))
|
"""))
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ class LocalTrade():
|
|||||||
max_rate: float = 0.0
|
max_rate: float = 0.0
|
||||||
# Lowest price reached
|
# Lowest price reached
|
||||||
min_rate: float = 0.0
|
min_rate: float = 0.0
|
||||||
close_reason: str = ''
|
sell_reason: str = ''
|
||||||
close_order_status: str = ''
|
close_order_status: str = ''
|
||||||
strategy: str = ''
|
strategy: str = ''
|
||||||
timeframe: Optional[int] = None
|
timeframe: Optional[int] = None
|
||||||
@ -265,9 +265,10 @@ class LocalTrade():
|
|||||||
# Margin trading properties
|
# Margin trading properties
|
||||||
leverage: Optional[float] = 0.0
|
leverage: Optional[float] = 0.0
|
||||||
borrowed: float = 0.0
|
borrowed: float = 0.0
|
||||||
borrowed_currency: float = None
|
borrowed_currency: str = None
|
||||||
|
collateral_currency: str = None
|
||||||
interest_rate: float = 0.0
|
interest_rate: float = 0.0
|
||||||
min_stoploss: float = None
|
liquidation_price: float = None
|
||||||
is_short: bool = False
|
is_short: bool = False
|
||||||
# End of margin trading properties
|
# End of margin trading properties
|
||||||
|
|
||||||
@ -346,7 +347,7 @@ class LocalTrade():
|
|||||||
'profit_pct': round(self.close_profit * 100, 2) if self.close_profit else None,
|
'profit_pct': round(self.close_profit * 100, 2) if self.close_profit else None,
|
||||||
'profit_abs': self.close_profit_abs,
|
'profit_abs': self.close_profit_abs,
|
||||||
|
|
||||||
'close_reason': self.close_reason,
|
'sell_reason': self.sell_reason,
|
||||||
'close_order_status': self.close_order_status,
|
'close_order_status': self.close_order_status,
|
||||||
'stop_loss_abs': self.stop_loss,
|
'stop_loss_abs': self.stop_loss,
|
||||||
'stop_loss_ratio': self.stop_loss_pct if self.stop_loss_pct else None,
|
'stop_loss_ratio': self.stop_loss_pct if self.stop_loss_pct else None,
|
||||||
@ -367,8 +368,9 @@ class LocalTrade():
|
|||||||
'leverage': self.leverage,
|
'leverage': self.leverage,
|
||||||
'borrowed': self.borrowed,
|
'borrowed': self.borrowed,
|
||||||
'borrowed_currency': self.borrowed_currency,
|
'borrowed_currency': self.borrowed_currency,
|
||||||
|
'collateral_currency': self.collateral_currency,
|
||||||
'interest_rate': self.interest_rate,
|
'interest_rate': self.interest_rate,
|
||||||
'min_stoploss': self.min_stoploss,
|
'liquidation_price': self.liquidation_price,
|
||||||
'leverage': self.leverage,
|
'leverage': self.leverage,
|
||||||
|
|
||||||
'open_order_id': self.open_order_id,
|
'open_order_id': self.open_order_id,
|
||||||
@ -411,8 +413,8 @@ class LocalTrade():
|
|||||||
|
|
||||||
new_loss = float(current_price * (1 - abs(stoploss)))
|
new_loss = float(current_price * (1 - abs(stoploss)))
|
||||||
# TODO: Could maybe move this if into the new stoploss if branch
|
# TODO: Could maybe move this if into the new stoploss if branch
|
||||||
if (self.min_stoploss): # If trading on margin, don't set the stoploss below the liquidation price
|
if (self.liquidation_price): # If trading on margin, don't set the stoploss below the liquidation price
|
||||||
new_loss = min(self.min_stoploss, new_loss)
|
new_loss = min(self.liquidation_price, new_loss)
|
||||||
|
|
||||||
# no stop loss assigned yet
|
# no stop loss assigned yet
|
||||||
if not self.stop_loss:
|
if not self.stop_loss:
|
||||||
@ -465,7 +467,7 @@ class LocalTrade():
|
|||||||
|
|
||||||
logger.info('Updating trade (id=%s) ...', self.id)
|
logger.info('Updating trade (id=%s) ...', self.id)
|
||||||
|
|
||||||
if order_type in ('market', 'limit') and self.isOpeningTrade(order['side']):
|
if order_type in ('market', 'limit') and self.is_opening_trade(order['side']):
|
||||||
# Update open rate and actual amount
|
# Update open rate and actual amount
|
||||||
self.open_rate = float(safe_value_fallback(order, 'average', 'price'))
|
self.open_rate = float(safe_value_fallback(order, 'average', 'price'))
|
||||||
self.amount = float(safe_value_fallback(order, 'filled', 'amount'))
|
self.amount = float(safe_value_fallback(order, 'filled', 'amount'))
|
||||||
@ -474,7 +476,7 @@ class LocalTrade():
|
|||||||
payment = "SELL" if self.is_short else "BUY"
|
payment = "SELL" if self.is_short else "BUY"
|
||||||
logger.info(f'{order_type.upper()}_{payment} order has been fulfilled for {self}.')
|
logger.info(f'{order_type.upper()}_{payment} order has been fulfilled for {self}.')
|
||||||
self.open_order_id = None
|
self.open_order_id = None
|
||||||
elif order_type in ('market', 'limit') and self.isClosingTrade(order['side']):
|
elif order_type in ('market', 'limit') and self.is_closing_trade(order['side']):
|
||||||
if self.is_open:
|
if self.is_open:
|
||||||
payment = "BUY" if self.is_short else "SELL"
|
payment = "BUY" if self.is_short else "SELL"
|
||||||
logger.info(f'{order_type.upper()}_{payment} order has been fulfilled for {self}.')
|
logger.info(f'{order_type.upper()}_{payment} order has been fulfilled for {self}.')
|
||||||
@ -482,7 +484,7 @@ class LocalTrade():
|
|||||||
elif order_type in ('stop_loss_limit', 'stop-loss', 'stop-loss-limit', 'stop'):
|
elif order_type in ('stop_loss_limit', 'stop-loss', 'stop-loss-limit', 'stop'):
|
||||||
self.stoploss_order_id = None
|
self.stoploss_order_id = None
|
||||||
self.close_rate_requested = self.stop_loss
|
self.close_rate_requested = self.stop_loss
|
||||||
self.close_reason = SellType.STOPLOSS_ON_EXCHANGE.value
|
self.sell_reason = SellType.STOPLOSS_ON_EXCHANGE.value
|
||||||
if self.is_open:
|
if self.is_open:
|
||||||
logger.info(f'{order_type.upper()} is hit for {self}.')
|
logger.info(f'{order_type.upper()} is hit for {self}.')
|
||||||
self.close(safe_value_fallback(order, 'average', 'price'))
|
self.close(safe_value_fallback(order, 'average', 'price'))
|
||||||
@ -574,8 +576,8 @@ class LocalTrade():
|
|||||||
|
|
||||||
close_trade = Decimal(self.amount) * Decimal(rate or self.close_rate) # type: ignore
|
close_trade = Decimal(self.amount) * Decimal(rate or self.close_rate) # type: ignore
|
||||||
fees = close_trade * Decimal(fee or self.fee_close)
|
fees = close_trade * Decimal(fee or self.fee_close)
|
||||||
interest = ((self.interest_rate * Decimal(borrowed or self.borrowed)) *
|
#TODO: Interest rate could be hourly instead of daily
|
||||||
(datetime.utcnow() - self.open_date).days) or 0 # Interest/day * num of days
|
interest = ((Decimal(self.interest_rate) * Decimal(self.borrowed)) * Decimal((datetime.utcnow() - self.open_date).days)) or 0 # Interest/day * num of days
|
||||||
if (self.is_short):
|
if (self.is_short):
|
||||||
return float(close_trade + fees + interest)
|
return float(close_trade + fees + interest)
|
||||||
else:
|
else:
|
||||||
@ -670,7 +672,7 @@ class LocalTrade():
|
|||||||
sel_trades = [trade for trade in sel_trades if trade.close_date
|
sel_trades = [trade for trade in sel_trades if trade.close_date
|
||||||
and trade.close_date > close_date]
|
and trade.close_date > close_date]
|
||||||
|
|
||||||
return sel_trades # TODO: What is sel_trades does it mean sell_trades? If so, update this for margin
|
return sel_trades
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def close_bt_trade(trade):
|
def close_bt_trade(trade):
|
||||||
@ -766,7 +768,7 @@ class Trade(_DECL_BASE, LocalTrade):
|
|||||||
max_rate = Column(Float, nullable=True, default=0.0)
|
max_rate = Column(Float, nullable=True, default=0.0)
|
||||||
# Lowest price reached
|
# Lowest price reached
|
||||||
min_rate = Column(Float, nullable=True)
|
min_rate = Column(Float, nullable=True)
|
||||||
close_reason = Column(String(100), nullable=True)
|
sell_reason = Column(String(100), nullable=True) #TODO: Change to close_reason
|
||||||
close_order_status = Column(String(100), nullable=True)
|
close_order_status = Column(String(100), nullable=True)
|
||||||
strategy = Column(String(100), nullable=True)
|
strategy = Column(String(100), nullable=True)
|
||||||
timeframe = Column(Integer, nullable=True)
|
timeframe = Column(Integer, nullable=True)
|
||||||
@ -775,8 +777,9 @@ class Trade(_DECL_BASE, LocalTrade):
|
|||||||
leverage = Column(Float, nullable=True, default=0.0)
|
leverage = Column(Float, nullable=True, default=0.0)
|
||||||
borrowed = Column(Float, nullable=False, default=0.0)
|
borrowed = Column(Float, nullable=False, default=0.0)
|
||||||
borrowed_currency = Column(Float, nullable=True)
|
borrowed_currency = Column(Float, nullable=True)
|
||||||
|
collateral_currency = Column(String(25), nullable=True)
|
||||||
interest_rate = Column(Float, nullable=False, default=0.0)
|
interest_rate = Column(Float, nullable=False, default=0.0)
|
||||||
min_stoploss = Column(Float, nullable=True)
|
liquidation_price = Column(Float, nullable=True)
|
||||||
is_short = Column(Boolean, nullable=False, default=False)
|
is_short = Column(Boolean, nullable=False, default=False)
|
||||||
# End of margin trading properties
|
# End of margin trading properties
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user