@@ -59,6 +59,20 @@ def contract_index(request: Request, db: Session = Depends(get_db)):
|
|||||||
if bar.contract not in contract_bars:
|
if bar.contract not in contract_bars:
|
||||||
contract_bars[bar.contract] = bar
|
contract_bars[bar.contract] = bar
|
||||||
|
|
||||||
|
# Next-day amplitude: mean of latest 5 diffs per contract
|
||||||
|
contract_next_amp = {}
|
||||||
|
for code in all_codes:
|
||||||
|
diffs = [
|
||||||
|
r[0] for r in
|
||||||
|
db.query(DailyBar.high - DailyBar.low)
|
||||||
|
.filter(DailyBar.contract == code)
|
||||||
|
.order_by(DailyBar.date.desc())
|
||||||
|
.limit(5)
|
||||||
|
.all()
|
||||||
|
]
|
||||||
|
if len(diffs) >= 5:
|
||||||
|
contract_next_amp[code] = round(sum(diffs) / 5)
|
||||||
|
|
||||||
template = request.app.state.templates.get_template("index.html")
|
template = request.app.state.templates.get_template("index.html")
|
||||||
return HTMLResponse(
|
return HTMLResponse(
|
||||||
template.render(
|
template.render(
|
||||||
@@ -66,6 +80,7 @@ def contract_index(request: Request, db: Session = Depends(get_db)):
|
|||||||
active_nav="contracts",
|
active_nav="contracts",
|
||||||
product_groups=product_groups,
|
product_groups=product_groups,
|
||||||
contract_bars=contract_bars,
|
contract_bars=contract_bars,
|
||||||
|
contract_next_amp=contract_next_amp,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="product-body">
|
<div class="product-body">
|
||||||
<table>
|
<table>
|
||||||
<tr><th>合约</th><th>日期</th><th>开盘</th><th>收盘</th><th>最高</th><th>最低</th><th>振幅</th><th>操作</th></tr>
|
<tr><th>合约</th><th>日期</th><th>开盘</th><th>收盘</th><th>最高</th><th>最低</th><th>振幅</th><th>次日振幅</th><th>操作</th></tr>
|
||||||
{% for c in pg.contracts %}
|
{% for c in pg.contracts %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><strong>{{ c }}</strong></td>
|
<td><strong>{{ c }}</strong></td>
|
||||||
@@ -34,8 +34,15 @@
|
|||||||
<span class="na">—</span>
|
<span class="na">—</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
{% if c in contract_next_amp %}
|
||||||
|
<span class="badge badge-warn">{{ contract_next_amp[c] }}</span>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td colspan="6" class="na">暂无数据</td>
|
<span class="na">—</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
{% else %}
|
||||||
|
<td colspan="7" class="na">暂无数据</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td><a href="/contracts/{{ c }}" style="color:var(--accent);text-decoration:none;">详情 →</a></td>
|
<td><a href="/contracts/{{ c }}" style="color:var(--accent);text-decoration:none;">详情 →</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user