changed types around
This commit is contained in:
parent
24e82bbb78
commit
f61d1aa0c3
75 changed files with 3625 additions and 34314 deletions
|
|
@ -30,7 +30,7 @@
|
|||
"dotenv": "^16.3.0",
|
||||
"@stock-bot/http-client": "*",
|
||||
"@stock-bot/config": "*",
|
||||
"@stock-bot/shared-types": "*",
|
||||
"@stock-bot/types": "*",
|
||||
"@stock-bot/event-bus": "*",
|
||||
"@stock-bot/utils": "*"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import Redis from 'ioredis';
|
||||
import { databaseConfig } from '@stock-bot/config';
|
||||
import type { MarketDataEvent, SignalEvent, TradingEvent } from '@stock-bot/shared-types';
|
||||
import type { MarketDataEvent, SignalEvent, TradingEvent } from '@stock-bot/types';
|
||||
|
||||
export class EventPublisher {
|
||||
private dragonfly: Redis;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { MarketData, OHLCV, MarketDataEvent } from '@stock-bot/shared-types';
|
||||
import type { MarketData, OHLCV, MarketDataEvent } from '@stock-bot/types';
|
||||
import { dataProviderConfigs } from '@stock-bot/config';
|
||||
import { EventPublisher } from './EventPublisher';
|
||||
import { DataNormalizer } from './DataNormalizer';
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
// Market Data Gateway Types - Consolidated and organized
|
||||
|
||||
// Market Data Types
|
||||
export interface MarketDataTick {
|
||||
symbol: string;
|
||||
|
|
@ -34,6 +36,18 @@ export interface MarketDataCandle {
|
|||
trades?: number;
|
||||
}
|
||||
|
||||
export interface MarketDataTrade {
|
||||
id: string;
|
||||
symbol: string;
|
||||
timestamp: number;
|
||||
price: number;
|
||||
size: number;
|
||||
side: 'buy' | 'sell';
|
||||
source: string;
|
||||
exchange?: string;
|
||||
conditions?: string[];
|
||||
}
|
||||
|
||||
export interface MarketDataOrder {
|
||||
id: string;
|
||||
symbol: string;
|
||||
|
|
@ -47,18 +61,6 @@ export interface MarketDataOrder {
|
|||
level?: number;
|
||||
}
|
||||
|
||||
export interface MarketDataTrade {
|
||||
id: string;
|
||||
symbol: string;
|
||||
timestamp: number;
|
||||
price: number;
|
||||
size: number;
|
||||
side: 'buy' | 'sell';
|
||||
source: string;
|
||||
exchange?: string;
|
||||
conditions?: string[];
|
||||
}
|
||||
|
||||
// Data Source Configuration
|
||||
export interface DataSourceConfig {
|
||||
id: string;
|
||||
|
|
@ -129,6 +131,36 @@ export interface ProcessingPipeline {
|
|||
};
|
||||
}
|
||||
|
||||
// Data Processing Pipeline
|
||||
export interface DataProcessor {
|
||||
id: string;
|
||||
name: string;
|
||||
type: 'enrichment' | 'validation' | 'normalization' | 'aggregation' | 'filter';
|
||||
enabled: boolean;
|
||||
priority: number;
|
||||
config: Record<string, any>;
|
||||
process(data: MarketDataTick | MarketDataCandle | MarketDataTrade): Promise<any>;
|
||||
}
|
||||
|
||||
export interface ProcessingPipeline {
|
||||
id: string;
|
||||
name: string;
|
||||
processors: DataProcessor[];
|
||||
inputFilter: {
|
||||
symbols?: string[];
|
||||
sources?: string[];
|
||||
dataTypes?: string[];
|
||||
};
|
||||
outputTargets: {
|
||||
eventBus?: boolean;
|
||||
database?: boolean;
|
||||
cache?: boolean;
|
||||
websocket?: boolean;
|
||||
dataProcessor?: boolean;
|
||||
featureStore?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
// Subscription Management
|
||||
export interface SubscriptionRequest {
|
||||
id: string;
|
||||
|
|
@ -200,94 +232,29 @@ export interface GatewayConfig {
|
|||
monitoring: {
|
||||
metrics: {
|
||||
enabled: boolean;
|
||||
port: number;
|
||||
path: string;
|
||||
};
|
||||
logging: {
|
||||
level: 'debug' | 'info' | 'warn' | 'error';
|
||||
format: 'json' | 'text';
|
||||
outputs: ('console' | 'file' | 'elasticsearch')[];
|
||||
intervalMs: number;
|
||||
retention: string;
|
||||
};
|
||||
alerts: {
|
||||
enabled: boolean;
|
||||
thresholds: {
|
||||
latencyMs: number;
|
||||
errorRate: number;
|
||||
latency: number;
|
||||
connectionLoss: number;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
// WebSocket Message Types
|
||||
export interface WebSocketMessage {
|
||||
type: 'subscribe' | 'unsubscribe' | 'data' | 'error' | 'heartbeat' | 'status';
|
||||
id?: string;
|
||||
timestamp: number;
|
||||
payload: any;
|
||||
}
|
||||
|
||||
export interface WebSocketSubscribeMessage extends WebSocketMessage {
|
||||
type: 'subscribe';
|
||||
payload: {
|
||||
symbols: string[];
|
||||
dataTypes: string[];
|
||||
filters?: Record<string, any>;
|
||||
};
|
||||
}
|
||||
|
||||
export interface WebSocketDataMessage extends WebSocketMessage {
|
||||
type: 'data';
|
||||
payload: {
|
||||
dataType: string;
|
||||
data: MarketDataTick | MarketDataCandle | MarketDataTrade | MarketDataOrder;
|
||||
};
|
||||
}
|
||||
|
||||
// Error Handling
|
||||
export interface DataSourceError {
|
||||
sourceId: string;
|
||||
timestamp: Date;
|
||||
type: 'connection' | 'authentication' | 'ratelimit' | 'data' | 'timeout';
|
||||
message: string;
|
||||
details?: Record<string, any>;
|
||||
severity: 'low' | 'medium' | 'high' | 'critical';
|
||||
}
|
||||
|
||||
export interface ProcessingError {
|
||||
processorId: string;
|
||||
pipelineId: string;
|
||||
timestamp: Date;
|
||||
data: any;
|
||||
error: string;
|
||||
stackTrace?: string;
|
||||
}
|
||||
|
||||
// Metrics and Monitoring
|
||||
export interface DataSourceMetrics {
|
||||
sourceId: string;
|
||||
timestamp: Date;
|
||||
connections: {
|
||||
active: number;
|
||||
total: number;
|
||||
failed: number;
|
||||
};
|
||||
messages: {
|
||||
received: number;
|
||||
processed: number;
|
||||
errors: number;
|
||||
dropped: number;
|
||||
};
|
||||
latency: {
|
||||
avgMs: number;
|
||||
p50Ms: number;
|
||||
p95Ms: number;
|
||||
p99Ms: number;
|
||||
};
|
||||
bandwidth: {
|
||||
inboundBytesPerSecond: number;
|
||||
outboundBytesPerSecond: number;
|
||||
};
|
||||
status: 'connected' | 'disconnected' | 'error';
|
||||
messagesReceived: number;
|
||||
bytesReceived: number;
|
||||
latencyMs: number;
|
||||
errorCount: number;
|
||||
lastUpdate: Date;
|
||||
}
|
||||
|
||||
export interface GatewayMetrics {
|
||||
|
|
@ -316,52 +283,6 @@ export interface GatewayMetrics {
|
|||
};
|
||||
}
|
||||
|
||||
// Service Integration
|
||||
export interface ServiceIntegration {
|
||||
serviceName: string;
|
||||
endpoint: string;
|
||||
healthCheck: string;
|
||||
authentication?: {
|
||||
type: 'apikey' | 'jwt' | 'basic';
|
||||
credentials: Record<string, string>;
|
||||
};
|
||||
retryPolicy: {
|
||||
maxRetries: number;
|
||||
backoffMs: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface DataProcessorIntegration extends ServiceIntegration {
|
||||
serviceName: 'data-processor';
|
||||
supportedOperations: ('ingest' | 'transform' | 'validate' | 'quality')[];
|
||||
}
|
||||
|
||||
export interface FeatureStoreIntegration extends ServiceIntegration {
|
||||
serviceName: 'feature-store';
|
||||
supportedOperations: ('compute' | 'store' | 'retrieve')[];
|
||||
}
|
||||
|
||||
export interface DataCatalogIntegration extends ServiceIntegration {
|
||||
serviceName: 'data-catalog';
|
||||
supportedOperations: ('register' | 'lineage' | 'quality' | 'governance')[];
|
||||
}
|
||||
|
||||
// Event Bus Integration
|
||||
export interface EventBusMessage {
|
||||
id: string;
|
||||
type: string;
|
||||
source: string;
|
||||
timestamp: Date;
|
||||
data: any;
|
||||
metadata?: Record<string, any>;
|
||||
}
|
||||
|
||||
export interface MarketDataEvent extends EventBusMessage {
|
||||
type: 'market.tick' | 'market.trade' | 'market.candle' | 'market.orderbook';
|
||||
source: 'market-data-gateway';
|
||||
data: MarketDataTick | MarketDataTrade | MarketDataCandle | MarketDataOrder;
|
||||
}
|
||||
|
||||
// Health Check
|
||||
export interface HealthStatus {
|
||||
service: string;
|
||||
|
|
@ -382,3 +303,42 @@ export interface HealthStatus {
|
|||
avgLatencyMs: number;
|
||||
};
|
||||
}
|
||||
|
||||
// WebSocket Types
|
||||
export interface WebSocketMessage {
|
||||
type: string;
|
||||
payload: any;
|
||||
timestamp: number;
|
||||
id?: string;
|
||||
}
|
||||
|
||||
export interface WebSocketSubscribeMessage extends WebSocketMessage {
|
||||
type: 'subscribe';
|
||||
payload: SubscriptionRequest;
|
||||
}
|
||||
|
||||
export interface WebSocketDataMessage extends WebSocketMessage {
|
||||
type: 'data';
|
||||
payload: MarketDataTick | MarketDataTrade | MarketDataCandle | MarketDataOrder;
|
||||
}
|
||||
|
||||
// Error Types
|
||||
export interface DataSourceError {
|
||||
sourceId: string;
|
||||
timestamp: Date;
|
||||
type: 'connection' | 'authentication' | 'ratelimit' | 'data' | 'timeout';
|
||||
message: string;
|
||||
details?: Record<string, any>;
|
||||
severity: 'low' | 'medium' | 'high' | 'critical';
|
||||
recoverable: boolean;
|
||||
}
|
||||
|
||||
// Event Types
|
||||
export interface MarketDataEvent {
|
||||
id: string;
|
||||
type: 'market.tick' | 'market.trade' | 'market.candle' | 'market.orderbook';
|
||||
source: 'market-data-gateway';
|
||||
timestamp: Date;
|
||||
data: MarketDataTick | MarketDataTrade | MarketDataCandle | MarketDataOrder;
|
||||
metadata?: Record<string, any>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
"hono": "^4.6.3",
|
||||
"ioredis": "^5.4.1",
|
||||
"@stock-bot/config": "*",
|
||||
"@stock-bot/shared-types": "*",
|
||||
"@stock-bot/types": "*",
|
||||
"ws": "^8.18.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
"type-check": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@stock-bot/shared-types": "workspace:*",
|
||||
"@stock-bot/types": "workspace:*",
|
||||
"@stock-bot/utils": "workspace:*",
|
||||
"@stock-bot/event-bus": "workspace:*",
|
||||
"@stock-bot/api-client": "workspace:*",
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
"type-check": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@stock-bot/shared-types": "*",
|
||||
"@stock-bot/types": "*",
|
||||
"@stock-bot/event-bus": "*",
|
||||
"@stock-bot/utils": "*",
|
||||
"@stock-bot/api-client": "*",
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
"type-check": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@stock-bot/shared-types": "*",
|
||||
"@stock-bot/types": "*",
|
||||
"@stock-bot/event-bus": "*",
|
||||
"@stock-bot/utils": "*",
|
||||
"@stock-bot/api-client": "*",
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
"test:watch": "bun test --watch src/tests/**/*.test.ts"
|
||||
}, "dependencies": {
|
||||
"hono": "^4.6.3",
|
||||
"@stock-bot/shared-types": "workspace:*",
|
||||
"@stock-bot/types": "workspace:*",
|
||||
"@stock-bot/utils": "workspace:*",
|
||||
"@stock-bot/event-bus": "workspace:*",
|
||||
"@stock-bot/api-client": "workspace:*",
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { EventEmitter } from 'events';
|
||||
import { OHLCV } from '@stock-bot/shared-types';
|
||||
import { Order, Position } from '@stock-bot/shared-types';
|
||||
import { OHLCV } from '@stock-bot/types';
|
||||
import { Order, Position } from '@stock-bot/types';
|
||||
import { createLogger } from '@stock-bot/utils';
|
||||
import { financialUtils } from '@stock-bot/utils';
|
||||
|
||||
const logger = createLogger('backtest-engine');
|
||||
|
||||
// Use OHLCV from shared-types as BarData equivalent
|
||||
// Use OHLCV from types as BarData equivalent
|
||||
export type BarData = OHLCV;
|
||||
|
||||
// Strategy interface to match existing pattern
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
"dependencies": {
|
||||
"hono": "^4.6.3",
|
||||
"@stock-bot/config": "*",
|
||||
"@stock-bot/shared-types": "*",
|
||||
"@stock-bot/types": "*",
|
||||
"ws": "^8.18.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
"hono": "^4.6.3",
|
||||
"ioredis": "^5.4.1",
|
||||
"@stock-bot/config": "*",
|
||||
"@stock-bot/shared-types": "*",
|
||||
"@stock-bot/types": "*",
|
||||
"ws": "^8.18.0",
|
||||
"node-cron": "^3.0.3",
|
||||
"axios": "^1.6.2"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue