Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/agent/backtestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { loadConfig } from "../config/loader.js";
import { getDb } from "../storage/db.js";
import { getBacktestBroker } from "../broker/index.js";
import { getStockOhlcv, getIndexOhlcv, type Bar } from "../data/sources/dnsePublic.js";
import { DISCOVERY_UNIVERSE, discoverTickers } from "../tools/discover.js";
import { DISCOVERY_UNIVERSE, discoverTickers, mapLimit } from "../tools/discover.js";
import { setActiveAsOf } from "./clock.js";
import { runTeamAnalysis } from "./team/index.js";
import type { FinalDecision, TeamEvent } from "./team/state.js";
Expand Down Expand Up @@ -259,10 +259,12 @@ export async function runBacktestSession(
const fetchFrom = startSec - 7 * 86400;
const fetchTo = endSec + 7 * 86400;
const bars: Record<string, Bar[]> = {};
for (const t of universe) {

await mapLimit(universe, 10, async (t) => {
bars[t] = await getStockOhlcv(t, "30", fetchFrom, fetchTo);
if (cb.signal?.aborted) throw new Error("aborted");
}
});

const vnindex = await getIndexOhlcv("VNINDEX", "30", fetchFrom, fetchTo);

const intervalTurns = intervalCloses(vnindex, startSec, endSec, interval.minutes);
Expand Down
2 changes: 1 addition & 1 deletion src/data/sources/dnsePublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function fetchOhlcs(

export function seriesToBars(s: OhlcvSeries): Bar[] {
const out: Bar[] = [];
for (let i = 0; i < s.t.length; i++) {
for (let i = 0; i < (s.t?.length || 0); i++) {
if (s.c[i] == null) continue; // skip empty intraday slots
out.push({
time: s.t[i]!,
Expand Down
2 changes: 1 addition & 1 deletion src/tools/discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ async function resolveUniverse(
return { universe: "all_listed", tickers: await listedTickers(["HOSE", "HNX", "UPCOM"]) };
}

async function mapLimit<T, R>(
export async function mapLimit<T, R>(
items: readonly T[],
concurrency: number,
fn: (item: T) => Promise<R>,
Expand Down
Loading