2.6 KiB
2.6 KiB
Migration Guide: From packages to libs
This guide will help you migrate your service to use the new library structure for better separation of concerns.
Steps for each service
- Update your
package.jsondependencies to use the new libraries:
"dependencies": {
- "@stock-bot/shared-types": "workspace:*",
+ "@stock-bot/shared-types": "workspace:*",
+ "@stock-bot/utils": "workspace:*",
+ "@stock-bot/event-bus": "workspace:*",
+ "@stock-bot/api-client": "workspace:*",
...
}
- Update your imports to use the domain-specific modules:
- import { OHLCV, Strategy, Order } from '@stock-bot/shared-types';
+ import { OHLCV } from '@stock-bot/shared-types';
+ import { Strategy } from '@stock-bot/shared-types';
+ import { Order } from '@stock-bot/shared-types';
For logging:
- // Custom logging or console.log usage
+ import { createLogger, LogLevel } from '@stock-bot/utils';
+
+ const logger = createLogger('your-service-name');
+ logger.info('Message');
For API client usage:
- // Manual axios calls
+ import { createBacktestClient, createStrategyClient } from '@stock-bot/api-client';
+
+ const backtestClient = createBacktestClient();
+ const result = await backtestClient.runBacktest(config);
For event-based communication:
- // Manual Redis/Dragonfly usage
+ import { createEventBus } from '@stock-bot/event-bus';
+ import { MarketDataEvent } from '@stock-bot/shared-types';
+
+ const eventBus = createEventBus({
+ redisHost: process.env.REDIS_HOST || 'localhost',
+ redisPort: parseInt(process.env.REDIS_PORT || '6379')
+ });
+
+ eventBus.subscribe('market.data', async (event) => {
+ // Handle event
+ });
Example: Updating BacktestEngine
// Before
import { Strategy, BacktestConfig } from '@stock-bot/shared-types';
import Redis from 'ioredis';
// After
import { Strategy } from '@stock-bot/shared-types';
import { BacktestConfig } from '@stock-bot/shared-types';
import { createLogger } from '@stock-bot/utils';
import { createEventBus } from '@stock-bot/event-bus';
const logger = createLogger('backtest-engine');
const eventBus = createEventBus({
redisHost: process.env.REDIS_HOST || 'localhost',
redisPort: parseInt(process.env.REDIS_PORT || '6379')
});
Updating build scripts
If your turbo.json configuration references specific packages, update the dependencies:
"backtest": {
"dependsOn": [
"^build",
- "packages/shared-types#build"
+ "libs/shared-types#build",
+ "libs/utils#build",
+ "libs/event-bus#build",
+ "libs/api-client#build"
],
}