class Source(db.Model): __tablename__ = "sources" id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.Unicode(), default="Unnamed") typename = db.Column(db.Unicode(), nullable=False) config_json = db.Column(db.Unicode(), default="{}")
class LiveSessionModel(db.Model): __tablename__ = "live_sessions" id = db.Column(db.Integer(), primary_key=True) start_datetime = db.Column(db.DateTime(), nullable=True) end_datetime = db.Column(db.DateTime(), nullable=True) # Used for logging only. Model config is copied config_json = db.Column(db.Unicode(), default="{}")
class StrategyModel(db.Model): __tablename__ = "strategies" id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.Unicode(), default="Unnamed") typename = db.Column( db.Enum(StrategyTypesEnum, values_callable=lambda x: [e.value for e in x]) ) live_session_id = db.Column( db.Integer, db.ForeignKey("live_sessions.id"), nullable=True ) resource_id = db.Column(db.Integer, db.ForeignKey("resources.id"), nullable=True) config_json = db.Column(db.Unicode(), default="{}")
class BacktestSessionModel(db.Model): __tablename__ = "backtest_sessions" id = db.Column(db.Integer(), primary_key=True) strategy_id = db.Column(db.Integer, db.ForeignKey("strategies.id")) start_datetime = db.Column(db.DateTime(), nullable=True) end_datetime = db.Column(db.DateTime(), nullable=True) config_json = db.Column(db.Unicode(), default="{}") backtest_type = db.Column(db.Unicode(), default="") finished_datetime = db.Column(db.DateTime(), nullable=True) cached_session_id = db.Column(db.Integer(), db.ForeignKey("backtest_sessions.id"), nullable=True) def __init__(self, **kw): super().__init__(**kw) self._sources = set() @property def backtest_sources(self): return self._sources def add_source(self, source): self._sources.add(source)
class ResourceModel(db.Model): __tablename__ = "resources" id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.Unicode(), default="Unnamed") is_always_on = db.Column(db.Boolean, default=False) primary_live_source_id = db.Column( db.Integer, db.ForeignKey("sources.id"), nullable=True ) secondary_live_source_id = db.Column( db.Integer, db.ForeignKey("sources.id"), nullable=True ) primary_backtest_source_id = db.Column( db.Integer, db.ForeignKey("sources.id"), nullable=True ) secondary_backtest_source_id = db.Column( db.Integer, db.ForeignKey("sources.id"), nullable=True )