46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
from __future__ import annotations
|
|
from fastapi import FastAPI
|
|
from pydantic import BaseModel
|
|
from typing import Dict, Any, Optional
|
|
|
|
from .core import LocalProblem, PlanDelta, SharedVariables, DualVariables
|
|
from .solver import LocalSolver
|
|
from .adapters import NBBOFeedAdapter, BrokerGatewayAdapter
|
|
|
|
app = FastAPI(title="ELAC-Plan API")
|
|
|
|
_solver = LocalSolver()
|
|
_feed = NBBOFeedAdapter()
|
|
_broker = BrokerGatewayAdapter()
|
|
|
|
|
|
class LocalProblemInput(BaseModel):
|
|
id: str
|
|
asset: str
|
|
venue: str
|
|
objective: str
|
|
constraints: Dict[str, Any]
|
|
price_target: float
|
|
tolerance: float
|
|
|
|
|
|
@app.post("/problems")
|
|
def create_problem(p: LocalProblemInput) -> Dict[str, Any]:
|
|
problem = LocalProblem(
|
|
id=p.id,
|
|
asset=p.asset,
|
|
venue=p.venue,
|
|
objective=p.objective,
|
|
constraints=p.constraints,
|
|
price_target=p.price_target,
|
|
tolerance=p.tolerance,
|
|
)
|
|
delta = _solver.solve(problem)
|
|
_broker.publish(delta)
|
|
return {"problem": problem.to_json(), "delta": delta.to_json()}
|
|
|
|
|
|
@app.get("/status")
|
|
def status() -> Dict[str, Any]:
|
|
return {"status": "ELAC-Plan API running"}
|