stock-bot/libs/config
2025-06-04 10:50:05 -04:00
..
src deleted a lot of the stuff 2025-06-04 10:50:05 -04:00
.env.example no idea- added loki and other stuff to market-data-gateway, also added config lib 2025-06-03 11:37:58 -04:00
.env.production.example no idea- added loki and other stuff to market-data-gateway, also added config lib 2025-06-03 11:37:58 -04:00
package.json added working config lib 2025-06-03 14:09:31 -04:00
README.md fixed some issues in config service 2025-06-03 12:14:38 -04:00
setup.bat no idea- added loki and other stuff to market-data-gateway, also added config lib 2025-06-03 11:37:58 -04:00
test-config.mjs final config changes 2025-06-03 14:18:03 -04:00
tsconfig.json updated files 2025-06-03 18:02:15 -04:00
USAGE.md final config changes 2025-06-03 14:18:03 -04:00
validate-config.js final config changes 2025-06-03 14:18:03 -04:00

@stock-bot/config

A configuration management library for the Stock Bot trading platform.

Overview

This library provides a centralized way to manage configurations across all Stock Bot microservices and components. It includes:

  • Environment-based configuration loading
  • Strong TypeScript typing and validation using Zod
  • Default configurations for services
  • Environment variable parsing helpers
  • Service-specific configuration modules

Usage

Basic Usage

import { databaseConfig, dataProviderConfigs, riskConfig } from '@stock-bot/config';

// Access database configuration
const dragonflyHost = databaseConfig.dragonfly.host;

// Access data provider configuration
const alpacaApiKey = dataProviderConfigs.providers.find(p => p.name === 'alpaca')?.apiKey;

// Access risk configuration
const maxPositionSize = riskConfig.maxPositionSize;

Service-Specific Configuration

import { marketDataGatewayConfig, riskGuardianConfig } from '@stock-bot/config';

// Access Market Data Gateway configuration
const websocketPath = marketDataGatewayConfig.websocket.path;

// Access Risk Guardian configuration
const preTradeValidation = riskGuardianConfig.riskChecks.preTradeValidation;

Environment Variables

The library automatically loads environment variables from .env files. You can create environment-specific files:

  • .env - Base environment variables
  • .env.development - Development-specific variables
  • .env.production - Production-specific variables
  • .env.local - Local overrides (not to be committed to git)

Configuration Modules

Core Configuration

  • Environment - Enum for different environments
  • loadEnvVariables() - Load environment variables from .env files
  • getEnvironment() - Get the current environment
  • validateConfig() - Validate configuration with Zod schema

Database Configuration

  • databaseConfig - Database connection settings (Dragonfly, QuestDB, MongoDB, PostgreSQL)

Data Provider Configuration

  • dataProviderConfigs - Settings for market data providers

Risk Configuration

  • riskConfig - Risk management parameters (max drawdown, position size, etc.)

Service-Specific Configuration

  • marketDataGatewayConfig - Configs for the Market Data Gateway service
  • riskGuardianConfig - Configs for the Risk Guardian service

Extending

To add a new service configuration:

  1. Create a new file in src/services/
  2. Define a Zod schema for validation
  3. Create loading and default configuration functions
  4. Export from src/services/index.ts
  5. The new configuration will be automatically available from the main package

Development

# Install dependencies
bun install

# Run tests
bun test

# Type check
bun run type-check

# Lint
bun run lint