feat: saxo connector
This commit is contained in:
@@ -74,6 +74,16 @@ def init_db():
|
||||
)""")
|
||||
c.execute("CREATE INDEX IF NOT EXISTS idx_saxo_snap_symbol_date ON saxo_option_snapshots(symbol, snapshot_date)")
|
||||
|
||||
c.execute("""CREATE TABLE IF NOT EXISTS saxo_instrument_catalog (
|
||||
uic INTEGER PRIMARY KEY,
|
||||
symbol TEXT NOT NULL,
|
||||
asset_type TEXT NOT NULL,
|
||||
description TEXT,
|
||||
updated_at TEXT DEFAULT (datetime('now'))
|
||||
)""")
|
||||
c.execute("CREATE INDEX IF NOT EXISTS idx_saxo_catalog_type ON saxo_instrument_catalog(asset_type)")
|
||||
c.execute("CREATE INDEX IF NOT EXISTS idx_saxo_catalog_symbol ON saxo_instrument_catalog(symbol)")
|
||||
|
||||
c.execute("""CREATE TABLE IF NOT EXISTS strategy_scenarios (
|
||||
id TEXT PRIMARY KEY,
|
||||
symbol TEXT NOT NULL,
|
||||
@@ -6126,3 +6136,44 @@ def get_saxo_snapshot_symbols() -> List[Dict[str, Any]]:
|
||||
""").fetchall()
|
||||
conn.close()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
|
||||
def upsert_saxo_catalog_rows(rows: List[Dict[str, Any]]):
|
||||
if not rows:
|
||||
return
|
||||
conn = get_conn()
|
||||
conn.executemany("""INSERT INTO saxo_instrument_catalog (uic, symbol, asset_type, description, updated_at)
|
||||
VALUES (?,?,?,?, datetime('now'))
|
||||
ON CONFLICT(uic) DO UPDATE SET
|
||||
symbol=excluded.symbol, asset_type=excluded.asset_type,
|
||||
description=excluded.description, updated_at=datetime('now')""",
|
||||
[(r["uic"], r["symbol"], r["asset_type"], r.get("description")) for r in rows])
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
def get_saxo_catalog(asset_type: Optional[str] = None, q: Optional[str] = None, limit: int = 200) -> List[Dict[str, Any]]:
|
||||
conn = get_conn()
|
||||
query = "SELECT * FROM saxo_instrument_catalog WHERE 1=1"
|
||||
params: List[Any] = []
|
||||
if asset_type:
|
||||
query += " AND asset_type=?"
|
||||
params.append(asset_type)
|
||||
if q:
|
||||
query += " AND (symbol LIKE ? OR description LIKE ?)"
|
||||
params.extend([f"%{q}%", f"%{q}%"])
|
||||
query += " ORDER BY symbol LIMIT ?"
|
||||
params.append(limit)
|
||||
rows = conn.execute(query, params).fetchall()
|
||||
conn.close()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
|
||||
def get_saxo_catalog_summary() -> List[Dict[str, Any]]:
|
||||
conn = get_conn()
|
||||
rows = conn.execute("""
|
||||
SELECT asset_type, COUNT(*) AS count, MAX(updated_at) AS last_refreshed
|
||||
FROM saxo_instrument_catalog GROUP BY asset_type ORDER BY asset_type
|
||||
""").fetchall()
|
||||
conn.close()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
Reference in New Issue
Block a user