cycle and trade add exchange field

This commit is contained in:
2025-09-19 23:04:17 +02:00
parent 442da655c0
commit 76cc967c42
5 changed files with 48 additions and 0 deletions

View File

@@ -37,6 +37,8 @@ def create_trade(session: Session, trade_data: Mapping) -> models.Trades:
payload = {k: v for k, v in data.items() if k in allowed}
if "symbol" not in payload:
raise ValueError("symbol is required")
if "exchange" not in payload:
raise ValueError("exchange is required")
if "underlying_currency" not in payload:
raise ValueError("underlying_currency is required")
payload["underlying_currency"] = _check_enum(models.UnderlyingCurrency, payload["underlying_currency"], "underlying_currency")
@@ -74,6 +76,7 @@ def create_trade(session: Session, trade_data: Mapping) -> models.Trades:
c_payload = {
"user_id": user_id,
"symbol": payload["symbol"],
"exchange": payload["exchange"],
"underlying_currency": payload["underlying_currency"],
"friendly_name": "Auto-created Cycle by trade " + payload.get("friendly_name", ""),
"status": models.CycleStatus.OPEN,
@@ -184,6 +187,8 @@ def create_cycle(session: Session, cycle_data: Mapping) -> models.Cycles:
raise ValueError("user_id is required")
if "symbol" not in payload:
raise ValueError("symbol is required")
if "exchange" not in payload:
raise ValueError("exchange is required")
if "underlying_currency" not in payload:
raise ValueError("underlying_currency is required")
payload["underlying_currency"] = _check_enum(models.UnderlyingCurrency, payload["underlying_currency"], "underlying_currency")

View File

@@ -0,0 +1,21 @@
from __future__ import annotations
from typing import TYPE_CHECKING
from sqlmodel import SQLModel
if TYPE_CHECKING:
from datetime import date, datetime
from trading_journal.models import TradeStrategy, TradeType, UnderlyingCurrency
class TradeBase(SQLModel):
user_id: int
friendly_name: str | None
symbol: str
underlying_currency: UnderlyingCurrency
trade_type: TradeType
trade_strategy: TradeStrategy
trade_date: date
trade_time_utc: datetime

View File

@@ -72,6 +72,7 @@ class Trades(SQLModel, table=True):
# allow null while user may omit friendly_name; uniqueness enforced per-user by constraint
friendly_name: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
symbol: str = Field(sa_column=Column(Text, nullable=False))
exchange: str = Field(sa_column=Column(Text, nullable=False))
underlying_currency: UnderlyingCurrency = Field(sa_column=Column(Text, nullable=False))
trade_type: TradeType = Field(sa_column=Column(Text, nullable=False))
trade_strategy: TradeStrategy = Field(sa_column=Column(Text, nullable=False))
@@ -100,6 +101,7 @@ class Cycles(SQLModel, table=True):
user_id: int = Field(foreign_key="users.id", nullable=False, index=True)
friendly_name: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
symbol: str = Field(sa_column=Column(Text, nullable=False))
exchange: str = Field(sa_column=Column(Text, nullable=False))
underlying_currency: UnderlyingCurrency = Field(sa_column=Column(Text, nullable=False))
status: CycleStatus = Field(sa_column=Column(Text, nullable=False))
funding_source: FundingSource = Field(sa_column=Column(Text, nullable=True))

View File

@@ -72,6 +72,7 @@ class Trades(SQLModel, table=True):
# allow null while user may omit friendly_name; uniqueness enforced per-user by constraint
friendly_name: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
symbol: str = Field(sa_column=Column(Text, nullable=False))
exchange: str = Field(sa_column=Column(Text, nullable=False))
underlying_currency: UnderlyingCurrency = Field(sa_column=Column(Text, nullable=False))
trade_type: TradeType = Field(sa_column=Column(Text, nullable=False))
trade_strategy: TradeStrategy = Field(sa_column=Column(Text, nullable=False))
@@ -100,6 +101,7 @@ class Cycles(SQLModel, table=True):
user_id: int = Field(foreign_key="users.id", nullable=False, index=True)
friendly_name: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
symbol: str = Field(sa_column=Column(Text, nullable=False))
exchange: str = Field(sa_column=Column(Text, nullable=False))
underlying_currency: UnderlyingCurrency = Field(sa_column=Column(Text, nullable=False))
status: CycleStatus = Field(sa_column=Column(Text, nullable=False))
funding_source: FundingSource = Field(sa_column=Column(Text, nullable=True))