feat: add autonomous paper-trading and calibration pipeline
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
const path = require('path');
|
||||
const Database = require('better-sqlite3');
|
||||
|
||||
const intelligencePath = process.env.INTELLIGENCE_DB || path.resolve(process.cwd(), 'intelligence.sqlite');
|
||||
const db = new Database(intelligencePath, { readonly: true });
|
||||
|
||||
async function autonomyRoutes(fastify) {
|
||||
fastify.get('/health', async () => ({ ok: true, service: 'duriin-api' }));
|
||||
|
||||
fastify.get('/autonomy/status', async () => {
|
||||
const exists = db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='autonomy_jobs'").get();
|
||||
if (!exists) return { enabled: false, reason: 'autonomy schema is not initialized' };
|
||||
const jobs = db.prepare(`
|
||||
SELECT lane, status, COUNT(*) AS count
|
||||
FROM autonomy_jobs
|
||||
GROUP BY lane, status
|
||||
ORDER BY lane, status
|
||||
`).all();
|
||||
const predictions = db.prepare(`
|
||||
SELECT status, COUNT(*) AS count
|
||||
FROM autonomy_predictions
|
||||
GROUP BY status
|
||||
ORDER BY status
|
||||
`).all();
|
||||
const decisions = db.prepare(`
|
||||
SELECT action, COUNT(*) AS count
|
||||
FROM autonomy_decisions
|
||||
GROUP BY action
|
||||
ORDER BY action
|
||||
`).all();
|
||||
const outcomes = db.prepare(`
|
||||
SELECT COUNT(*) AS total,
|
||||
SUM(direction_correct) AS correct,
|
||||
AVG(excess_return) AS average_excess_return
|
||||
FROM autonomy_outcomes
|
||||
`).get();
|
||||
const legacy = db.prepare('SELECT COUNT(*) AS count FROM autonomy_legacy_records').get();
|
||||
const instruments = db.prepare('SELECT COUNT(*) AS count FROM autonomy_instruments WHERE active=1 AND tradable=1').get();
|
||||
return { enabled: true, jobs, predictions, decisions, outcomes, legacyRecords: legacy.count, allowlistedInstruments: instruments.count };
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = autonomyRoutes;
|
||||
Reference in New Issue
Block a user