feat: Add precision_mode_price column

This commit is contained in:
Matthias 2024-08-13 09:09:12 +02:00
parent 6fc2a604b4
commit f8de46cea9
2 changed files with 14 additions and 7 deletions

View File

@ -147,6 +147,9 @@ def migrate_trades_and_orders_table(
price_precision = get_column_def(cols, "price_precision", "null")
precision_mode = get_column_def(cols, "precision_mode", "null")
contract_size = get_column_def(cols, "contract_size", "null")
precision_mode_price = get_column_def(
cols, "precision_mode_price", get_column_def(cols, "precision_mode", "null")
)
# Schema migration necessary
with engine.begin() as connection:
@ -177,7 +180,7 @@ def migrate_trades_and_orders_table(
timeframe, open_trade_value, close_profit_abs,
trading_mode, leverage, liquidation_price, is_short,
interest_rate, funding_fees, funding_fee_running, realized_profit,
amount_precision, price_precision, precision_mode, contract_size,
amount_precision, price_precision, precision_mode, precision_mode_price, contract_size,
max_stake_amount
)
select id, lower(exchange), pair, {base_currency} base_currency,
@ -207,8 +210,8 @@ def migrate_trades_and_orders_table(
{funding_fees} funding_fees, {funding_fee_running} funding_fee_running,
{realized_profit} realized_profit,
{amount_precision} amount_precision, {price_precision} price_precision,
{precision_mode} precision_mode, {contract_size} contract_size,
{max_stake_amount} max_stake_amount
{precision_mode} precision_mode, {precision_mode_price} precision_mode_price,
{contract_size} contract_size, {max_stake_amount} max_stake_amount
from {trade_back_name}
"""
)
@ -348,8 +351,8 @@ def check_migrate(engine, decl_base, previous_tables) -> None:
# if ('orders' not in previous_tables
# or not has_column(cols_orders, 'funding_fee')):
migrating = False
# if not has_column(cols_trades, 'funding_fee_running'):
if not has_column(cols_orders, "ft_order_tag"):
if not has_column(cols_trades, "precision_mode_price"):
# if not has_column(cols_orders, "ft_order_tag"):
migrating = True
logger.info(
f"Running database migration for trades - "

View File

@ -433,6 +433,7 @@ class LocalTrade:
amount_precision: Optional[float] = None
price_precision: Optional[float] = None
precision_mode: Optional[int] = None
precision_mode_price: Optional[int] = None
contract_size: Optional[float] = None
# Leverage trading properties
@ -730,6 +731,7 @@ class LocalTrade:
"amount_precision": self.amount_precision,
"price_precision": self.price_precision,
"precision_mode": self.precision_mode,
"precision_mode_price": self.precision_mode_price,
"contract_size": self.contract_size,
"has_open_orders": self.has_open_orders,
"orders": orders_json,
@ -810,7 +812,7 @@ class LocalTrade:
stop_loss_norm = price_to_precision(
new_loss,
self.price_precision,
self.precision_mode,
self.precision_mode_price,
rounding_mode=ROUND_DOWN if self.is_short else ROUND_UP,
)
# no stop loss assigned yet
@ -819,7 +821,7 @@ class LocalTrade:
self.initial_stop_loss = price_to_precision(
stop_loss_norm,
self.price_precision,
self.precision_mode,
self.precision_mode_price,
rounding_mode=ROUND_DOWN if self.is_short else ROUND_UP,
)
self.initial_stop_loss_pct = -1 * abs(stoploss)
@ -1562,6 +1564,7 @@ class LocalTrade:
amount_precision=data.get("amount_precision", None),
price_precision=data.get("price_precision", None),
precision_mode=data.get("precision_mode", None),
precision_mode_price=data.get("precision_mode_price", data.get("precision_mode", None)),
contract_size=data.get("contract_size", None),
)
for order in data["orders"]:
@ -1695,6 +1698,7 @@ class Trade(ModelBase, LocalTrade):
)
price_precision: Mapped[Optional[float]] = mapped_column(Float(), nullable=True) # type: ignore
precision_mode: Mapped[Optional[int]] = mapped_column(Integer, nullable=True) # type: ignore
precision_mode_price: Mapped[Optional[int]] = mapped_column(Integer, nullable=True) # type: ignore
contract_size: Mapped[Optional[float]] = mapped_column(Float(), nullable=True) # type: ignore
# Leverage trading properties