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
20
services/ingest-options/src/adapters/ibkr.ts
Normal file
20
services/ingest-options/src/adapters/ibkr.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import type { OptionIngestAdapter, OptionIngestHandlers } from "./types";
|
||||
|
||||
type IbkrOptionsAdapterConfig = {
|
||||
host: string;
|
||||
port: number;
|
||||
clientId: number;
|
||||
};
|
||||
|
||||
export const createIbkrOptionsAdapter = (
|
||||
config: IbkrOptionsAdapterConfig
|
||||
): OptionIngestAdapter => {
|
||||
return {
|
||||
name: "ibkr",
|
||||
start: (_handlers: OptionIngestHandlers) => {
|
||||
throw new Error(
|
||||
`IBKR adapter not implemented. Requested ${config.host}:${config.port} clientId=${config.clientId}.`
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
54
services/ingest-options/src/adapters/synthetic.ts
Normal file
54
services/ingest-options/src/adapters/synthetic.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import type { OptionPrint } from "@islandflow/types";
|
||||
import type { OptionIngestAdapter, OptionIngestHandlers } from "./types";
|
||||
|
||||
type SyntheticOptionsAdapterConfig = {
|
||||
emitIntervalMs: number;
|
||||
};
|
||||
|
||||
const buildSyntheticPrint = (seq: number, now: number): OptionPrint => {
|
||||
return {
|
||||
source_ts: now,
|
||||
ingest_ts: now,
|
||||
seq,
|
||||
trace_id: `ingest-options-${seq}`,
|
||||
ts: now,
|
||||
option_contract_id: "SPY-2025-01-17-450-C",
|
||||
price: 1.25,
|
||||
size: 10,
|
||||
exchange: "TEST",
|
||||
conditions: ["TEST"]
|
||||
};
|
||||
};
|
||||
|
||||
export const createSyntheticOptionsAdapter = (
|
||||
config: SyntheticOptionsAdapterConfig
|
||||
): OptionIngestAdapter => {
|
||||
return {
|
||||
name: "synthetic",
|
||||
start: (handlers: OptionIngestHandlers) => {
|
||||
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-options/src/adapters/types.ts
Normal file
13
services/ingest-options/src/adapters/types.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import type { OptionNBBO, OptionPrint } from "@islandflow/types";
|
||||
|
||||
export type StopHandler = () => void | Promise<void>;
|
||||
|
||||
export type OptionIngestHandlers = {
|
||||
onTrade: (print: OptionPrint) => void | Promise<void>;
|
||||
onNBBO?: (nbbo: OptionNBBO) => void | Promise<void>;
|
||||
};
|
||||
|
||||
export type OptionIngestAdapter = {
|
||||
name: string;
|
||||
start: (handlers: OptionIngestHandlers) => StopHandler | Promise<StopHandler>;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue