rebuild(runtime): govern market operations and job truth
This commit is contained in:
@@ -163,6 +163,21 @@ class MarketRepository:
|
||||
)
|
||||
)
|
||||
|
||||
def open_dates_between(
|
||||
self, connection: sqlite3.Connection, start_date: str, end_date: str
|
||||
) -> tuple[str, ...]:
|
||||
return tuple(
|
||||
str(row["trade_date"])
|
||||
for row in connection.execute(
|
||||
"""
|
||||
SELECT trade_date FROM trading_days
|
||||
WHERE is_open = 1 AND trade_date BETWEEN ? AND ?
|
||||
ORDER BY trade_date
|
||||
""",
|
||||
(start_date, end_date),
|
||||
).fetchall()
|
||||
)
|
||||
|
||||
def active_stock_count(self, connection: sqlite3.Connection) -> int:
|
||||
row = connection.execute(
|
||||
"""
|
||||
@@ -235,6 +250,81 @@ class MarketRepository:
|
||||
(through,),
|
||||
).fetchone()
|
||||
|
||||
def save_event_revision(
|
||||
self,
|
||||
connection: sqlite3.Connection,
|
||||
*,
|
||||
trade_date: str,
|
||||
identifier: str,
|
||||
event_type: str,
|
||||
reason: str,
|
||||
first_time: str,
|
||||
last_time: str,
|
||||
open_times: int | None,
|
||||
source: str,
|
||||
priority: int,
|
||||
created_by: int | None,
|
||||
created_at: str,
|
||||
) -> int:
|
||||
cursor = connection.execute(
|
||||
"""
|
||||
INSERT INTO market_event_revisions (
|
||||
trade_date, identifier, event_type, reason, first_time, last_time,
|
||||
open_times, source, priority, created_by, created_at
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
trade_date,
|
||||
identifier,
|
||||
event_type,
|
||||
reason,
|
||||
first_time,
|
||||
last_time,
|
||||
open_times,
|
||||
source,
|
||||
priority,
|
||||
created_by,
|
||||
created_at,
|
||||
),
|
||||
)
|
||||
return int(cursor.lastrowid)
|
||||
|
||||
def event_revisions(
|
||||
self, connection: sqlite3.Connection, trade_date: str
|
||||
) -> tuple[sqlite3.Row, ...]:
|
||||
return tuple(
|
||||
connection.execute(
|
||||
"""
|
||||
SELECT * FROM (
|
||||
SELECT revisions.*,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY identifier, event_type
|
||||
ORDER BY priority DESC, id DESC
|
||||
) AS rank
|
||||
FROM market_event_revisions AS revisions
|
||||
WHERE trade_date = ?
|
||||
) WHERE rank = 1
|
||||
""",
|
||||
(trade_date,),
|
||||
).fetchall()
|
||||
)
|
||||
|
||||
def event_revision_history(
|
||||
self, connection: sqlite3.Connection, trade_date: str, identifier: str
|
||||
) -> tuple[sqlite3.Row, ...]:
|
||||
return tuple(
|
||||
connection.execute(
|
||||
"""
|
||||
SELECT revisions.*, users.username AS created_by_name
|
||||
FROM market_event_revisions AS revisions
|
||||
LEFT JOIN users ON users.id = revisions.created_by
|
||||
WHERE revisions.trade_date = ? AND revisions.identifier = ?
|
||||
ORDER BY revisions.id DESC
|
||||
""",
|
||||
(trade_date, identifier),
|
||||
).fetchall()
|
||||
)
|
||||
|
||||
def sector_members(
|
||||
self, connection: sqlite3.Connection, trade_date: str, sector_name: str
|
||||
) -> sqlite3.Row | None:
|
||||
|
||||
Reference in New Issue
Block a user