You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
"""
|
|
SEC Form 4 — Insider Transaction model
|
|
"""
|
|
|
|
from datetime import datetime, timezone
|
|
import uuid
|
|
|
|
from sqlalchemy import Column, String, Float, Boolean, Index, UniqueConstraint
|
|
from sqlalchemy.dialects.postgresql import UUID, TIMESTAMP
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
class InsiderTransaction(Base):
|
|
__tablename__ = "insider_transactions"
|
|
|
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
ticker = Column(String(10), nullable=False, index=True)
|
|
cik = Column(String(20), nullable=False)
|
|
accession_number = Column(String(30), nullable=False)
|
|
filing_date = Column(TIMESTAMP(timezone=True), nullable=False)
|
|
|
|
# Reporting owner
|
|
owner_name = Column(String(255), nullable=False)
|
|
owner_cik = Column(String(20), nullable=True)
|
|
is_officer = Column(Boolean, default=False)
|
|
is_director = Column(Boolean, default=False)
|
|
is_ten_percent_owner = Column(Boolean, default=False)
|
|
officer_title = Column(String(255), nullable=True)
|
|
|
|
# Transaction details
|
|
security_title = Column(String(255), nullable=True)
|
|
transaction_date = Column(TIMESTAMP(timezone=True), nullable=False)
|
|
transaction_code = Column(String(5), nullable=False) # P, S, A, M, G, etc.
|
|
shares = Column(Float, nullable=False)
|
|
price_per_share = Column(Float, nullable=True)
|
|
total_value = Column(Float, nullable=True)
|
|
shares_owned_after = Column(Float, nullable=True)
|
|
is_derivative = Column(Boolean, default=False)
|
|
|
|
created_at = Column(
|
|
TIMESTAMP(timezone=True), default=lambda: datetime.now(timezone.utc)
|
|
)
|
|
updated_at = Column(
|
|
TIMESTAMP(timezone=True),
|
|
default=lambda: datetime.now(timezone.utc),
|
|
onupdate=lambda: datetime.now(timezone.utc),
|
|
)
|
|
|
|
__table_args__ = (
|
|
UniqueConstraint(
|
|
"accession_number", "owner_cik", "transaction_date",
|
|
"transaction_code", "shares",
|
|
name="uq_insider_transaction",
|
|
),
|
|
Index("idx_insider_ticker_date", "ticker", "transaction_date"),
|
|
Index("idx_insider_ticker_code", "ticker", "transaction_code"),
|
|
Index("idx_insider_filing_date", "filing_date"),
|
|
)
|