commit 2 refactor

This commit is contained in:
Boki 2026-10-20 14:35:45 -04:00
parent 588f666943
commit 32e43c9243
310 changed files with 33318 additions and 31189 deletions

View file

@ -0,0 +1 @@
export { at, defined } from '@stock-bot/invariants';

View file

@ -92,8 +92,8 @@ export function analyzePortfolio(
_benchmarkReturns?: number[],
_riskFreeRate: number = 0.02
): {
performance: any;
risk: any;
performance: Record<string, unknown>;
risk: Record<string, unknown>;
} {
// Note: Implementation depends on performance-metrics and risk-metrics
// This is a placeholder for the full implementation

View file

@ -1,3 +1,4 @@
import { defined } from '@stock-bot/invariants';
/**
* Technical Indicators
* Comprehensive set of technical analysis indicators
@ -807,7 +808,7 @@ export function ichimoku(
}
// Chikou Span (Lagging Span)
chikouSpan.push(ohlcv[i]!.close);
chikouSpan.push(defined(ohlcv[i]).close);
}
return {
@ -837,13 +838,13 @@ export function ultimateOscillator(
// Calculate BP and TR
for (let i = 0; i < ohlcv.length; i++) {
const current = ohlcv[i]!;
const current = defined(ohlcv[i]);
if (i === 0) {
bp.push(current.close - current.low);
tr.push(current.high - current.low);
} else {
const previous = ohlcv[i - 1]!;
const previous = defined(ohlcv[i - 1]);
bp.push(current.close - Math.min(current.low, previous.close));
tr.push(
Math.max(
@ -886,8 +887,8 @@ export function easeOfMovement(ohlcv: OHLCV[], period: number = 14): number[] {
const emv: number[] = [];
for (let i = 1; i < ohlcv.length; i++) {
const current = ohlcv[i]!;
const previous = ohlcv[i - 1]!;
const current = defined(ohlcv[i]);
const previous = defined(ohlcv[i - 1]);
const distance = (current.high + current.low) / 2 - (previous.high + previous.low) / 2;
const boxHeight = current.high - current.low;
@ -1030,8 +1031,8 @@ export function klingerVolumeOscillator(
const volumeForce: number[] = [];
for (let i = 1; i < ohlcv.length; i++) {
const current = ohlcv[i]!;
const previous = ohlcv[i - 1]!;
const current = defined(ohlcv[i]);
const previous = defined(ohlcv[i - 1]);
const typicalPrice = (current.high + current.low + current.close) / 3;
const prevTypicalPrice = (previous.high + previous.low + previous.close) / 3;
@ -1164,7 +1165,7 @@ export function stochasticRSI(
const slice = rsiValues.slice(i - stochPeriod + 1, i + 1);
const highest = Math.max(...slice);
const lowest = Math.min(...slice);
const currentRSI = rsiValues[i]!;
const currentRSI = defined(rsiValues[i]);
if (highest === lowest) {
stochRSI.push(0);
@ -1196,8 +1197,8 @@ export function vortexIndicator(
const tr: number[] = [];
for (let i = 1; i < ohlcv.length; i++) {
const current = ohlcv[i]!;
const previous = ohlcv[i - 1]!;
const current = defined(ohlcv[i]);
const previous = defined(ohlcv[i - 1]);
// Vortex Movement
vm_plus.push(Math.abs(current.high - previous.low));

View file

@ -1,3 +1,5 @@
import type { LoggerLike } from '@stock-bot/logger';
/**
* Enhanced fetch wrapper with proxy support and automatic debug logging
* Drop-in replacement for native fetch with additional features
@ -8,7 +10,7 @@ export interface BunRequestInit extends RequestInit {
}
export interface FetchOptions extends RequestInit {
logger?: any;
logger?: LoggerLike;
proxy?: string | null;
timeout?: number;
}
@ -61,7 +63,7 @@ export async function fetch(input: RequestInfo | URL, options?: FetchOptions): P
async function performFetch(
input: RequestInfo | URL,
requestOptions: RequestInit,
logger: any,
logger: LoggerLike,
url: string
): Promise<Response> {
logger.debug('HTTP request', {

View file

@ -1,3 +1,4 @@
import { defined } from '@stock-bot/invariants';
/**
* Generic utility functions that work with standardized types
* These functions demonstrate how to use generic types with OHLCV data
@ -69,10 +70,10 @@ export function calculateTrueRange<T extends HasOHLC>(data: T[]): number[] {
for (let i = 0; i < data.length; i++) {
if (i === 0) {
result.push(data[i]!.high - data[i]!.low);
result.push(defined(data[i]).high - defined(data[i]).low);
} else {
const current = data[i]!;
const previous = data[i - 1]!;
const current = defined(data[i]);
const previous = defined(data[i - 1]);
const tr = Math.max(
current.high - current.low,
Math.abs(current.high - previous.close),
@ -93,8 +94,8 @@ export function calculateReturns<T extends HasClose>(data: T[]): number[] {
const returns: number[] = [];
for (let i = 1; i < closes.length; i++) {
const current = closes[i]!;
const previous = closes[i - 1]!;
const current = defined(closes[i]);
const previous = defined(closes[i - 1]);
if (previous > 0) {
returns.push((current - previous) / previous);
} else {
@ -113,8 +114,8 @@ export function calculateLogReturns<T extends HasClose>(data: T[]): number[] {
const logReturns: number[] = [];
for (let i = 1; i < closes.length; i++) {
const current = closes[i]!;
const previous = closes[i - 1]!;
const current = defined(closes[i]);
const previous = defined(closes[i - 1]);
if (previous > 0 && current > 0) {
logReturns.push(Math.log(current / previous));
} else {
@ -172,7 +173,7 @@ export function groupBySymbol(data: OHLCV[]): Record<string, OHLCV[]> {
if (!grouped[item.symbol]) {
grouped[item.symbol] = [];
}
grouped[item.symbol]!.push(item);
defined(grouped[item.symbol]).push(item);
}
return grouped;

View file

@ -1,4 +1,5 @@
export * from './calculations/index';
export * from './assertions';
export * from './common';
export * from './dateUtils';
export * from './generic-functions';

View file

@ -1,3 +1,5 @@
import { defined } from '@stock-bot/invariants';
/**
* User Agent utility for generating random user agents
*/
@ -26,5 +28,5 @@ const USER_AGENTS = [
export function getRandomUserAgent(): string {
const index = Math.floor(Math.random() * USER_AGENTS.length);
return USER_AGENTS[index]!;
return defined(USER_AGENTS[index]);
}