Interface IActionSchema

Action schema registered via addActionSchema(). Defines event handler implementation and lifecycle callbacks for state management integration.

Actions provide a way to attach custom event handlers to strategies for:

  • State management (Redux, Zustand, MobX)
  • Event logging and monitoring
  • Real-time notifications (Telegram, Discord, email)
  • Analytics and metrics collection
  • Custom business logic triggers

Each action instance is created per strategy-frame pair and receives all events emitted during strategy execution. Multiple actions can be attached to a single strategy.

import { addActionSchema } from "backtest-kit";

// Define action handler class
class TelegramNotifier implements Partial<IAction> {
constructor(
private strategyName: StrategyName,
private frameName: FrameName,
private backtest: boolean
) {}

signal(event: IStrategyTickResult): void {
if (!this.backtest && event.action === 'opened') {
telegram.send(`[${this.strategyName}/${this.frameName}] New signal`);
}
}

dispose(): void {
telegram.close();
}
}

// Register action schema
addActionSchema({
actionName: "telegram-notifier",
handler: TelegramNotifier,
callbacks: {
onInit: async (strategyName, frameName, backtest) => {
console.log(`Telegram notifier initialized for ${strategyName}/${frameName}`);
},
onSignal: (event, strategyName, frameName, backtest) => {
console.log(`Signal event: ${event.action}`);
}
}
});
interface IActionSchema {
    actionName: string;
    callbacks?: Partial<IActionCallbacks>;
    handler: Partial<IPublicAction> | TActionCtor;
    note?: string;
}

Properties

actionName: string

Unique action identifier for registration

callbacks?: Partial<IActionCallbacks>

Optional lifecycle and event callbacks

handler: Partial<IPublicAction> | TActionCtor

Action handler constructor (instantiated per strategy-frame pair)

note?: string

Optional developer note for documentation