feat(strategies): publish type-only strategy authoring API (CL31)
This commit is contained in:
parent
a411f9a665
commit
3a63b2039e
13 changed files with 300 additions and 121 deletions
|
|
@ -75,7 +75,7 @@ This fixture does not need a provider connection or running databases. For initi
|
|||
## Deeper references
|
||||
|
||||
- [Calculation library](../../libs/calculations/README.md): reviewed indicators and analytics, plus clearly separated preserved legacy functions.
|
||||
- [TypeScript strategy contract](../../apps/stock/orchestrator/src/contracts/canonical-strategy.ts): the actual callback context and output types.
|
||||
- [TypeScript strategy contract](../../libs/research/src/strategy-api.ts): the actual callback context and output types.
|
||||
- [Research product reference](../development/architecture/research-product.md): API policies, provenance and paper setup. Its original design examples and later implementation notes need to be read in context.
|
||||
- [Architecture decisions](../development/architecture/decisions): why the boundaries were chosen. These record decisions and migration context, not a substitute for the current runtime map.
|
||||
- [Backlog](../development/backlog/README.md) and [roadmap](../development/ROADMAP.md): work history, completion evidence and conditional future tasks.
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ This guide follows **functions and state**, rather than application boxes. The l
|
|||
|
||||
## 1. Begin with the decision contract
|
||||
|
||||
Open [canonical-strategy.ts](../../apps/stock/orchestrator/src/contracts/canonical-strategy.ts). `StrategyProgram` describes the object a strategy factory returns. Its `decide(context)` callback returns two things:
|
||||
Open [strategy-api.ts](../../libs/research/src/strategy-api.ts). `StrategyProgram` describes the object a strategy factory returns. Its `decide(context)` callback returns two things:
|
||||
|
||||
- `nextState`: what the strategy wants to remember for its next decision.
|
||||
- `intent`: what exposure or orders it wants the financial engine to consider.
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ A strategy is a TypeScript function that reads observations and account state, t
|
|||
|
||||
| File | What to look for |
|
||||
| --- | --- |
|
||||
| [canonical-strategy.ts](../../apps/stock/orchestrator/src/contracts/canonical-strategy.ts) | `StrategyProgram`, its `decide` callback, and the read-only `StrategyContext`. |
|
||||
| [strategy-api.ts](../../libs/research/src/strategy-api.ts) | `StrategyProgram`, its `decide` callback, and the read-only `StrategyContext`. |
|
||||
| [canonical-sma.ts](../../apps/stock/orchestrator/src/strategies/canonical-sma.ts) | A complete strategy: validated parameters, versioned state, history, crossover, target quantity. |
|
||||
| [canonical-mean-reversion.ts](../../apps/stock/orchestrator/src/strategies/canonical-mean-reversion.ts) | Trend, momentum, volatility regime, entry filters, and exits composed in TypeScript. |
|
||||
| [canonical-builtins.ts](../../apps/stock/orchestrator/src/strategies/canonical-builtins.ts) | The small built-in factory and checks binding each strategy owner to its instrument and observation series. |
|
||||
|
|
@ -33,12 +33,14 @@ Keep history in explicit state, use engine time instead of `Date.now()`, and avo
|
|||
|
||||
## A minimal callback shape
|
||||
|
||||
This is a deliberately simple **in-repository source example**, using imports as if placed beside `canonical-sma.ts`. It requests one share when its series is fresh; it is not an investment strategy or a ready-to-upload candidate package.
|
||||
Import author types from `@stock-bot/research/strategy-api`. This subpath contains only types; it exposes no native sessions, execution controllers, brokers, or storage services. Existing host imports of `contracts/canonical-strategy.ts` remain compatible.
|
||||
|
||||
This simple callback requests one share when its series is fresh. It demonstrates the authoring contract; it is not a validated investment strategy or a ready-to-upload candidate package.
|
||||
|
||||
```ts
|
||||
import { parseFinancialDecimal } from '@stock-bot/types';
|
||||
import type { RetainedProgramSelection } from '@stock-bot/stock-config/candidate-execution';
|
||||
import type { StrategyProgram } from '../contracts/canonical-strategy';
|
||||
import type { StrategyProgram } from '@stock-bot/research/strategy-api';
|
||||
|
||||
export function createStrategy(
|
||||
selection: RetainedProgramSelection
|
||||
|
|
@ -73,6 +75,8 @@ export function createStrategy(
|
|||
}
|
||||
```
|
||||
|
||||
For a self-contained source with no runtime imports, use [fresh-position.ts](../../libs/research/examples/fresh-position.ts). Its `shares` parameter must be a nonnegative safe integer; the example converts that checked integer to a fixed eight-decimal quantity. All imports erase during TypeScript transformation. [The public API tests](../../scripts/test/public-strategy-api.test.ts) compile the example outside the monorepo without path aliases, check the emitted module, and compare source and packaged decisions/state through the same Rust replay. Production candidate packaging still uses the existing isolated CLI; this test does not replace isolation or approval.
|
||||
|
||||
`quantity` is a desired **total holding for this owner**, not “buy this many more.” `parseFinancialDecimal('1')` creates the validated financial string `"1.00000000"`. Numeric arrays remain useful for features; financial postings use the decimal contract.
|
||||
|
||||
An empty target list means no new target update. An explicit zero target requests an exit. Neither guarantees a fill: Rust reconciles the target with holdings and pending orders, applies risk checks, and uses eligible future execution events. Never report a position change merely because the callback requested one.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue