feat(api): real klines/trades from indexer + auto table creation
- charts.py: serve OHLCV bars & trades from Postgres (klines/trades tables written by indexer), no synthetic data - entities.py: add TradeModel/KlineModel matching indexer schema - main.py: idempotent create_all on startup - config.py: unify default DATABASE_URL with docker-compose/indexer
This commit is contained in:
@@ -118,3 +118,38 @@ class OrderModel(Base):
|
||||
fee = Column(Numeric(precision=36, scale=18), default=Decimal("0"), nullable=False)
|
||||
tx_hash = Column(String(66), nullable=True)
|
||||
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
|
||||
class TradeModel(Base):
|
||||
"""链上真实成交明细 (由 Indexer 确定性投影写入)"""
|
||||
__tablename__ = "trades"
|
||||
|
||||
id = Column(BigInteger().with_variant(Integer, "sqlite"), primary_key=True, autoincrement=True)
|
||||
tx_hash = Column(String(66), nullable=True, index=True)
|
||||
market_address = Column(String(42), nullable=False, index=True)
|
||||
outcome_index = Column(BigInteger, nullable=False)
|
||||
trade_type = Column(String(8), nullable=False) # "MINT" | "REDEEM"
|
||||
price = Column(Numeric(precision=36, scale=18), nullable=False)
|
||||
volume = Column(Numeric(precision=36, scale=18), nullable=False)
|
||||
block_number = Column(BigInteger, nullable=True)
|
||||
ts = Column(BigInteger, nullable=True, index=True)
|
||||
|
||||
__table_args__ = (
|
||||
Index("idx_trades_market_ts", "market_address", "outcome_index", "ts"),
|
||||
)
|
||||
|
||||
class KlineModel(Base):
|
||||
"""秒级 OHLCV K 线 (由 Indexer 按 5 秒窗口确定性聚合写入)"""
|
||||
__tablename__ = "klines"
|
||||
|
||||
market_address = Column(String(42), primary_key=True)
|
||||
outcome_index = Column(BigInteger, primary_key=True)
|
||||
bar_time = Column(BigInteger, primary_key=True)
|
||||
open = Column(Numeric(precision=36, scale=18), nullable=False)
|
||||
high = Column(Numeric(precision=36, scale=18), nullable=False)
|
||||
low = Column(Numeric(precision=36, scale=18), nullable=False)
|
||||
close = Column(Numeric(precision=36, scale=18), nullable=False)
|
||||
volume = Column(Numeric(precision=36, scale=18), nullable=False)
|
||||
|
||||
__table_args__ = (
|
||||
Index("idx_klines_market_time", "market_address", "outcome_index", "bar_time"),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user