Add ingest adapter seam and IBKR stub
This commit is contained in:
parent
f2f12f2ebe
commit
a35ab0b778
8 changed files with 239 additions and 94 deletions
54
services/ingest-equities/src/adapters/synthetic.ts
Normal file
54
services/ingest-equities/src/adapters/synthetic.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import type { EquityPrint } from "@islandflow/types";
|
||||
import type { EquityIngestAdapter, EquityIngestHandlers } from "./types";
|
||||
|
||||
type SyntheticEquitiesAdapterConfig = {
|
||||
emitIntervalMs: number;
|
||||
};
|
||||
|
||||
const buildSyntheticPrint = (seq: number, now: number): EquityPrint => {
|
||||
return {
|
||||
source_ts: now,
|
||||
ingest_ts: now,
|
||||
seq,
|
||||
trace_id: `ingest-equities-${seq}`,
|
||||
ts: now,
|
||||
underlying_id: "SPY",
|
||||
price: 450.1,
|
||||
size: 100,
|
||||
exchange: "TEST",
|
||||
offExchangeFlag: false
|
||||
};
|
||||
};
|
||||
|
||||
export const createSyntheticEquitiesAdapter = (
|
||||
config: SyntheticEquitiesAdapterConfig
|
||||
): EquityIngestAdapter => {
|
||||
return {
|
||||
name: "synthetic",
|
||||
start: (handlers: EquityIngestHandlers) => {
|
||||
let seq = 0;
|
||||
let timer: ReturnType<typeof setInterval> | null = null;
|
||||
let stopped = false;
|
||||
|
||||
const emit = () => {
|
||||
if (stopped) {
|
||||
return;
|
||||
}
|
||||
|
||||
seq += 1;
|
||||
const now = Date.now();
|
||||
const print = buildSyntheticPrint(seq, now);
|
||||
void handlers.onTrade(print);
|
||||
};
|
||||
|
||||
timer = setInterval(emit, config.emitIntervalMs);
|
||||
|
||||
return () => {
|
||||
stopped = true;
|
||||
if (timer) {
|
||||
clearInterval(timer);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
||||
13
services/ingest-equities/src/adapters/types.ts
Normal file
13
services/ingest-equities/src/adapters/types.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import type { EquityPrint, EquityQuote } from "@islandflow/types";
|
||||
|
||||
export type StopHandler = () => void | Promise<void>;
|
||||
|
||||
export type EquityIngestHandlers = {
|
||||
onTrade: (print: EquityPrint) => void | Promise<void>;
|
||||
onQuote?: (quote: EquityQuote) => void | Promise<void>;
|
||||
};
|
||||
|
||||
export type EquityIngestAdapter = {
|
||||
name: string;
|
||||
start: (handlers: EquityIngestHandlers) => StopHandler | Promise<StopHandler>;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue