refactored monorepo for more projects
This commit is contained in:
parent
4632c174dc
commit
9492f1b15e
180 changed files with 1438 additions and 424 deletions
223
apps/stock/config/config/default.json
Normal file
223
apps/stock/config/config/default.json
Normal file
|
|
@ -0,0 +1,223 @@
|
|||
{
|
||||
"name": "stock-bot",
|
||||
"version": "1.0.0",
|
||||
"environment": "development",
|
||||
"service": {
|
||||
"name": "stock-bot",
|
||||
"port": 3000,
|
||||
"host": "0.0.0.0",
|
||||
"healthCheckPath": "/health",
|
||||
"metricsPath": "/metrics",
|
||||
"shutdownTimeout": 30000,
|
||||
"cors": {
|
||||
"enabled": true,
|
||||
"origin": "*",
|
||||
"credentials": true
|
||||
}
|
||||
},
|
||||
"database": {
|
||||
"postgres": {
|
||||
"enabled": true,
|
||||
"host": "localhost",
|
||||
"port": 5432,
|
||||
"database": "trading_bot",
|
||||
"user": "trading_user",
|
||||
"password": "trading_pass_dev",
|
||||
"ssl": false,
|
||||
"poolSize": 20,
|
||||
"connectionTimeout": 30000,
|
||||
"idleTimeout": 10000
|
||||
},
|
||||
"questdb": {
|
||||
"host": "localhost",
|
||||
"ilpPort": 9009,
|
||||
"httpPort": 9000,
|
||||
"pgPort": 8812,
|
||||
"database": "questdb",
|
||||
"user": "admin",
|
||||
"password": "quest",
|
||||
"bufferSize": 65536,
|
||||
"flushInterval": 1000
|
||||
},
|
||||
"mongodb": {
|
||||
"uri": "mongodb://trading_admin:trading_mongo_dev@localhost:27017/stock?authSource=admin",
|
||||
"database": "stock",
|
||||
"poolSize": 20
|
||||
},
|
||||
"dragonfly": {
|
||||
"host": "localhost",
|
||||
"port": 6379,
|
||||
"db": 0,
|
||||
"keyPrefix": "stock-bot:",
|
||||
"maxRetries": 3,
|
||||
"retryDelay": 100
|
||||
}
|
||||
},
|
||||
"log": {
|
||||
"level": "info",
|
||||
"format": "json",
|
||||
"hideObject": false,
|
||||
"loki": {
|
||||
"enabled": false,
|
||||
"host": "localhost",
|
||||
"port": 3100,
|
||||
"labels": {}
|
||||
}
|
||||
},
|
||||
"redis": {
|
||||
"enabled": true,
|
||||
"host": "localhost",
|
||||
"port": 6379,
|
||||
"db": 0
|
||||
},
|
||||
"queue": {
|
||||
"enabled": true,
|
||||
"redis": {
|
||||
"host": "localhost",
|
||||
"port": 6379,
|
||||
"db": 1
|
||||
},
|
||||
"workers": 5,
|
||||
"concurrency": 2,
|
||||
"enableScheduledJobs": true,
|
||||
"delayWorkerStart": false,
|
||||
"defaultJobOptions": {
|
||||
"attempts": 3,
|
||||
"backoff": {
|
||||
"type": "exponential",
|
||||
"delay": 1000
|
||||
},
|
||||
"removeOnComplete": 100,
|
||||
"removeOnFail": 50,
|
||||
"timeout": 300000
|
||||
}
|
||||
},
|
||||
"http": {
|
||||
"timeout": 30000,
|
||||
"retries": 3,
|
||||
"retryDelay": 1000,
|
||||
"userAgent": "StockBot/1.0",
|
||||
"proxy": {
|
||||
"enabled": false
|
||||
}
|
||||
},
|
||||
"webshare": {
|
||||
"apiKey": "",
|
||||
"apiUrl": "https://proxy.webshare.io/api/v2/",
|
||||
"enabled": true
|
||||
},
|
||||
"browser": {
|
||||
"headless": true,
|
||||
"timeout": 30000
|
||||
},
|
||||
"proxy": {
|
||||
"cachePrefix": "proxy:",
|
||||
"ttl": 3600
|
||||
},
|
||||
"providers": {
|
||||
"yahoo": {
|
||||
"name": "yahoo",
|
||||
"enabled": true,
|
||||
"priority": 1,
|
||||
"rateLimit": {
|
||||
"maxRequests": 5,
|
||||
"windowMs": 60000
|
||||
},
|
||||
"timeout": 30000,
|
||||
"baseUrl": "https://query1.finance.yahoo.com"
|
||||
},
|
||||
"qm": {
|
||||
"name": "qm",
|
||||
"enabled": false,
|
||||
"priority": 2,
|
||||
"username": "",
|
||||
"password": "",
|
||||
"baseUrl": "https://app.quotemedia.com/quotetools",
|
||||
"webmasterId": ""
|
||||
},
|
||||
"ib": {
|
||||
"name": "ib",
|
||||
"enabled": false,
|
||||
"priority": 3,
|
||||
"gateway": {
|
||||
"host": "localhost",
|
||||
"port": 5000,
|
||||
"clientId": 1
|
||||
},
|
||||
"marketDataType": "delayed"
|
||||
},
|
||||
"eod": {
|
||||
"name": "eod",
|
||||
"enabled": false,
|
||||
"priority": 4,
|
||||
"apiKey": "",
|
||||
"baseUrl": "https://eodhistoricaldata.com/api",
|
||||
"tier": "free"
|
||||
}
|
||||
},
|
||||
"features": {
|
||||
"realtime": true,
|
||||
"backtesting": true,
|
||||
"paperTrading": true,
|
||||
"autoTrading": false,
|
||||
"historicalData": true,
|
||||
"realtimeData": true,
|
||||
"fundamentalData": true,
|
||||
"newsAnalysis": false,
|
||||
"notifications": false,
|
||||
"emailAlerts": false,
|
||||
"smsAlerts": false,
|
||||
"webhookAlerts": false,
|
||||
"technicalAnalysis": true,
|
||||
"sentimentAnalysis": false,
|
||||
"patternRecognition": false,
|
||||
"riskManagement": true,
|
||||
"positionSizing": true,
|
||||
"stopLoss": true,
|
||||
"takeProfit": true
|
||||
},
|
||||
"services": {
|
||||
"dataIngestion": {
|
||||
"port": 2001,
|
||||
"workers": 4,
|
||||
"queues": {
|
||||
"ceo": { "concurrency": 2 },
|
||||
"webshare": { "concurrency": 1 },
|
||||
"qm": { "concurrency": 2 },
|
||||
"ib": { "concurrency": 1 },
|
||||
"proxy": { "concurrency": 1 }
|
||||
},
|
||||
"rateLimit": {
|
||||
"enabled": true,
|
||||
"requestsPerSecond": 10
|
||||
}
|
||||
},
|
||||
"dataPipeline": {
|
||||
"port": 2002,
|
||||
"workers": 2,
|
||||
"batchSize": 1000,
|
||||
"processingInterval": 60000,
|
||||
"queues": {
|
||||
"exchanges": { "concurrency": 1 },
|
||||
"symbols": { "concurrency": 2 }
|
||||
},
|
||||
"syncOptions": {
|
||||
"maxRetries": 3,
|
||||
"retryDelay": 5000,
|
||||
"timeout": 300000
|
||||
}
|
||||
},
|
||||
"webApi": {
|
||||
"port": 2003,
|
||||
"rateLimitPerMinute": 60,
|
||||
"cache": {
|
||||
"ttl": 300,
|
||||
"checkPeriod": 60
|
||||
},
|
||||
"cors": {
|
||||
"origins": ["http://localhost:3000", "http://localhost:4200"],
|
||||
"credentials": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
apps/stock/config/config/development.json
Normal file
11
apps/stock/config/config/development.json
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"environment": "development",
|
||||
"log": {
|
||||
"level": "debug",
|
||||
"format": "pretty"
|
||||
},
|
||||
"features": {
|
||||
"autoTrading": false,
|
||||
"paperTrading": true
|
||||
}
|
||||
}
|
||||
42
apps/stock/config/config/production.json
Normal file
42
apps/stock/config/config/production.json
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
"environment": "production",
|
||||
"log": {
|
||||
"level": "warn",
|
||||
"format": "json",
|
||||
"loki": {
|
||||
"enabled": true,
|
||||
"host": "loki.production.example.com",
|
||||
"port": 3100
|
||||
}
|
||||
},
|
||||
"database": {
|
||||
"postgres": {
|
||||
"host": "postgres.production.example.com",
|
||||
"ssl": true,
|
||||
"poolSize": 50
|
||||
},
|
||||
"questdb": {
|
||||
"host": "questdb.production.example.com"
|
||||
},
|
||||
"mongodb": {
|
||||
"uri": "mongodb+srv://prod_user:prod_pass@cluster.mongodb.net/stock?retryWrites=true&w=majority",
|
||||
"poolSize": 50
|
||||
},
|
||||
"dragonfly": {
|
||||
"host": "redis.production.example.com",
|
||||
"password": "production_redis_password"
|
||||
}
|
||||
},
|
||||
"queue": {
|
||||
"redis": {
|
||||
"host": "redis.production.example.com",
|
||||
"password": "production_redis_password"
|
||||
}
|
||||
},
|
||||
"features": {
|
||||
"autoTrading": true,
|
||||
"notifications": true,
|
||||
"emailAlerts": true,
|
||||
"webhookAlerts": true
|
||||
}
|
||||
}
|
||||
22
apps/stock/config/package.json
Normal file
22
apps/stock/config/package.json
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "@stock-bot/stock-config",
|
||||
"version": "1.0.0",
|
||||
"description": "Stock trading bot configuration",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"clean": "rm -rf dist",
|
||||
"dev": "tsc --watch",
|
||||
"test": "jest",
|
||||
"lint": "eslint src --ext .ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@stock-bot/config": "*",
|
||||
"zod": "^3.22.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.11.0",
|
||||
"typescript": "^5.3.3"
|
||||
}
|
||||
}
|
||||
83
apps/stock/config/src/config-instance.ts
Normal file
83
apps/stock/config/src/config-instance.ts
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
import { ConfigManager, createAppConfig } from '@stock-bot/config';
|
||||
import { stockAppSchema, type StockAppConfig } from './schemas';
|
||||
import * as path from 'path';
|
||||
|
||||
let configInstance: ConfigManager<StockAppConfig> | null = null;
|
||||
|
||||
/**
|
||||
* Initialize the stock application configuration
|
||||
* @param serviceName - Optional service name to override port configuration
|
||||
*/
|
||||
export function initializeStockConfig(serviceName?: 'dataIngestion' | 'dataPipeline' | 'webApi'): StockAppConfig {
|
||||
try {
|
||||
if (!configInstance) {
|
||||
configInstance = createAppConfig(stockAppSchema, {
|
||||
configPath: path.join(__dirname, '../config'),
|
||||
});
|
||||
}
|
||||
|
||||
const config = configInstance.initialize(stockAppSchema);
|
||||
|
||||
// If a service name is provided, override the service port
|
||||
if (serviceName && config.services?.[serviceName]) {
|
||||
return {
|
||||
...config,
|
||||
service: {
|
||||
...config.service,
|
||||
port: config.services[serviceName].port,
|
||||
name: serviceName.replace(/([A-Z])/g, '-$1').toLowerCase() // Convert camelCase to kebab-case
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return config;
|
||||
} catch (error: any) {
|
||||
console.error('Failed to initialize stock configuration:', error.message);
|
||||
if (error.errors) {
|
||||
console.error('Validation errors:', JSON.stringify(error.errors, null, 2));
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current stock configuration
|
||||
*/
|
||||
export function getStockConfig(): StockAppConfig {
|
||||
if (!configInstance) {
|
||||
// Auto-initialize if not already done
|
||||
return initializeStockConfig();
|
||||
}
|
||||
return configInstance.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration for a specific service
|
||||
*/
|
||||
export function getServiceConfig(service: 'dataIngestion' | 'dataPipeline' | 'webApi') {
|
||||
const config = getStockConfig();
|
||||
return config.services?.[service];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration for a specific provider
|
||||
*/
|
||||
export function getProviderConfig(provider: 'eod' | 'ib' | 'qm' | 'yahoo') {
|
||||
const config = getStockConfig();
|
||||
return config.providers[provider];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a feature is enabled
|
||||
*/
|
||||
export function isFeatureEnabled(feature: keyof StockAppConfig['features']): boolean {
|
||||
const config = getStockConfig();
|
||||
return config.features[feature];
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset configuration (useful for testing)
|
||||
*/
|
||||
export function resetStockConfig(): void {
|
||||
configInstance = null;
|
||||
}
|
||||
15
apps/stock/config/src/index.ts
Normal file
15
apps/stock/config/src/index.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// Export schemas
|
||||
export * from './schemas';
|
||||
|
||||
// Export config instance functions
|
||||
export {
|
||||
initializeStockConfig,
|
||||
getStockConfig,
|
||||
getServiceConfig,
|
||||
getProviderConfig,
|
||||
isFeatureEnabled,
|
||||
resetStockConfig,
|
||||
} from './config-instance';
|
||||
|
||||
// Re-export type for convenience
|
||||
export type { StockAppConfig } from './schemas/stock-app.schema';
|
||||
35
apps/stock/config/src/schemas/features.schema.ts
Normal file
35
apps/stock/config/src/schemas/features.schema.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { z } from 'zod';
|
||||
|
||||
/**
|
||||
* Feature flags for the stock trading application
|
||||
*/
|
||||
export const featuresSchema = z.object({
|
||||
// Trading features
|
||||
realtime: z.boolean().default(true),
|
||||
backtesting: z.boolean().default(true),
|
||||
paperTrading: z.boolean().default(true),
|
||||
autoTrading: z.boolean().default(false),
|
||||
|
||||
// Data features
|
||||
historicalData: z.boolean().default(true),
|
||||
realtimeData: z.boolean().default(true),
|
||||
fundamentalData: z.boolean().default(true),
|
||||
newsAnalysis: z.boolean().default(false),
|
||||
|
||||
// Notification features
|
||||
notifications: z.boolean().default(false),
|
||||
emailAlerts: z.boolean().default(false),
|
||||
smsAlerts: z.boolean().default(false),
|
||||
webhookAlerts: z.boolean().default(false),
|
||||
|
||||
// Analysis features
|
||||
technicalAnalysis: z.boolean().default(true),
|
||||
sentimentAnalysis: z.boolean().default(false),
|
||||
patternRecognition: z.boolean().default(false),
|
||||
|
||||
// Risk management
|
||||
riskManagement: z.boolean().default(true),
|
||||
positionSizing: z.boolean().default(true),
|
||||
stopLoss: z.boolean().default(true),
|
||||
takeProfit: z.boolean().default(true),
|
||||
});
|
||||
3
apps/stock/config/src/schemas/index.ts
Normal file
3
apps/stock/config/src/schemas/index.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export * from './stock-app.schema';
|
||||
export * from './providers.schema';
|
||||
export * from './features.schema';
|
||||
67
apps/stock/config/src/schemas/providers.schema.ts
Normal file
67
apps/stock/config/src/schemas/providers.schema.ts
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import { z } from 'zod';
|
||||
|
||||
// Base provider configuration
|
||||
export const baseProviderConfigSchema = z.object({
|
||||
name: z.string(),
|
||||
enabled: z.boolean().default(true),
|
||||
priority: z.number().default(0),
|
||||
rateLimit: z
|
||||
.object({
|
||||
maxRequests: z.number().default(100),
|
||||
windowMs: z.number().default(60000),
|
||||
})
|
||||
.optional(),
|
||||
timeout: z.number().default(30000),
|
||||
retries: z.number().default(3),
|
||||
});
|
||||
|
||||
// EOD Historical Data provider
|
||||
export const eodProviderConfigSchema = baseProviderConfigSchema.extend({
|
||||
apiKey: z.string(),
|
||||
baseUrl: z.string().default('https://eodhistoricaldata.com/api'),
|
||||
tier: z.enum(['free', 'fundamentals', 'all-in-one']).default('free'),
|
||||
});
|
||||
|
||||
// Interactive Brokers provider
|
||||
export const ibProviderConfigSchema = baseProviderConfigSchema.extend({
|
||||
gateway: z.object({
|
||||
host: z.string().default('localhost'),
|
||||
port: z.number().default(5000),
|
||||
clientId: z.number().default(1),
|
||||
}),
|
||||
account: z.string().optional(),
|
||||
marketDataType: z.enum(['live', 'delayed', 'frozen']).default('delayed'),
|
||||
});
|
||||
|
||||
// QuoteMedia provider
|
||||
export const qmProviderConfigSchema = baseProviderConfigSchema.extend({
|
||||
username: z.string(),
|
||||
password: z.string(),
|
||||
baseUrl: z.string().default('https://app.quotemedia.com/quotetools'),
|
||||
webmasterId: z.string(),
|
||||
});
|
||||
|
||||
// Yahoo Finance provider
|
||||
export const yahooProviderConfigSchema = baseProviderConfigSchema.extend({
|
||||
baseUrl: z.string().default('https://query1.finance.yahoo.com'),
|
||||
cookieJar: z.boolean().default(true),
|
||||
crumb: z.string().optional(),
|
||||
});
|
||||
|
||||
// Combined provider configuration
|
||||
export const providersSchema = z.object({
|
||||
eod: eodProviderConfigSchema.optional(),
|
||||
ib: ibProviderConfigSchema.optional(),
|
||||
qm: qmProviderConfigSchema.optional(),
|
||||
yahoo: yahooProviderConfigSchema.optional(),
|
||||
});
|
||||
|
||||
// Dynamic provider configuration type
|
||||
export type ProviderName = 'eod' | 'ib' | 'qm' | 'yahoo';
|
||||
|
||||
export const providerSchemas = {
|
||||
eod: eodProviderConfigSchema,
|
||||
ib: ibProviderConfigSchema,
|
||||
qm: qmProviderConfigSchema,
|
||||
yahoo: yahooProviderConfigSchema,
|
||||
} as const;
|
||||
72
apps/stock/config/src/schemas/stock-app.schema.ts
Normal file
72
apps/stock/config/src/schemas/stock-app.schema.ts
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import { z } from 'zod';
|
||||
import {
|
||||
baseAppSchema,
|
||||
postgresConfigSchema,
|
||||
mongodbConfigSchema,
|
||||
questdbConfigSchema,
|
||||
dragonflyConfigSchema
|
||||
} from '@stock-bot/config';
|
||||
import { providersSchema } from './providers.schema';
|
||||
import { featuresSchema } from './features.schema';
|
||||
|
||||
/**
|
||||
* Stock trading application configuration schema
|
||||
*/
|
||||
export const stockAppSchema = baseAppSchema.extend({
|
||||
// Stock app uses all databases
|
||||
database: z.object({
|
||||
postgres: postgresConfigSchema,
|
||||
mongodb: mongodbConfigSchema,
|
||||
questdb: questdbConfigSchema,
|
||||
dragonfly: dragonflyConfigSchema,
|
||||
}),
|
||||
|
||||
// Stock-specific providers
|
||||
providers: providersSchema,
|
||||
|
||||
// Feature flags
|
||||
features: featuresSchema,
|
||||
|
||||
// Service-specific configurations
|
||||
services: z.object({
|
||||
dataIngestion: z.object({
|
||||
port: z.number().default(2001),
|
||||
workers: z.number().default(4),
|
||||
queues: z.record(z.object({
|
||||
concurrency: z.number().default(1),
|
||||
})).optional(),
|
||||
rateLimit: z.object({
|
||||
enabled: z.boolean().default(true),
|
||||
requestsPerSecond: z.number().default(10),
|
||||
}).optional(),
|
||||
}).optional(),
|
||||
dataPipeline: z.object({
|
||||
port: z.number().default(2002),
|
||||
workers: z.number().default(2),
|
||||
batchSize: z.number().default(1000),
|
||||
processingInterval: z.number().default(60000),
|
||||
queues: z.record(z.object({
|
||||
concurrency: z.number().default(1),
|
||||
})).optional(),
|
||||
syncOptions: z.object({
|
||||
maxRetries: z.number().default(3),
|
||||
retryDelay: z.number().default(5000),
|
||||
timeout: z.number().default(300000),
|
||||
}).optional(),
|
||||
}).optional(),
|
||||
webApi: z.object({
|
||||
port: z.number().default(2003),
|
||||
rateLimitPerMinute: z.number().default(60),
|
||||
cache: z.object({
|
||||
ttl: z.number().default(300),
|
||||
checkPeriod: z.number().default(60),
|
||||
}).optional(),
|
||||
cors: z.object({
|
||||
origins: z.array(z.string()).default(['http://localhost:3000']),
|
||||
credentials: z.boolean().default(true),
|
||||
}).optional(),
|
||||
}).optional(),
|
||||
}).optional(),
|
||||
});
|
||||
|
||||
export type StockAppConfig = z.infer<typeof stockAppSchema>;
|
||||
15
apps/stock/config/tsconfig.json
Normal file
15
apps/stock/config/tsconfig.json
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"composite": true,
|
||||
"declaration": true,
|
||||
"declarationMap": true
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist", "**/*.test.ts"],
|
||||
"references": [
|
||||
{ "path": "../../../libs/core/config" }
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue