Files
randebu/src/backend/app/db/models.py
shokollm 3806af3e23 feat(backend): Implement AVE Cloud integration for Data and Trading APIs
- Add tier field to User model for plan detection (free/normal/pro)
- Create AVE Cloud API client with all Data API endpoints:
  - Token search (GET /v2/tokens)
  - Batch prices (POST /v2/tokens/price)
  - Token details (GET /v2/tokens/{id})
  - Kline data (GET /v2/klines/token/{id})
  - Trending tokens (GET /v2/tokens/trending)
  - Token risk (GET /v2/contracts/{id})
- Add Trading API endpoints:
  - Chain wallet quote (POST /v1/chain/quote)
  - Chain wallet swap (POST /v1/chain/swap)
- Add tier gating with upsell messaging for Pro features
- Handle rate limiting gracefully with 429 responses
- Add Pydantic schemas for AVE API requests/responses

Fixes #11
2026-04-08 14:41:40 +00:00

123 lines
3.9 KiB
Python

import uuid
from datetime import datetime
from sqlalchemy import (
Column,
String,
Text,
Float,
Boolean,
DateTime,
ForeignKey,
Index,
JSON,
)
from sqlalchemy.orm import relationship
from ..core.database import Base
def generate_uuid():
return str(uuid.uuid4())
class User(Base):
__tablename__ = "users"
id = Column(String, primary_key=True, default=generate_uuid)
email = Column(String, unique=True, nullable=False)
password_hash = Column(String, nullable=False)
tier = Column(String, default="free")
created_at = Column(DateTime, default=datetime.utcnow)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
bots = relationship("Bot", back_populates="user", cascade="all, delete-orphan")
class Bot(Base):
__tablename__ = "bots"
id = Column(String, primary_key=True, default=generate_uuid)
user_id = Column(String, ForeignKey("users.id"), nullable=False)
name = Column(String, nullable=False)
description = Column(Text)
strategy_config = Column(JSON, nullable=False)
llm_config = Column(JSON, nullable=False)
status = Column(String, default="draft")
created_at = Column(DateTime, default=datetime.utcnow)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
user = relationship("User", back_populates="bots")
conversations = relationship(
"BotConversation", back_populates="bot", cascade="all, delete-orphan"
)
backtests = relationship(
"Backtest", back_populates="bot", cascade="all, delete-orphan"
)
simulations = relationship(
"Simulation", back_populates="bot", cascade="all, delete-orphan"
)
signals = relationship("Signal", back_populates="bot", cascade="all, delete-orphan")
class BotConversation(Base):
__tablename__ = "bot_conversations"
id = Column(String, primary_key=True, default=generate_uuid)
bot_id = Column(String, ForeignKey("bots.id"), nullable=False)
role = Column(String, nullable=False)
content = Column(Text, nullable=False)
created_at = Column(DateTime, default=datetime.utcnow)
bot = relationship("Bot", back_populates="conversations")
class Backtest(Base):
__tablename__ = "backtests"
id = Column(String, primary_key=True, default=generate_uuid)
bot_id = Column(String, ForeignKey("bots.id"), nullable=False)
started_at = Column(DateTime, nullable=False)
ended_at = Column(DateTime)
status = Column(String, nullable=False)
config = Column(JSON, nullable=False)
result = Column(JSON)
bot = relationship("Bot", back_populates="backtests")
class Simulation(Base):
__tablename__ = "simulations"
id = Column(String, primary_key=True, default=generate_uuid)
bot_id = Column(String, ForeignKey("bots.id"), nullable=False)
started_at = Column(DateTime, nullable=False)
status = Column(String, nullable=False)
config = Column(JSON, nullable=False)
signals = Column(JSON)
bot = relationship("Bot", back_populates="simulations")
class Signal(Base):
__tablename__ = "signals"
id = Column(String, primary_key=True, default=generate_uuid)
bot_id = Column(String, ForeignKey("bots.id"), nullable=False)
run_id = Column(String, nullable=False)
signal_type = Column(String, nullable=False)
token = Column(String, nullable=False)
price = Column(Float, nullable=False)
confidence = Column(Float)
reasoning = Column(Text)
executed = Column(Boolean, default=False)
created_at = Column(DateTime, default=datetime.utcnow)
bot = relationship("Bot", back_populates="signals")
Index("idx_bots_user_id", Bot.user_id)
Index("idx_conversations_bot_id", BotConversation.bot_id)
Index("idx_backtests_bot_id", Backtest.bot_id)
Index("idx_simulations_bot_id", Simulation.bot_id)
Index("idx_signals_bot_id", Signal.bot_id)
Index("idx_signals_run_id", Signal.run_id)