Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/trading-strategies/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './backtest/index.js';
export * from './strategy/index.js';
export * from './strategy-graph/index.js';
export * from './trader/index.js';
export {BuyOnceStrategy, BuyOnceSchema, type BuyOnceConfig} from './strategy-buy-once/BuyOnceStrategy.js';
/** @deprecated Use {@link BuyOnceStrategy} without `buyAt` instead. */
Expand Down
31 changes: 31 additions & 0 deletions packages/trading-strategies/src/strategy-graph/GraphSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {z} from 'zod';

/**
* A strategy expressed as data instead of code: the same JSON drives the visual editor,
* validation, sharing, and the {@link GraphStrategy} interpreter, so what users see on
* the canvas is exactly what runs in a backtest or live session.
*/
export const StrategyGraphSchema = z.object({
connections: z.array(
z.object({
from: z.object({node: z.string().min(1), port: z.string().min(1).default('out')}),
to: z.object({node: z.string().min(1), port: z.string().min(1).default('in')}),
})
),
name: z.string().optional(),
nodes: z.record(
z.string().min(1),
z.object({
config: z.record(z.string(), z.unknown()).optional(),
/** Canvas coordinates for the visual editor. Ignored by the interpreter. */
position: z.object({x: z.number(), y: z.number()}).optional(),
type: z.string().min(1),
})
),
version: z.literal(1),
});

export type StrategyGraph = z.infer<typeof StrategyGraphSchema>;
export type StrategyGraphInput = z.input<typeof StrategyGraphSchema>;
export type GraphNode = StrategyGraph['nodes'][string];
export type GraphConnection = StrategyGraph['connections'][number];
Loading