updated mkdocs and leverage docs
Added tests for set_liquidation_price and set_stop_loss updated params in interestmode enum
This commit is contained in:
@@ -149,17 +149,16 @@ def migrate_orders_table(decl_base, inspector, engine, table_back_name: str, col
|
||||
# let SQLAlchemy create the schema as required
|
||||
decl_base.metadata.create_all(engine)
|
||||
leverage = get_column_def(cols, 'leverage', '1.0')
|
||||
is_short = get_column_def(cols, 'is_short', 'False')
|
||||
# TODO-mg: Should liquidation price go in here?
|
||||
# is_short = get_column_def(cols, 'is_short', 'False')
|
||||
|
||||
with engine.begin() as connection:
|
||||
connection.execute(text(f"""
|
||||
insert into orders ( id, ft_trade_id, ft_order_side, ft_pair, ft_is_open, order_id,
|
||||
status, symbol, order_type, side, price, amount, filled, average, remaining, cost,
|
||||
order_date, order_filled_date, order_update_date, leverage, is_short)
|
||||
order_date, order_filled_date, order_update_date, leverage)
|
||||
select id, ft_trade_id, ft_order_side, ft_pair, ft_is_open, order_id,
|
||||
status, symbol, order_type, side, price, amount, filled, null average, remaining, cost,
|
||||
order_date, order_filled_date, order_update_date,
|
||||
{leverage} leverage, {is_short} is_short
|
||||
order_date, order_filled_date, order_update_date, {leverage} leverage
|
||||
from {table_back_name}
|
||||
"""))
|
||||
|
||||
|
@@ -133,7 +133,6 @@ class Order(_DECL_BASE):
|
||||
order_update_date = Column(DateTime, nullable=True)
|
||||
|
||||
leverage = Column(Float, nullable=True, default=1.0)
|
||||
is_short = Column(Boolean, nullable=True, default=False)
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
@@ -159,7 +158,7 @@ class Order(_DECL_BASE):
|
||||
self.remaining = order.get('remaining', self.remaining)
|
||||
self.cost = order.get('cost', self.cost)
|
||||
self.leverage = order.get('leverage', self.leverage)
|
||||
# TODO-mg: is_short?
|
||||
|
||||
if 'timestamp' in order and order['timestamp'] is not None:
|
||||
self.order_date = datetime.fromtimestamp(order['timestamp'] / 1000, tz=timezone.utc)
|
||||
|
||||
@@ -301,44 +300,42 @@ class LocalTrade():
|
||||
def __init__(self, **kwargs):
|
||||
for key in kwargs:
|
||||
setattr(self, key, kwargs[key])
|
||||
self.set_liquidation_price(self.liquidation_price)
|
||||
if self.liquidation_price:
|
||||
self.set_liquidation_price(self.liquidation_price)
|
||||
self.recalc_open_trade_value()
|
||||
|
||||
def set_stop_loss_helper(self, stop_loss: Optional[float], liquidation_price: Optional[float]):
|
||||
"""Helper function for set_liquidation_price and set_stop_loss"""
|
||||
# Stoploss would be better as a computed variable,
|
||||
# but that messes up the database so it might not be possible
|
||||
|
||||
if liquidation_price is not None:
|
||||
if stop_loss is not None:
|
||||
if self.is_short:
|
||||
self.stop_loss = min(stop_loss, liquidation_price)
|
||||
else:
|
||||
self.stop_loss = max(stop_loss, liquidation_price)
|
||||
else:
|
||||
self.stop_loss = liquidation_price
|
||||
self.initial_stop_loss = liquidation_price
|
||||
self.liquidation_price = liquidation_price
|
||||
else:
|
||||
# programmming error check: 1 of liqudication_price or stop_loss must be set
|
||||
assert stop_loss is not None
|
||||
if not self.stop_loss:
|
||||
self.initial_stop_loss = stop_loss
|
||||
self.stop_loss = stop_loss
|
||||
|
||||
def set_stop_loss(self, stop_loss: float):
|
||||
"""
|
||||
Method you should use to set self.stop_loss.
|
||||
Assures stop_loss is not passed the liquidation price
|
||||
"""
|
||||
self.set_stop_loss_helper(stop_loss=stop_loss, liquidation_price=self.liquidation_price)
|
||||
if self.liquidation_price is not None:
|
||||
if self.is_short:
|
||||
sl = min(stop_loss, self.liquidation_price)
|
||||
else:
|
||||
sl = max(stop_loss, self.liquidation_price)
|
||||
else:
|
||||
sl = stop_loss
|
||||
|
||||
if not self.stop_loss:
|
||||
self.initial_stop_loss = sl
|
||||
self.stop_loss = sl
|
||||
|
||||
def set_liquidation_price(self, liquidation_price: float):
|
||||
"""
|
||||
Method you should use to set self.liquidation price.
|
||||
Assures stop_loss is not passed the liquidation price
|
||||
"""
|
||||
self.set_stop_loss_helper(stop_loss=self.stop_loss, liquidation_price=liquidation_price)
|
||||
if self.stop_loss is not None:
|
||||
if self.is_short:
|
||||
self.stop_loss = min(self.stop_loss, liquidation_price)
|
||||
else:
|
||||
self.stop_loss = max(self.stop_loss, liquidation_price)
|
||||
else:
|
||||
self.initial_stop_loss = liquidation_price
|
||||
self.stop_loss = liquidation_price
|
||||
|
||||
self.liquidation_price = liquidation_price
|
||||
|
||||
def __repr__(self):
|
||||
open_since = self.open_date.strftime(DATETIME_PRINT_FORMAT) if self.is_open else 'closed'
|
||||
|
Reference in New Issue
Block a user