Add exchange trading endpoints:
- POST /api/exchange: Create exchange trade
- Validates slot, price staleness, EUR amount limits
- Calculates sats from EUR and agreed price
- Direction-specific premium (buy=+5%, sell=-5%)
- GET /api/trades: List user's exchanges
- POST /api/trades/{id}/cancel: Cancel user's exchange
Add schemas:
- ExchangeRequest, ExchangeResponse
- ExchangeUserContact, AdminExchangeResponse (for Phase 2.4)
- PaginatedExchanges, PaginatedAdminExchanges
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
"""FastAPI application entry point."""
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from database import Base, engine
|
|
from routes import audit as audit_routes
|
|
from routes import auth as auth_routes
|
|
from routes import availability as availability_routes
|
|
from routes import booking as booking_routes
|
|
from routes import exchange as exchange_routes
|
|
from routes import invites as invites_routes
|
|
from routes import meta as meta_routes
|
|
from routes import profile as profile_routes
|
|
from validate_constants import validate_shared_constants
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
"""Create database tables on startup and validate constants."""
|
|
# Validate shared constants match backend definitions
|
|
validate_shared_constants()
|
|
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
yield
|
|
|
|
|
|
app = FastAPI(lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["http://localhost:3000"],
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
allow_credentials=True,
|
|
)
|
|
|
|
# Include routers - modules with single router
|
|
app.include_router(auth_routes.router)
|
|
app.include_router(audit_routes.router)
|
|
app.include_router(profile_routes.router)
|
|
app.include_router(availability_routes.router)
|
|
app.include_router(meta_routes.router)
|
|
|
|
# Include routers - modules with multiple routers
|
|
for r in invites_routes.routers:
|
|
app.include_router(r)
|
|
for r in booking_routes.routers:
|
|
app.include_router(r)
|
|
for r in exchange_routes.routers:
|
|
app.include_router(r)
|