stock-bot/libs/utils
2025-06-03 15:53:26 -04:00
..
src added LOKI_FLUSH_INTERVAL_MS 2025-06-03 15:29:45 -04:00
package.json no idea- added loki and other stuff to market-data-gateway, also added config lib 2025-06-03 11:37:58 -04:00
README.md adding data-services 2025-06-03 07:42:48 -04:00
tsconfig.json fixed refs 2025-06-03 15:53:26 -04:00

Utils Library

Common utility functions shared across services in the stock-bot project.

Included Utilities

Date Utilities

Helper functions for working with market dates:

import { dateUtils } from '@stock-bot/utils';

// Check if a date is a trading day
const isTradingDay = dateUtils.isTradingDay(new Date());

// Get the next trading day
const nextTradingDay = dateUtils.getNextTradingDay(new Date());

Financial Utilities

Mathematical functions for financial calculations:

import { financialUtils } from '@stock-bot/utils';

// Calculate Sharpe ratio
const returns = [0.05, 0.03, -0.01, 0.04, 0.02];
const sharpeRatio = financialUtils.calculateSharpeRatio(returns, 0.02);

// Calculate maximum drawdown
const equityCurve = [10000, 10500, 10200, 10800, 10300];
const maxDrawdown = financialUtils.calculateMaxDrawdown(equityCurve);

Logger

Standardized logging service:

import { createLogger, LogLevel } from '@stock-bot/utils';

// Create a logger for your service
const logger = createLogger('strategy-orchestrator', LogLevel.INFO);

// Log at different levels
logger.info('Strategy initialized');
logger.warn('Position size exceeds recommended limit');
logger.error('Failed to execute order', { orderId: '123', reason: 'Insufficient funds' });