Expand synthetic data across S&P 500

Add S&P 500 symbol list and expand synthetic options/equities feeds with varied contracts, sizes, and bursts to keep alerts firing.
This commit is contained in:
dirtydishes 2025-12-29 19:09:15 -05:00
parent 41bdd2c73a
commit 7996d00677
4 changed files with 643 additions and 26 deletions

View file

@ -1,22 +1,40 @@
import type { EquityPrint } from "@islandflow/types";
import { SP500_SYMBOLS, type EquityPrint } from "@islandflow/types";
import type { EquityIngestAdapter, EquityIngestHandlers } from "./types";
type SyntheticEquitiesAdapterConfig = {
emitIntervalMs: number;
};
const buildSyntheticPrint = (seq: number, now: number): EquityPrint => {
const EXCHANGES = ["NYSE", "NASDAQ", "ARCA", "BATS", "IEX", "TEST"];
const hashSymbol = (value: string): number => {
let hash = 0;
for (let i = 0; i < value.length; i += 1) {
hash = (hash * 31 + value.charCodeAt(i)) >>> 0;
}
return hash;
};
const buildSyntheticPrint = (
seq: number,
now: number,
symbol: string,
price: number,
size: number,
exchange: string,
offExchangeFlag: boolean
): EquityPrint => {
return {
source_ts: now,
ingest_ts: now,
seq,
trace_id: `ingest-equities-${seq}`,
trace_id: `synthetic-equities-${seq}`,
ts: now,
underlying_id: "SPY",
price: 450.1,
size: 100,
exchange: "TEST",
offExchangeFlag: false
underlying_id: symbol,
price,
size,
exchange,
offExchangeFlag
};
};
@ -35,10 +53,21 @@ export const createSyntheticEquitiesAdapter = (
return;
}
seq += 1;
const now = Date.now();
const print = buildSyntheticPrint(seq, now);
void handlers.onTrade(print);
const batchSize = 3;
for (let i = 0; i < batchSize; i += 1) {
seq += 1;
const symbol = SP500_SYMBOLS[(seq + i) % SP500_SYMBOLS.length];
const symbolHash = hashSymbol(symbol);
const basePrice = 25 + (symbolHash % 475);
const price = Number((basePrice + ((seq % 40) - 20) * 0.05).toFixed(2));
const size = 10 + (seq % 600);
const exchange = EXCHANGES[(seq + symbolHash) % EXCHANGES.length];
const offExchangeFlag = (seq + i) % 6 === 0;
const print = buildSyntheticPrint(seq, now + i * 4, symbol, price, size, exchange, offExchangeFlag);
void handlers.onTrade(print);
}
};
timer = setInterval(emit, config.emitIntervalMs);