removed some old stuff

This commit is contained in:
Boki 2025-06-20 13:40:44 -04:00
parent 05974cd602
commit c2420a34f1
9 changed files with 0 additions and 2197 deletions

View file

@ -1,43 +0,0 @@
# Cache Library Usage Guide
> **⚠️ DEPRECATED**: This documentation is outdated. The cache library has been simplified to only use Redis/Dragonfly.
>
> **Please see [simplified-cache-usage.md](./simplified-cache-usage.md) for current usage instructions.**
The `@stock-bot/cache` library now provides a simplified Redis-only caching solution designed specifically for trading bot applications.
## Migration from Old API
If you're migrating from the old cache API, here are the key changes:
### Old API (DEPRECATED)
```typescript
// These are no longer supported
const cache = createCache('auto');
const cache = createCache('memory');
const cache = createCache('hybrid');
const cache = createCache('redis');
// Direct imports no longer available
import { MemoryCache, HybridCache } from '@stock-bot/cache';
```
### New Simplified API
```typescript
// Use factory functions with options only
const cache = createCache({ keyPrefix: 'app:', ttl: 3600 });
const tradingCache = createTradingCache();
const marketCache = createMarketDataCache();
// Only Redis cache is available
import { RedisCache, RedisConnectionManager } from '@stock-bot/cache';
```
## Quick Migration Steps
1. **Remove cache type parameters**: Change `createCache('hybrid')` to `createCache()`
2. **Remove name parameter**: The `name` option is no longer needed
3. **Update imports**: Use named imports instead of default import
4. **Use specialized factories**: Consider using `createTradingCache()`, `createMarketDataCache()`, etc.
For complete usage examples and best practices, see [simplified-cache-usage.md](./simplified-cache-usage.md).

View file

@ -1,176 +0,0 @@
# Simplified Cache Library Usage
The cache library has been simplified to only use Redis/Dragonfly with a connection manager for better performance and easier management.
## Quick Start
```typescript
import { createCache, createTradingCache, createMarketDataCache, RedisConnectionManager } from '@stock-bot/cache';
// Create different cache instances
const generalCache = createCache({ keyPrefix: 'app:' });
const tradingCache = createTradingCache(); // Uses 'trading:' prefix
const marketCache = createMarketDataCache(); // Uses 'market:' prefix with 5min TTL
// All cache instances share connections by default for better performance
```
## Connection Management
The library now uses a connection manager that allows you to control whether services share connections or get unique ones:
```typescript
import { RedisConnectionManager } from '@stock-bot/cache';
const connectionManager = RedisConnectionManager.getInstance();
// For shared connections (recommended for most cases)
const sharedRedis = connectionManager.getConnection({
name: 'BATCH-PROCESSOR',
singleton: true // All instances share this connection
});
// For unique connections (when you need isolation)
const uniqueRedis = connectionManager.getConnection({
name: 'DATA-FETCHER',
singleton: false // Each instance gets its own connection
});
```
## Cache Usage Examples
### Basic Operations
```typescript
import { createCache } from '@stock-bot/cache';
const cache = createCache({ keyPrefix: 'myapp:' });
// Set data with default TTL (1 hour)
await cache.set('user:123', { name: 'John', email: 'john@example.com' });
// Set data with custom TTL (5 minutes)
await cache.set('session:abc', sessionData, 300);
// Get data
const user = await cache.get('user:123');
// Check if key exists
const exists = await cache.exists('user:123');
// Delete data
await cache.del('user:123');
// Clear all data with this prefix
await cache.clear();
```
### Trading-Specific Caches
```typescript
import { createTradingCache, createMarketDataCache, createIndicatorCache } from '@stock-bot/cache';
// Trading cache (1 hour TTL)
const tradingCache = createTradingCache();
await tradingCache.set('position:AAPL', { shares: 100, price: 150.00 });
// Market data cache (5 minute TTL)
const marketCache = createMarketDataCache();
await marketCache.set('quote:AAPL', { price: 151.25, volume: 1000000 });
// Indicator cache (30 minute TTL)
const indicatorCache = createIndicatorCache();
await indicatorCache.set('sma:AAPL:20', [150.1, 150.3, 150.8, 151.2]);
```
## Connection Names in Redis
When you create cache instances, they will appear in Redis with clean, identifiable names:
- `TRADING-SERVICE` - For trading cache
- `MARKET-SERVICE` - For market data cache
- `INDICATORS-SERVICE` - For indicator cache
- `CACHE-SERVICE` - For general cache
You can monitor all connections using:
```bash
# TypeScript version (more detailed)
bun run scripts/get-redis-connections.ts
# Bash version (quick check)
./scripts/get-redis-connections.sh
```
## Health Monitoring
```typescript
// Check if cache is ready
if (cache.isReady()) {
console.log('Cache is ready for operations');
}
// Wait for cache to be ready
await cache.waitForReady(5000); // Wait up to 5 seconds
// Health check
const isHealthy = await cache.health();
// Get performance statistics
const stats = cache.getStats();
console.log(`Hit rate: ${stats.hitRate}%, Total operations: ${stats.total}`);
```
## Batch Processor Example
Here's how to set up a batch processor with a shared connection:
```typescript
import { RedisConnectionManager } from '@stock-bot/cache';
import Redis from 'ioredis';
export class BatchProcessor {
private redis: Redis;
constructor() {
const connectionManager = RedisConnectionManager.getInstance();
// All batch processor instances share this connection
this.redis = connectionManager.getConnection({
name: 'BATCH-PROCESSOR',
singleton: true
});
}
async processItems(items: any[]): Promise<void> {
await this.redis.set('batch:status', 'processing');
for (const item of items) {
await this.redis.lpush('batch:queue', JSON.stringify(item));
}
await this.redis.set('batch:status', 'completed');
}
async getBatchStatus(): Promise<string> {
return await this.redis.get('batch:status') || 'idle';
}
}
```
## Key Benefits
**Simplified**: Only Redis-based caching, no complex hybrid logic
**Connection Management**: Shared connections for better performance
**Clean Monitoring**: Easy to identify connections in Redis
**Trading Optimized**: Pre-configured caches for different data types
**Type Safe**: Full TypeScript support
**Error Handling**: Graceful fallbacks and comprehensive logging
## Removed Features
**Memory Cache**: Removed to avoid consistency issues
**Hybrid Cache**: Removed unnecessary complexity
**Auto-detection**: Always uses Redis/Dragonfly now
This simplified approach provides better performance, easier debugging, and more predictable behavior for your trading application.

View file

@ -1,65 +0,0 @@
# Testing with Bun in Stock Bot Platform
The Stock Bot platform uses [Bun Test](https://bun.sh/docs/cli/test) as the primary testing framework (Updated June 2025). Bun Test provides fast, modern testing with Jest-like API compatibility.
## Getting Started
Run tests using these commands:
```cmd
# Run all tests (using Turbo)
bun test
# Run tests in watch mode
bun test:watch
# Run tests with coverage
bun test:coverage
# Run specific test types
bun test:unit
bun test:integration
bun test:e2e
```
## Library-specific Testing
Each library has its own testing configuration in a `bunfig.toml` file. This allows for library-specific test settings while maintaining consistent patterns across the codebase.
### Example bunfig.toml:
```toml
[test]
preload = ["./test/setup.ts"]
timeout = 5000
[test.env]
NODE_ENV = "test"
[bun]
paths = {
"@/*" = ["./src/*"]
}
```
## Migration from Jest
This project has been fully migrated from Jest to Bun Test. Some key differences:
1. **Import statements**: Use `import { describe, it, expect } from 'bun:test'` instead of Jest imports
2. **Mocking**: Use Bun's built-in mocking utilities (see global `spyOn` helper)
3. **Configuration**: Use `bunfig.toml` instead of Jest config files
4. **Test helpers**: Test helpers are available globally via `global.testHelpers`
## Best Practices
- Use `describe` and `it` for test organization
- Use relative imports (`../src/`) in test files
- Keep test setup clean with proper `beforeEach` and `afterEach` handlers
- For complex test scenarios, create dedicated setup files
## Test Environment
- All tests run with `NODE_ENV=test`
- Console output is silenced by default (restore with `testHelpers.restoreConsole()`)
- Default timeout is 30 seconds for integration tests, 5 seconds for unit tests

View file

@ -1,104 +0,0 @@
# TypeScript Configuration Structure
This document explains the TypeScript configuration structure used in the Stock Bot trading platform.
## Root Configuration
The root `tsconfig.json` at the project root establishes common settings for all projects in the monorepo:
```json
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"sourceMap": false,
"declaration": true,
"baseUrl": ".",
"paths": {
"@stock-bot/*": ["libs/*/src"]
}
},
"exclude": [
"node_modules",
"dist"
]
}
```
## Template Configurations
We provide two template configurations:
1. `tsconfig.app.json` - For application projects:
```json
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"module": "ESNext",
"moduleResolution": "bundler",
"types": ["bun-types"]
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
```
## Project-Specific Configurations
Each project in the monorepo extends from the root configuration and adds its own specific settings:
### Library Projects
Library projects extend the root configuration with a relative path:
```json
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"declaration": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts"]
}
```
### Application Projects
Application projects also extend the root configuration with a relative path:
```json
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"module": "ESNext",
"moduleResolution": "bundler",
"types": ["bun-types"]
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
```
## Special Configurations
Some projects have special needs:
1. **Trading Dashboard (Angular)**: Uses an extended configuration structure with separate files for app and testing.
2. **Projects with TypeScript imports from extensions**: These projects set `"allowImportingTsExtensions": true` and `"noEmit": true`.