移除数据录入模块,持仓数据跟随种子数据加载
This commit is contained in:
+1
-2
@@ -7,7 +7,7 @@ from starlette.middleware.base import BaseHTTPMiddleware
|
||||
from app.database import engine, Base, SessionLocal
|
||||
from app.models import User
|
||||
from app.seed import seed
|
||||
from app.routers import contracts, analysis, data_input, admin, auth
|
||||
from app.routers import contracts, analysis, admin, auth
|
||||
|
||||
TEMPLATES_DIR = Path(__file__).parent / "templates"
|
||||
|
||||
@@ -56,7 +56,6 @@ app.add_middleware(AuthMiddleware)
|
||||
app.include_router(auth.router)
|
||||
app.include_router(contracts.router)
|
||||
app.include_router(analysis.router)
|
||||
app.include_router(data_input.router)
|
||||
app.include_router(admin.router)
|
||||
|
||||
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
from datetime import date
|
||||
from fastapi import APIRouter, Depends, Form, Request
|
||||
from fastapi.responses import HTMLResponse, RedirectResponse
|
||||
from sqlalchemy.orm import Session
|
||||
from app.database import get_db
|
||||
from app.models import PositionSnapshot
|
||||
|
||||
router = APIRouter(prefix="/input", tags=["input"])
|
||||
|
||||
INSTITUTIONS = ["中信期货", "高盛期货", "国泰君安期货", "华泰期货", "东证期货", "银河期货"]
|
||||
|
||||
|
||||
@router.get("/", response_class=HTMLResponse)
|
||||
def input_page(request: Request):
|
||||
template = request.app.state.templates.get_template("input.html")
|
||||
return HTMLResponse(
|
||||
template.render(request=request, active_nav="input", institutions=INSTITUTIONS)
|
||||
)
|
||||
|
||||
|
||||
@router.post("/")
|
||||
def submit_position(
|
||||
request: Request,
|
||||
institution: str = Form(...),
|
||||
direction: str = Form(...),
|
||||
date_str: str = Form(...),
|
||||
position: int = Form(...),
|
||||
avg_cost: float = Form(...),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
d = date.fromisoformat(date_str)
|
||||
|
||||
prev = (
|
||||
db.query(PositionSnapshot)
|
||||
.filter(
|
||||
PositionSnapshot.institution == institution,
|
||||
PositionSnapshot.direction == direction,
|
||||
PositionSnapshot.date < d,
|
||||
)
|
||||
.order_by(PositionSnapshot.date.desc())
|
||||
.first()
|
||||
)
|
||||
delta = position - prev.position if prev else 0
|
||||
|
||||
existing = (
|
||||
db.query(PositionSnapshot)
|
||||
.filter(
|
||||
PositionSnapshot.institution == institution,
|
||||
PositionSnapshot.direction == direction,
|
||||
PositionSnapshot.date == d,
|
||||
)
|
||||
.first()
|
||||
)
|
||||
|
||||
if existing:
|
||||
existing.position = position
|
||||
existing.delta = delta
|
||||
existing.avg_cost = avg_cost
|
||||
else:
|
||||
snap = PositionSnapshot(
|
||||
institution=institution,
|
||||
direction=direction,
|
||||
date=d,
|
||||
position=position,
|
||||
delta=delta,
|
||||
avg_cost=avg_cost,
|
||||
)
|
||||
db.add(snap)
|
||||
|
||||
db.commit()
|
||||
return RedirectResponse("/analysis", status_code=303)
|
||||
@@ -198,9 +198,6 @@
|
||||
<a href="/analysis/" class="{% if active_nav == 'analysis' %}active{% endif %}">
|
||||
<span class="icon">⚔️</span> 博弈分析
|
||||
</a>
|
||||
<a href="/input/" class="{% if active_nav == 'input' %}active{% endif %}">
|
||||
<span class="icon">📝</span> 数据录入
|
||||
</a>
|
||||
<a href="/admin/" class="{% if active_nav == 'admin' %}active{% endif %}">
|
||||
<span class="icon">⚙️</span> 系统管理
|
||||
</a>
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}数据录入{% endblock %}
|
||||
{% block heading %}数据录入{% endblock %}
|
||||
{% block breadcrumb %}机构持仓录入{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="form-card">
|
||||
<div class="section-title">持仓快照</div>
|
||||
<form method="post" action="/input">
|
||||
<div class="form-group">
|
||||
<label>机构</label>
|
||||
<select name="institution" required>
|
||||
{% for inst in institutions %}
|
||||
<option value="{{ inst }}">{{ inst }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>方向</label>
|
||||
<select name="direction" required>
|
||||
<option value="long">多单</option>
|
||||
<option value="short">空单</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>日期</label>
|
||||
<input type="date" name="date_str" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>持仓量(手)</label>
|
||||
<input type="number" name="position" required placeholder="例: 193030">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>持仓均价</label>
|
||||
<input type="number" name="avg_cost" step="0.01" required placeholder="例: 995.26">
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">提交</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user