# MoexClientService Split — Plan ## Подход Полный сплит по доменам (ADR-020). Один коммит — миграция всех файлов одновременно. ## Архитектура ``` modules/moex-client/ ├── moex-http.client.ts # Инфраструктура: axios, PQueue, circuit breaker ├── moex-securities.client.ts # searchSecurities(), getSecurityDescription() ├── moex-market-data.client.ts # getShareMarketData(), getShareMarketDataBatch(), │ # getBondData(), getBondMarketData(), getBondPositionDataBatch() ├── moex-candles.client.ts # getCandles() ├── moex-history.client.ts # getHistory(), getBondHistory() ├── moex-dividends.client.ts # getDividends() ├── moex-client.types.ts # (unchanged) ├── moex-client.module.ts # providers: все клиенты, exports: доменные клиенты, не @Global() ├── moex-client.service.spec.ts # → moex-http.client.spec.ts └── moex-client.service.integration.spec.ts # → интеграционные тесты ``` ## Data Flow ``` Consumer Service ↓ (DI) Domain Client (MoexSecuritiesClient | MoexMarketDataClient | etc.) ↓ (DI) MoexHttpClient (request + extractTable) ↓ MOEX ISS API ``` `MoexHttpClient` — не экспортируется из модуля, только доменные клиенты его видят. ## Consumer Updates | Модуль | Было | Стало | |--------|------|-------| | `shares/shares.module.ts` | — | `imports: [MoexClientModule]` | | `shares/shares.service.ts` | `moexClient: MoexClientService` | `moexSecurities: MoexSecuritiesClient`, `moexMarketData: MoexMarketDataClient` | | `bonds/bonds.module.ts` | — | `imports: [MoexClientModule]` | | `bonds/bonds.service.ts` | `moexClient: MoexClientService` | `moexMarketData: MoexMarketDataClient`, `moexHistory: MoexHistoryClient` | | `candles/candles.module.ts` | — | `imports: [MoexClientModule]` | | `candles/candles.service.ts` | `moexClient: MoexClientService` | `moexCandles: MoexCandlesClient` | | `securities/securities.module.ts` | — | `imports: [MoexClientModule]` | | `securities/securities.service.ts` | `moexClient: MoexClientService` | `moexSecurities: MoexSecuritiesClient`, `moexMarketData: MoexMarketDataClient` | | `securities/screener.service.ts` | `moexClient: MoexClientService` | `moexMarketData: MoexMarketDataClient` | | `portfolio/portfolio.module.ts` | — | `imports: [MoexClientModule]` | | `portfolio/portfolio.service.ts` | `moexClient: MoexClientService` | `moexSecurities: MoexSecuritiesClient`, `moexMarketData: MoexMarketDataClient`, `moexDividends: MoexDividendsClient` | | `tbank/tbank.module.ts` | `imports: [MoexClientModule]` | (unchanged) | | `tbank/.../broker-events.service.ts` | `moexClient: MoexClientService` | `moexDividends: MoexDividendsClient`, `moexMarketData: MoexMarketDataClient` | ## Migration Order 1. Создать `MoexHttpClient` — перенести инфраструктуру из `MoexClientService` 2. Создать `MoexSecuritiesClient` — перенести 2 метода 3. Создать `MoexMarketDataClient` — перенести 5 методов 4. Создать `MoexCandlesClient` — перенести 1 метод 5. Создать `MoexHistoryClient` — перенести 2 метода 6. Создать `MoexDividendsClient` — перенести 1 метод 7. Обновить `MoexClientModule` — убрать `@Global()`, новые providers/exports 8. Обновить всех потребителей (модули + сервисы + тесты) 9. Удалить старый `MoexClientService` 10. `npm run build && npm run test` ## Testing Strategy - `MoexHttpClient` — unit-тесты на circuit breaker, rate limiter, request - Каждый доменный клиент — unit-тесты с mocked `MoexHttpClient` - Существующие тесты потребителей — обновить DI-моки