This commit is contained in:
Bojan Kucera 2025-06-04 22:46:01 -04:00
parent 7993148a95
commit 528be93804
38 changed files with 4617 additions and 1081 deletions

View file

@ -0,0 +1,54 @@
/**
* Processing Service - Technical indicators and data processing
*/
import { createLogger } from '@stock-bot/logger';
import { loadEnvVariables } from '@stock-bot/config';
import { Hono } from 'hono';
import { serve } from '@hono/node-server';
// Load environment variables
loadEnvVariables();
const app = new Hono();
const logger = createLogger('processing-service');
const PORT = parseInt(process.env.PROCESSING_SERVICE_PORT || '3003');
// Health check endpoint
app.get('/health', (c) => {
return c.json({
service: 'processing-service',
status: 'healthy',
timestamp: new Date().toISOString()
});
});
// Technical indicators endpoint
app.post('/api/indicators', async (c) => {
const body = await c.req.json();
logger.info('Technical indicators request', { indicators: body.indicators });
// TODO: Implement technical indicators processing
return c.json({
message: 'Technical indicators endpoint - not implemented yet',
requestedIndicators: body.indicators
});
});
// Vectorized processing endpoint
app.post('/api/vectorized/process', async (c) => {
const body = await c.req.json();
logger.info('Vectorized processing request', { dataPoints: body.data?.length });
// TODO: Implement vectorized processing
return c.json({
message: 'Vectorized processing endpoint - not implemented yet'
});
});
// Start server
serve({
fetch: app.fetch,
port: PORT,
});
logger.info(`Processing Service started on port ${PORT}`);

View file

@ -0,0 +1,82 @@
/**
* Technical Indicators Service
* Leverages @stock-bot/utils for calculations
*/
import { createLogger } from '@stock-bot/logger';
import {
sma,
ema,
rsi,
macd
} from '@stock-bot/utils';
const logger = createLogger('indicators-service');
export interface IndicatorRequest {
symbol: string;
data: number[];
indicators: string[];
parameters?: Record<string, any>;
}
export interface IndicatorResult {
symbol: string;
timestamp: Date;
indicators: Record<string, number[]>;
}
export class IndicatorsService {
async calculateIndicators(request: IndicatorRequest): Promise<IndicatorResult> {
logger.info('Calculating indicators', {
symbol: request.symbol,
indicators: request.indicators,
dataPoints: request.data.length
});
const results: Record<string, number[]> = {};
for (const indicator of request.indicators) {
try {
switch (indicator.toLowerCase()) {
case 'sma':
const smaPeriod = request.parameters?.smaPeriod || 20;
results.sma = sma(request.data, smaPeriod);
break;
case 'ema':
const emaPeriod = request.parameters?.emaPeriod || 20;
results.ema = ema(request.data, emaPeriod);
break;
case 'rsi':
const rsiPeriod = request.parameters?.rsiPeriod || 14;
results.rsi = rsi(request.data, rsiPeriod);
break;
case 'macd':
const fast = request.parameters?.macdFast || 12;
const slow = request.parameters?.macdSlow || 26;
const signal = request.parameters?.macdSignal || 9;
results.macd = macd(request.data, fast, slow, signal).macd;
break;
case 'stochastic':
// TODO: Implement stochastic oscillator
logger.warn('Stochastic oscillator not implemented yet');
break;
default:
logger.warn('Unknown indicator requested', { indicator });
}
} catch (error) {
logger.error('Error calculating indicator', { indicator, error });
}
}
return {
symbol: request.symbol,
timestamp: new Date(),
indicators: results
};
}
}