{% extends "base.html" %} {% block title %}交易记录{% endblock %} {% block heading %}交易记录{% endblock %} {% block breadcrumb %}开平仓记录{% endblock %} {% block content %} {% set view = request.query_params.get('view', '') %} {% set product_tab = request.query_params.get('tab', '全部') %} {% set product_codes = product_contracts.keys()|list %} {% set grouped_open = {} %} {% for t in open_trades %} {% set _ = grouped_open.setdefault(t.product_code, []).append(t) %} {% endfor %}
📋 持仓 📊 已平仓
{% if view != 'closed' %}
{# ── 新建开仓 ── #}
新建开仓
{# ── 持仓列表 ── #}
持仓中 · {{ open_trades|length }} 笔
全部 {% for pc in product_codes %} {% set count = grouped_open.get(pc, [])|length %} {{ pc }}{% if count %} · {{ count }}{% endif %} {% endfor %}
{% if open_trades %} {% for pc in product_codes %} {% if product_tab == '全部' or product_tab == pc %} {% set trades = grouped_open.get(pc, []) %} {% if trades %}
{% if product_tab == '全部' %}
{{ pc }} · {{ trades|length }} 笔
{% endif %} {% for t in trades %} {% endfor %}
合约方向开仓日期开仓价手续费操作
{{ t.contract_code.replace(t.product_code, '', 1) }} {% if t.direction == 'short' %} {% else %} {% endif %} {{ t.open_date }} {{ weekdays[t.open_date.weekday()] }} {{ t.open_price }} {{ t.open_fee or 0 }}
{% endif %} {% endif %} {% endfor %} {% else %}
暂无持仓
{% endif %} {# ── 平仓弹窗 ── #}
{% else %}
{# ═══════════════ 已平仓 ═══════════════ #} {% if closed_trades %}
已平仓 · {{ closed_trades|length }} 笔
{% for t in closed_trades %} {% endfor %}
品种合约方向开仓平仓持仓开仓价平仓价开仓费平仓费盈亏操作
{{ t.product_code }} {{ t.contract_code.replace(t.product_code, '', 1) }} {% if t.direction == 'short' %} {% else %} {% endif %} {{ t.open_date }} {{ weekdays[t.open_date.weekday()] }} {{ t.close_date }} {{ weekdays[t.close_date.weekday()] }} {{ (t.close_date - t.open_date).days }}天 {{ t.open_price }} {{ t.close_price }} {{ t.open_fee or 0 }} {{ t.close_fee or 0 }} {% set p = t.pnl %} {% if p is not none %} {% if p > 0 %}+{% endif %}{{ p }} {% endif %}
{% set ns = namespace(total_pnl=0, total_open_fee=0, total_close_fee=0) %} {% for t in closed_trades %} {% set ns.total_pnl = ns.total_pnl + (t.pnl or 0) %} {% set ns.total_open_fee = ns.total_open_fee + (t.open_fee or 0) %} {% set ns.total_close_fee = ns.total_close_fee + (t.close_fee or 0) %} {% endfor %}
盈亏合计 {% if ns.total_pnl > 0 %}+{% endif %}{{ '%.2f'|format(ns.total_pnl) }} | 开仓手续费 {{ '%.2f'|format(ns.total_open_fee) }} | 平仓手续费 {{ '%.2f'|format(ns.total_close_fee) }} | 手续费合计 {{ '%.2f'|format(ns.total_open_fee + ns.total_close_fee) }}
{% else %}
暂无已平仓记录
{% endif %}
{% endif %} {% if view != 'closed' %} {% endif %} {% endblock %}