# Generated by Django 5.2.9 on 2026-01-01 14:45

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("account", "0007_portfoliomodel_base_currency_positionmodel_category_and_more"),
    ]

    operations = [
        migrations.CreateModel(
            name="StopLossConfigModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "stop_loss_type",
                    models.CharField(
                        choices=[
                            ("fixed", "固定止损"),
                            ("trailing", "移动止损"),
                            ("time_based", "时间止损"),
                        ],
                        default="fixed",
                        max_length=20,
                        verbose_name="止损类型",
                    ),
                ),
                (
                    "stop_loss_pct",
                    models.FloatField(help_text="如 -0.10 表示 -10%", verbose_name="止损百分比"),
                ),
                (
                    "trailing_stop_pct",
                    models.FloatField(
                        blank=True,
                        help_text="移动止损时使用，如 -0.10",
                        null=True,
                        verbose_name="移动止损百分比",
                    ),
                ),
                (
                    "max_holding_days",
                    models.IntegerField(
                        blank=True,
                        help_text="时间止损时使用",
                        null=True,
                        verbose_name="最大持仓天数",
                    ),
                ),
                (
                    "highest_price",
                    models.DecimalField(
                        blank=True,
                        decimal_places=4,
                        max_digits=20,
                        null=True,
                        verbose_name="持仓期间最高价",
                    ),
                ),
                (
                    "highest_price_updated_at",
                    models.DateTimeField(blank=True, null=True, verbose_name="最高价更新时间"),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("active", "激活中"),
                            ("triggered", "已触发"),
                            ("cancelled", "已取消"),
                            ("expired", "已过期"),
                        ],
                        default="active",
                        max_length=20,
                        verbose_name="状态",
                    ),
                ),
                ("activated_at", models.DateTimeField(auto_now_add=True, verbose_name="激活时间")),
                (
                    "triggered_at",
                    models.DateTimeField(blank=True, null=True, verbose_name="触发时间"),
                ),
                ("notes", models.TextField(blank=True, verbose_name="备注")),
                ("created_at", models.DateTimeField(auto_now_add=True, verbose_name="创建时间")),
                ("updated_at", models.DateTimeField(auto_now=True, verbose_name="更新时间")),
                (
                    "position",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="stop_loss_config",
                        to="account.positionmodel",
                        verbose_name="关联持仓",
                    ),
                ),
            ],
            options={
                "verbose_name": "止损配置",
                "verbose_name_plural": "止损配置",
                "db_table": "stop_loss_config",
                "indexes": [
                    models.Index(fields=["status"], name="stop_loss_c_status_10828f_idx"),
                    models.Index(
                        fields=["position", "status"], name="stop_loss_c_positio_121109_idx"
                    ),
                ],
            },
        ),
        migrations.CreateModel(
            name="StopLossTriggerModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "trigger_type",
                    models.CharField(
                        choices=[
                            ("fixed", "固定止损"),
                            ("trailing", "移动止损"),
                            ("time_based", "时间止损"),
                        ],
                        max_length=20,
                        verbose_name="触发类型",
                    ),
                ),
                (
                    "trigger_price",
                    models.DecimalField(decimal_places=4, max_digits=20, verbose_name="触发价格"),
                ),
                ("trigger_time", models.DateTimeField(verbose_name="触发时间")),
                ("trigger_reason", models.TextField(verbose_name="触发原因")),
                (
                    "pnl",
                    models.DecimalField(decimal_places=2, max_digits=20, verbose_name="盈亏金额"),
                ),
                ("pnl_pct", models.FloatField(verbose_name="盈亏百分比")),
                ("notes", models.TextField(blank=True, verbose_name="备注")),
                ("created_at", models.DateTimeField(auto_now_add=True, verbose_name="创建时间")),
                (
                    "position",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="stop_loss_triggers",
                        to="account.positionmodel",
                        verbose_name="关联持仓",
                    ),
                ),
            ],
            options={
                "verbose_name": "止损触发记录",
                "verbose_name_plural": "止损触发记录",
                "db_table": "stop_loss_trigger",
                "ordering": ["-trigger_time"],
                "indexes": [
                    models.Index(
                        fields=["position", "-trigger_time"], name="stop_loss_t_positio_57dd54_idx"
                    ),
                    models.Index(fields=["trigger_type"], name="stop_loss_t_trigger_27462a_idx"),
                ],
            },
        ),
        migrations.CreateModel(
            name="TakeProfitConfigModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "take_profit_pct",
                    models.FloatField(help_text="如 0.20 表示 +20%", verbose_name="止盈百分比"),
                ),
                (
                    "partial_profit_levels",
                    models.JSONField(
                        blank=True,
                        help_text="如 [0.10, 0.20, 0.30] 表示在10%, 20%, 30%时各止盈一部分",
                        null=True,
                        verbose_name="分批止盈点位",
                    ),
                ),
                ("is_active", models.BooleanField(default=True, verbose_name="是否激活")),
                ("notes", models.TextField(blank=True, verbose_name="备注")),
                ("created_at", models.DateTimeField(auto_now_add=True, verbose_name="创建时间")),
                ("updated_at", models.DateTimeField(auto_now=True, verbose_name="更新时间")),
                (
                    "position",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="take_profit_config",
                        to="account.positionmodel",
                        verbose_name="关联持仓",
                    ),
                ),
            ],
            options={
                "verbose_name": "止盈配置",
                "verbose_name_plural": "止盈配置",
                "db_table": "take_profit_config",
                "indexes": [
                    models.Index(fields=["is_active"], name="take_profit_is_acti_49ae34_idx"),
                    models.Index(
                        fields=["position", "is_active"], name="take_profit_positio_e596e1_idx"
                    ),
                ],
            },
        ),
    ]
