adding data-services
This commit is contained in:
parent
e3bfd05b90
commit
405b818c86
139 changed files with 55943 additions and 416 deletions
28
libs/shared-types/README.md
Normal file
28
libs/shared-types/README.md
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# Shared Types Library
|
||||
|
||||
This library contains domain-specific TypeScript type definitions used across the stock-bot project.
|
||||
|
||||
## Directory Structure
|
||||
|
||||
- `market/` - Market data structures (OHLCV, OrderBook, etc.)
|
||||
- `trading/` - Trading types (Orders, Positions, etc.)
|
||||
- `strategy/` - Strategy and signal types
|
||||
- `events/` - Event definitions for the event bus
|
||||
- `api/` - Common API request/response types
|
||||
- `config/` - Configuration type definitions
|
||||
|
||||
## Usage
|
||||
|
||||
```typescript
|
||||
import { OHLCV, MarketData } from '@stock-bot/shared-types';
|
||||
|
||||
// Use the types
|
||||
const marketData: MarketData = {
|
||||
symbol: 'AAPL',
|
||||
price: 150.25,
|
||||
bid: 150.20,
|
||||
ask: 150.30,
|
||||
volume: 1000000,
|
||||
timestamp: new Date()
|
||||
};
|
||||
```
|
||||
23
libs/shared-types/package.json
Normal file
23
libs/shared-types/package.json
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"name": "@stock-bot/shared-types",
|
||||
"version": "1.0.0",
|
||||
"description": "Domain-specific shared TypeScript definitions for the trading bot",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"dev": "tsc --watch",
|
||||
"clean": "rm -rf dist",
|
||||
"test": "echo \"No tests yet\""
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.4.5"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js",
|
||||
"require": "./dist/index.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
44
libs/shared-types/src/api/api.ts
Normal file
44
libs/shared-types/src/api/api.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
// Service Types
|
||||
export interface ServiceConfig {
|
||||
name: string;
|
||||
version: string;
|
||||
environment: 'development' | 'staging' | 'production';
|
||||
port?: number;
|
||||
dependencies?: string[];
|
||||
}
|
||||
|
||||
export interface HealthStatus {
|
||||
service: string;
|
||||
status: 'healthy' | 'unhealthy' | 'degraded';
|
||||
timestamp: Date;
|
||||
details?: Record<string, any>;
|
||||
}
|
||||
|
||||
// API Response Types
|
||||
export interface ApiResponse<T> {
|
||||
success: boolean;
|
||||
data?: T;
|
||||
error?: string;
|
||||
timestamp: Date;
|
||||
}
|
||||
|
||||
export interface PaginatedResponse<T> {
|
||||
data: T[];
|
||||
total: number;
|
||||
page: number;
|
||||
limit: number;
|
||||
hasNext: boolean;
|
||||
}
|
||||
|
||||
// HTTP Response standards
|
||||
export interface ErrorResponse {
|
||||
status: number;
|
||||
code: string;
|
||||
message: string;
|
||||
details?: any;
|
||||
}
|
||||
|
||||
export interface SuccessResponse<T> {
|
||||
status: number;
|
||||
data: T;
|
||||
}
|
||||
69
libs/shared-types/src/config/config.ts
Normal file
69
libs/shared-types/src/config/config.ts
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
// Configuration Types
|
||||
export interface DatabaseConfig {
|
||||
questdb: {
|
||||
host: string;
|
||||
port: number;
|
||||
database: string;
|
||||
};
|
||||
postgres: {
|
||||
host: string;
|
||||
port: number;
|
||||
database: string;
|
||||
username: string;
|
||||
password: string;
|
||||
};
|
||||
dragonfly: {
|
||||
host: string;
|
||||
port: number;
|
||||
password?: string;
|
||||
};
|
||||
mongodb?: {
|
||||
uri: string;
|
||||
database: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface BrokerConfig {
|
||||
name: string;
|
||||
apiKey: string;
|
||||
secretKey: string;
|
||||
baseUrl: string;
|
||||
sandbox: boolean;
|
||||
rateLimit?: {
|
||||
maxRequestsPerSecond: number;
|
||||
maxRequestsPerMinute: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface DataProviderConfig {
|
||||
name: string;
|
||||
apiKey: string;
|
||||
baseUrl: string;
|
||||
rateLimits: {
|
||||
requestsPerSecond: number;
|
||||
requestsPerDay: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface LoggingConfig {
|
||||
level: 'debug' | 'info' | 'warn' | 'error';
|
||||
format: 'json' | 'text';
|
||||
destination: 'console' | 'file' | 'both';
|
||||
filePath?: string;
|
||||
}
|
||||
|
||||
export interface SystemConfig {
|
||||
databases: DatabaseConfig;
|
||||
brokers: BrokerConfig[];
|
||||
dataProviders: DataProviderConfig[];
|
||||
logging: LoggingConfig;
|
||||
services: {
|
||||
[key: string]: ServiceConfig;
|
||||
};
|
||||
}
|
||||
|
||||
interface ServiceConfig {
|
||||
port: number;
|
||||
host: string;
|
||||
dependencies: string[];
|
||||
}
|
||||
42
libs/shared-types/src/events/events.ts
Normal file
42
libs/shared-types/src/events/events.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import { MarketData } from '../market/market-data';
|
||||
import { Order } from '../trading/orders';
|
||||
import { TradingSignal } from '../strategy/strategy';
|
||||
|
||||
// Event Types
|
||||
export interface MarketDataEvent {
|
||||
type: 'MARKET_DATA';
|
||||
data: MarketData;
|
||||
timestamp: Date;
|
||||
}
|
||||
|
||||
export interface OrderEvent {
|
||||
type: 'ORDER_CREATED' | 'ORDER_FILLED' | 'ORDER_CANCELLED';
|
||||
order: Order;
|
||||
timestamp: Date;
|
||||
}
|
||||
|
||||
export interface SignalEvent {
|
||||
type: 'SIGNAL_GENERATED';
|
||||
signal: TradingSignal;
|
||||
timestamp: Date;
|
||||
}
|
||||
|
||||
// Define more specific events
|
||||
export interface RiskAlertEvent {
|
||||
type: 'RISK_ALERT';
|
||||
alertLevel: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
|
||||
message: string;
|
||||
portfolioId?: string;
|
||||
strategyId?: string;
|
||||
timestamp: Date;
|
||||
}
|
||||
|
||||
export interface SystemEvent {
|
||||
type: 'SYSTEM_STARTUP' | 'SYSTEM_SHUTDOWN' | 'SERVICE_ERROR';
|
||||
serviceName: string;
|
||||
message?: string;
|
||||
timestamp: Date;
|
||||
}
|
||||
|
||||
export type TradingEvent = MarketDataEvent | OrderEvent | SignalEvent;
|
||||
export type Event = TradingEvent | RiskAlertEvent | SystemEvent;
|
||||
20
libs/shared-types/src/index.ts
Normal file
20
libs/shared-types/src/index.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// Export all types from their respective domains
|
||||
|
||||
// Market Data Types
|
||||
export * from './market/market-data';
|
||||
|
||||
// Trading Types
|
||||
export * from './trading/orders';
|
||||
|
||||
// Strategy Types
|
||||
export * from './strategy/strategy';
|
||||
export * from './strategy/backtest';
|
||||
|
||||
// Events
|
||||
export * from './events/events';
|
||||
|
||||
// API Types
|
||||
export * from './api/api';
|
||||
|
||||
// Configuration Types
|
||||
export * from './config/config';
|
||||
48
libs/shared-types/src/market/market-data.ts
Normal file
48
libs/shared-types/src/market/market-data.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
// Market Data Types
|
||||
export interface OHLCV {
|
||||
symbol: string;
|
||||
timestamp: Date;
|
||||
open: number;
|
||||
high: number;
|
||||
low: number;
|
||||
close: number;
|
||||
volume: number;
|
||||
}
|
||||
|
||||
export interface MarketData {
|
||||
symbol: string;
|
||||
price: number;
|
||||
bid: number;
|
||||
ask: number;
|
||||
volume: number;
|
||||
timestamp: Date;
|
||||
}
|
||||
|
||||
export interface OrderBook {
|
||||
symbol: string;
|
||||
bids: [number, number][]; // [price, size]
|
||||
asks: [number, number][]; // [price, size]
|
||||
timestamp: Date;
|
||||
}
|
||||
|
||||
// Fundamental Data Types
|
||||
export interface CompanyFundamentals {
|
||||
symbol: string;
|
||||
marketCap: number;
|
||||
peRatio?: number;
|
||||
pbRatio?: number;
|
||||
roe?: number;
|
||||
revenue: number;
|
||||
netIncome: number;
|
||||
lastUpdated: Date;
|
||||
}
|
||||
|
||||
export interface NewsItem {
|
||||
id: string;
|
||||
headline: string;
|
||||
summary: string;
|
||||
sentiment: number; // -1 to 1
|
||||
symbols: string[];
|
||||
source: string;
|
||||
publishedAt: Date;
|
||||
}
|
||||
53
libs/shared-types/src/strategy/backtest.ts
Normal file
53
libs/shared-types/src/strategy/backtest.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
// Trading Signal Types
|
||||
import { SignalType } from './strategy';
|
||||
|
||||
export interface Signal {
|
||||
symbol: string;
|
||||
type: SignalType;
|
||||
strength: number; // 0-1
|
||||
price: number;
|
||||
timestamp: Date;
|
||||
strategyId: string;
|
||||
metadata?: Record<string, any>;
|
||||
}
|
||||
|
||||
export interface BacktestConfig {
|
||||
strategyId: string;
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
symbols: string[];
|
||||
initialCapital: number;
|
||||
parameters: Record<string, any>;
|
||||
}
|
||||
|
||||
export interface BacktestResult {
|
||||
id: string;
|
||||
strategyId: string;
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
symbols: string[];
|
||||
initialCapital: number;
|
||||
finalCapital: number;
|
||||
totalReturn: number;
|
||||
annualizedReturn: number;
|
||||
maxDrawdown: number;
|
||||
sharpeRatio: number;
|
||||
trades: BacktestTrade[];
|
||||
dailyPerformance: DailyPerformance[];
|
||||
}
|
||||
|
||||
export interface BacktestTrade {
|
||||
symbol: string;
|
||||
side: 'BUY' | 'SELL';
|
||||
quantity: number;
|
||||
price: number;
|
||||
timestamp: Date;
|
||||
pnl?: number;
|
||||
}
|
||||
|
||||
export interface DailyPerformance {
|
||||
date: Date;
|
||||
portfolioValue: number;
|
||||
dailyPnL: number;
|
||||
dailyReturn: number;
|
||||
}
|
||||
28
libs/shared-types/src/strategy/strategy.ts
Normal file
28
libs/shared-types/src/strategy/strategy.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// Strategy Types
|
||||
export type SignalType = 'BUY' | 'SELL' | 'HOLD';
|
||||
|
||||
export interface TradingSignal {
|
||||
symbol: string;
|
||||
type: SignalType;
|
||||
strength: number; // 0-1
|
||||
price: number;
|
||||
timestamp: Date;
|
||||
strategyId: string;
|
||||
metadata?: Record<string, any>;
|
||||
}
|
||||
|
||||
export interface Strategy {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
isActive: boolean;
|
||||
riskLimits: RiskLimits;
|
||||
parameters: Record<string, any>;
|
||||
}
|
||||
|
||||
export interface RiskLimits {
|
||||
maxPositionSize: number;
|
||||
maxDailyLoss: number;
|
||||
maxDrawdown: number;
|
||||
allowedSymbols?: string[];
|
||||
}
|
||||
35
libs/shared-types/src/trading/orders.ts
Normal file
35
libs/shared-types/src/trading/orders.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// Trading Types
|
||||
export type OrderSide = 'BUY' | 'SELL';
|
||||
export type OrderType = 'MARKET' | 'LIMIT' | 'STOP' | 'STOP_LIMIT';
|
||||
export type OrderStatus = 'PENDING' | 'FILLED' | 'PARTIALLY_FILLED' | 'CANCELLED' | 'REJECTED';
|
||||
|
||||
export interface Order {
|
||||
id: string;
|
||||
symbol: string;
|
||||
side: OrderSide;
|
||||
type: OrderType;
|
||||
quantity: number;
|
||||
price?: number;
|
||||
stopPrice?: number;
|
||||
status: OrderStatus;
|
||||
timestamp: Date;
|
||||
strategyId: string;
|
||||
}
|
||||
|
||||
export interface Position {
|
||||
symbol: string;
|
||||
quantity: number;
|
||||
averagePrice: number;
|
||||
marketValue: number;
|
||||
unrealizedPnL: number;
|
||||
timestamp: Date;
|
||||
}
|
||||
|
||||
export interface Portfolio {
|
||||
cash: number;
|
||||
totalValue: number;
|
||||
positions: Position[];
|
||||
dayPnL: number;
|
||||
totalPnL: number;
|
||||
timestamp: Date;
|
||||
}
|
||||
18
libs/shared-types/tsconfig.json
Normal file
18
libs/shared-types/tsconfig.json
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"declaration": true,
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"resolveJsonModule": true
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue