stock-bot/libs/api-client
2025-06-03 11:49:45 -04:00
..
src adding data-services 2025-06-03 07:42:48 -04:00
package.json adding data-services 2025-06-03 07:42:48 -04:00
README.md adding data-services 2025-06-03 07:42:48 -04:00
tsconfig.json standardized tsconfigs 2025-06-03 11:49:45 -04:00

API Client Library

Type-safe HTTP clients for inter-service communication in the stock-bot project.

Available Clients

BacktestClient

Client for interacting with the Backtest Engine service:

import { createBacktestClient } from '@stock-bot/api-client';

// Create a client instance
const backtestClient = createBacktestClient('http://localhost:4002');

// Run a backtest
const result = await backtestClient.runBacktest({
  strategyId: '123',
  startDate: new Date('2023-01-01'),
  endDate: new Date('2023-12-31'),
  symbols: ['AAPL', 'MSFT', 'GOOG'],
  initialCapital: 100000,
  parameters: {
    riskFactor: 0.5,
    positionSizeLimit: 0.1
  }
});

StrategyClient

Client for interacting with the Strategy Orchestrator service:

import { createStrategyClient } from '@stock-bot/api-client';

// Create a client instance
const strategyClient = createStrategyClient('http://localhost:4001');

// Get a strategy by ID
const strategy = await strategyClient.getStrategy('123');

// Update a strategy
await strategyClient.updateStrategy('123', {
  parameters: {
    lookbackPeriod: 20,
    threshold: 0.02
  }
});

// Enable a strategy
await strategyClient.enableStrategy('123');

Creating Custom Clients

Extend the BaseApiClient to create clients for other services:

import { BaseApiClient } from '@stock-bot/api-client';

class RiskGuardianClient extends BaseApiClient {
  async getRiskLimits(portfolioId: string) {
    return this.client.get(`/api/risk/limits/${portfolioId}`);
  }
}