82 lines
4.8 KiB
Markdown
82 lines
4.8 KiB
Markdown
# Stock Bot
|
|
|
|
Bun/TypeScript workspaces for market-data collection, processing, APIs, and a React dashboard,
|
|
with a Rust native trading engine. `apps/wcag-ada` is an independent project and is not part of
|
|
the root workspace checks.
|
|
|
|
## Build and verify
|
|
|
|
Use Bun 1.2.17, Node.js 18 or newer, and a Rust toolchain with a native linker. CI uses Rust
|
|
1.88. Building and the tooling/contract/integration checks do not require running databases or provider
|
|
credentials.
|
|
|
|
```sh
|
|
bun install --frozen-lockfile
|
|
bun run build
|
|
bun run check
|
|
```
|
|
|
|
The root build selects every buildable leaf workspace, including all stock services and the
|
|
native engine. `bun run build --dry=json` shows the actual Turbo task plan.
|
|
|
|
| Command | Scope |
|
|
| ------------------------ | ------------------------------------------------------------------------------------------- |
|
|
| `bun run build:libs` | Build shared libraries in dependency order |
|
|
| `bun run build --clean` | Force every workspace build without cached results |
|
|
| `bun run typecheck` | Check library, stock application, and tool source directly |
|
|
| `bun run test:contracts` | Compile positive and negative service-contract assertions |
|
|
| `bun run test:tooling` | Run workspace and service-consumer regression tests without infrastructure |
|
|
| `bun run test:integration` | Replay fixed prices through ingestion, storage, and the real native backtest engine |
|
|
| `bun run lint:check` | Lint stock applications, libraries, and tools with zero warnings allowed |
|
|
| `bun run check` | Run build, type checking, contract tests, tooling/integration tests, and lint; report every failed gate |
|
|
|
|
`check` exits nonzero if any gate fails. Type/lint errors are not suppressed or baselined.
|
|
The larger existing `bun run test` suite is separate:
|
|
some tests need databases, Redis, browsers, or native-engine fixes.
|
|
|
|
Native builds generate `apps/stock/engine/dist/engine.node` and `dist/index.d.ts`. The public
|
|
ESM/CommonJS loaders and declaration facade use those generated artifacts. Rebuild after
|
|
changing Rust APIs. TensorFlow is loaded only when starting the optional ML strategy.
|
|
Its TypeScript dependency is present for checking; using ML also requires installing its
|
|
platform-specific native binding. Dependency install scripts were not enabled for verification.
|
|
|
|
## Service contracts
|
|
|
|
`@stock-bot/types` contains independent domain, job, and handler types.
|
|
`@stock-bot/services` composes service capabilities from the public APIs exported by the
|
|
owning adapters. It uses type-only imports and does not initialize connections.
|
|
|
|
```ts
|
|
import type { IServiceContainer, ServiceTypes } from '@stock-bot/services';
|
|
import type { ExecutionContext } from '@stock-bot/types';
|
|
```
|
|
|
|
The DI and handler packages re-export `IServiceContainer` for existing consumers. Queue
|
|
managers and individual queues are separate capabilities: obtain queues through
|
|
`container.queueManager`, submit with `queue.add`, and await results with `queue.waitForJob`.
|
|
Use `getFullQueueName(service, handler)` when addressing another service's queue.
|
|
|
|
Use `requireServices(container, 'mongodb', 'queueManager')` at consumer boundaries when
|
|
those capabilities are required. Missing/disabled adapters fail explicitly before work begins.
|
|
`@stock-bot/invariants` provides small, dependency-free checks for required values and
|
|
indexed array reads; browser code can use it without importing server utilities.
|
|
|
|
Handler initializers receive their scanner/registry explicitly through the DI application
|
|
initialization context. WebSocket connections and completion timers belong to the socket
|
|
handler and are released on close/shutdown.
|
|
|
|
## Backtest data integrity
|
|
|
|
Historical storage no longer invents prices when a database is unavailable. Configure a
|
|
historical store, or explicitly set `services.orchestrator.backtesting.allowSyntheticData`
|
|
for offline demos, with `syntheticSeed` for repeatability. Synthetic data is disabled by
|
|
default and must not be used to assess trading performance. MongoDB's normalized EOD
|
|
store currently supports daily bars only; intraday requests require QuestDB.
|
|
|
|
The integration test uses an in-memory persistence transport and the real storage/native
|
|
engine path. It checks idempotent ingestion, invalid-price rejection, repeatable trades,
|
|
and explicit failures for missing data or unsupported strategies. No live provider or broker
|
|
is contacted. Native SMA and MACD regressions are covered by the repository checks.
|
|
|
|
Coverage reports contain measured LCOV data only. Missing coverage or an empty package
|
|
selection fails the coverage command instead of producing an estimated score.
|