feat(shared): add domain schemas implementation
This commit is contained in:
@@ -7,7 +7,8 @@
|
||||
"test": "vitest run --"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aiquant/agent-runtime": "workspace:*"
|
||||
"@aiquant/agent-runtime": "workspace:*",
|
||||
"zod": "^3.24.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.9.2",
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const experimentResultSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
strategyId: z.string().min(1),
|
||||
strategyVersion: z.number().int().positive(),
|
||||
sampleSize: z.number().int().nonnegative(),
|
||||
score: z.number(),
|
||||
netReturn: z.number(),
|
||||
maxDrawdown: z.number().nonnegative(),
|
||||
hitRate: z.number().min(0).max(1),
|
||||
evaluatedAt: z.string().datetime()
|
||||
});
|
||||
|
||||
export type ExperimentResult = z.infer<typeof experimentResultSchema>;
|
||||
@@ -0,0 +1,13 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const marketSnapshotSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
symbol: z.string().min(1),
|
||||
contractId: z.string().min(1),
|
||||
timeframe: z.string().min(1),
|
||||
observedAt: z.string().datetime(),
|
||||
price: z.number().positive(),
|
||||
volume: z.number().nonnegative().optional()
|
||||
});
|
||||
|
||||
export type MarketSnapshot = z.infer<typeof marketSnapshotSchema>;
|
||||
@@ -0,0 +1,21 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const modelCapabilitySchema = z.object({
|
||||
structuredOutputs: z.boolean().default(false),
|
||||
jsonMode: z.boolean().default(false)
|
||||
});
|
||||
|
||||
export const modelProfileSchema = z.object({
|
||||
name: z.string().min(1),
|
||||
provider: z.string().min(1),
|
||||
apiBase: z.string().url(),
|
||||
apiKeyRef: z.string().min(1),
|
||||
model: z.string().min(1),
|
||||
temperature: z.number().min(0).max(2).optional(),
|
||||
maxTokens: z.number().int().positive().optional(),
|
||||
timeoutMs: z.number().int().positive().optional(),
|
||||
capabilities: modelCapabilitySchema,
|
||||
tags: z.array(z.string().min(1)).default([])
|
||||
});
|
||||
|
||||
export type ModelProfile = z.infer<typeof modelProfileSchema>;
|
||||
@@ -0,0 +1,35 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const strategyStateSchema = z.enum([
|
||||
"draft",
|
||||
"candidate",
|
||||
"dry-run",
|
||||
"approved-for-live",
|
||||
"archived"
|
||||
]);
|
||||
|
||||
export const strategyDefinitionSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
version: z.number().int().positive(),
|
||||
name: z.string().min(1),
|
||||
state: strategyStateSchema,
|
||||
agentProfile: z.object({
|
||||
signal: z.string().min(1),
|
||||
risk: z.string().min(1),
|
||||
evaluator: z.string().min(1),
|
||||
optimizer: z.string().min(1)
|
||||
}),
|
||||
featureConfig: z.object({
|
||||
windows: z.array(z.string().min(1)).min(1)
|
||||
}),
|
||||
riskConfig: z.object({
|
||||
minConfidence: z.number().min(0).max(1)
|
||||
}),
|
||||
scoringConfig: z.object({
|
||||
objective: z.literal("risk-adjusted-return")
|
||||
}),
|
||||
createdAt: z.string().datetime()
|
||||
});
|
||||
|
||||
export type StrategyState = z.infer<typeof strategyStateSchema>;
|
||||
export type StrategyDefinition = z.infer<typeof strategyDefinitionSchema>;
|
||||
@@ -0,0 +1,26 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const tradeModeSchema = z.enum(["dry-run", "live"]);
|
||||
export const tradeSideSchema = z.enum(["up", "down"]);
|
||||
export const tradeStatusSchema = z.enum([
|
||||
"proposed",
|
||||
"confirmed",
|
||||
"rejected",
|
||||
"settled"
|
||||
]);
|
||||
|
||||
export const tradeRecordSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
strategyId: z.string().min(1),
|
||||
strategyVersion: z.number().int().positive(),
|
||||
mode: tradeModeSchema,
|
||||
contractId: z.string().min(1),
|
||||
side: tradeSideSchema,
|
||||
confidence: z.number().min(0).max(1),
|
||||
status: tradeStatusSchema,
|
||||
createdAt: z.string().datetime(),
|
||||
settledAt: z.string().datetime().optional(),
|
||||
pnl: z.number().optional()
|
||||
});
|
||||
|
||||
export type TradeRecord = z.infer<typeof tradeRecordSchema>;
|
||||
@@ -0,0 +1,5 @@
|
||||
export * from "./domain/experiment";
|
||||
export * from "./domain/market";
|
||||
export * from "./domain/model-profile";
|
||||
export * from "./domain/strategy";
|
||||
export * from "./domain/trade";
|
||||
Reference in New Issue
Block a user