Add new order columns, ft_amount and ft_price
This commit is contained in:
parent
550ab2b8e8
commit
fd694f14c2
@ -720,7 +720,7 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
time_in_force=time_in_force,
|
time_in_force=time_in_force,
|
||||||
leverage=leverage
|
leverage=leverage
|
||||||
)
|
)
|
||||||
order_obj = Order.parse_from_ccxt_object(order, pair, side)
|
order_obj = Order.parse_from_ccxt_object(order, pair, side, amount, enter_limit_requested)
|
||||||
order_id = order['id']
|
order_id = order['id']
|
||||||
order_status = order.get('status')
|
order_status = order.get('status')
|
||||||
logger.info(f"Order #{order_id} was created for {pair} and status is {order_status}.")
|
logger.info(f"Order #{order_id} was created for {pair} and status is {order_status}.")
|
||||||
@ -1094,7 +1094,8 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
leverage=trade.leverage
|
leverage=trade.leverage
|
||||||
)
|
)
|
||||||
|
|
||||||
order_obj = Order.parse_from_ccxt_object(stoploss_order, trade.pair, 'stoploss')
|
order_obj = Order.parse_from_ccxt_object(stoploss_order, trade.pair, 'stoploss',
|
||||||
|
trade.amount, stop_price)
|
||||||
trade.orders.append(order_obj)
|
trade.orders.append(order_obj)
|
||||||
trade.stoploss_order_id = str(stoploss_order['id'])
|
trade.stoploss_order_id = str(stoploss_order['id'])
|
||||||
trade.stoploss_last_update = datetime.now(timezone.utc)
|
trade.stoploss_last_update = datetime.now(timezone.utc)
|
||||||
@ -1595,7 +1596,7 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
self.handle_insufficient_funds(trade)
|
self.handle_insufficient_funds(trade)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
order_obj = Order.parse_from_ccxt_object(order, trade.pair, trade.exit_side)
|
order_obj = Order.parse_from_ccxt_object(order, trade.pair, trade.exit_side, amount, limit)
|
||||||
trade.orders.append(order_obj)
|
trade.orders.append(order_obj)
|
||||||
|
|
||||||
trade.open_order_id = order['id']
|
trade.open_order_id = order['id']
|
||||||
|
@ -214,17 +214,22 @@ def migrate_orders_table(engine, table_back_name: str, cols_order: List):
|
|||||||
average = get_column_def(cols_order, 'average', 'null')
|
average = get_column_def(cols_order, 'average', 'null')
|
||||||
stop_price = get_column_def(cols_order, 'stop_price', 'null')
|
stop_price = get_column_def(cols_order, 'stop_price', 'null')
|
||||||
funding_fee = get_column_def(cols_order, 'funding_fee', '0.0')
|
funding_fee = get_column_def(cols_order, 'funding_fee', '0.0')
|
||||||
|
ft_amount = get_column_def(cols_order, 'ft_amount', 'coalesce(amount, 0.0)')
|
||||||
|
ft_price = get_column_def(cols_order, 'ft_price', 'coalesce(price, 0.0)')
|
||||||
|
|
||||||
# sqlite does not support literals for booleans
|
# sqlite does not support literals for booleans
|
||||||
with engine.begin() as connection:
|
with engine.begin() as connection:
|
||||||
connection.execute(text(f"""
|
connection.execute(text(f"""
|
||||||
insert into orders (id, ft_trade_id, ft_order_side, ft_pair, ft_is_open, order_id,
|
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,
|
status, symbol, order_type, side, price, amount, filled, average, remaining, cost,
|
||||||
stop_price, order_date, order_filled_date, order_update_date, ft_fee_base, funding_fee)
|
stop_price, order_date, order_filled_date, order_update_date, ft_fee_base, funding_fee,
|
||||||
|
ft_amount, ft_price
|
||||||
|
)
|
||||||
select id, ft_trade_id, ft_order_side, ft_pair, ft_is_open, order_id,
|
select id, ft_trade_id, ft_order_side, ft_pair, ft_is_open, order_id,
|
||||||
status, symbol, order_type, side, price, amount, filled, {average} average, remaining,
|
status, symbol, order_type, side, price, amount, filled, {average} average, remaining,
|
||||||
cost, {stop_price} stop_price, order_date, order_filled_date,
|
cost, {stop_price} stop_price, order_date, order_filled_date,
|
||||||
order_update_date, {ft_fee_base} ft_fee_base, {funding_fee} funding_fee
|
order_update_date, {ft_fee_base} ft_fee_base, {funding_fee} funding_fee,
|
||||||
|
{ft_amount} ft_amount, {ft_price} ft_price
|
||||||
from {table_back_name}
|
from {table_back_name}
|
||||||
"""))
|
"""))
|
||||||
|
|
||||||
@ -311,8 +316,8 @@ def check_migrate(engine, decl_base, previous_tables) -> None:
|
|||||||
# if ('orders' not in previous_tables
|
# if ('orders' not in previous_tables
|
||||||
# or not has_column(cols_orders, 'funding_fee')):
|
# or not has_column(cols_orders, 'funding_fee')):
|
||||||
migrating = False
|
migrating = False
|
||||||
# if not has_column(cols_orders, 'funding_fee'):
|
# if not has_column(cols_trades, 'max_stake_amount'):
|
||||||
if not has_column(cols_trades, 'max_stake_amount'):
|
if not has_column(cols_orders, 'ft_price'):
|
||||||
migrating = True
|
migrating = True
|
||||||
logger.info(f"Running database migration for trades - "
|
logger.info(f"Running database migration for trades - "
|
||||||
f"backup: {table_back_name}, {order_table_bak_name}")
|
f"backup: {table_back_name}, {order_table_bak_name}")
|
||||||
|
@ -49,6 +49,8 @@ class Order(_DECL_BASE):
|
|||||||
ft_order_side: str = Column(String(25), nullable=False)
|
ft_order_side: str = Column(String(25), nullable=False)
|
||||||
ft_pair: str = Column(String(25), nullable=False)
|
ft_pair: str = Column(String(25), nullable=False)
|
||||||
ft_is_open = Column(Boolean, nullable=False, default=True, index=True)
|
ft_is_open = Column(Boolean, nullable=False, default=True, index=True)
|
||||||
|
ft_amount = Column(Float, nullable=False)
|
||||||
|
ft_price = Column(Float, nullable=False)
|
||||||
|
|
||||||
order_id: str = Column(String(255), nullable=False, index=True)
|
order_id: str = Column(String(255), nullable=False, index=True)
|
||||||
status = Column(String(255), nullable=True)
|
status = Column(String(255), nullable=True)
|
||||||
@ -227,11 +229,20 @@ class Order(_DECL_BASE):
|
|||||||
logger.warning(f"Did not find order for {order}.")
|
logger.warning(f"Did not find order for {order}.")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_from_ccxt_object(order: Dict[str, Any], pair: str, side: str) -> 'Order':
|
def parse_from_ccxt_object(
|
||||||
|
order: Dict[str, Any], pair: str, side: str,
|
||||||
|
amount: Optional[float] = None, price: Optional[float] = None) -> 'Order':
|
||||||
"""
|
"""
|
||||||
Parse an order from a ccxt object and return a new order Object.
|
Parse an order from a ccxt object and return a new order Object.
|
||||||
|
Optional support for overriding amount and price is only used for test simplification.
|
||||||
"""
|
"""
|
||||||
o = Order(order_id=str(order['id']), ft_order_side=side, ft_pair=pair)
|
o = Order(
|
||||||
|
order_id=str(order['id']),
|
||||||
|
ft_order_side=side,
|
||||||
|
ft_pair=pair,
|
||||||
|
ft_amount=amount if amount else order['amount'],
|
||||||
|
ft_price=price if price else order['price'],
|
||||||
|
)
|
||||||
|
|
||||||
o.update_from_ccxt_object(order)
|
o.update_from_ccxt_object(order)
|
||||||
return o
|
return o
|
||||||
|
Loading…
Reference in New Issue
Block a user