Skip to content

Commit

Permalink
feat: add requiredHistory to warm up the strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
bludnic committed May 21, 2024
1 parent 2c5af9b commit 4736389
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 73 deletions.
7 changes: 4 additions & 3 deletions packages/bot-processor/src/types/bot/bot-template.type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { TBotContext } from "./bot-context.type";
import type { IBotConfiguration } from "./bot-configuration.interface";

export type BotTemplate<T extends IBotConfiguration> = (
ctx: TBotContext<T>,
) => Generator<unknown, unknown>;
export interface BotTemplate<T extends IBotConfiguration> {
(ctx: TBotContext<T>): Generator<unknown, unknown>;
requiredHistory?: number;
}
7 changes: 7 additions & 0 deletions packages/bot-templates/src/templates/test/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export function* debug(ctx: TBotContext<DebugStrategyConfig>) {
}

logger.info(`[DebugStrategy] Run bot template`);
logger.info(
ctx.market.candles.map((candle) =>
new Date(candle.timestamp).toISOString(),
),
`[DebugStrategy] Candles`,
);

logger.info(`[DebugStrategy] Bot template executed successfully`);
}
Expand All @@ -41,6 +47,7 @@ debug.displayName = "Debug Strategy";
debug.schema = z.object({
fetchSymbols: z.boolean().optional(),
});
debug.requiredHistory = 15;

export type DebugStrategyConfig = IBotConfiguration<
z.infer<typeof debug.schema>
Expand Down
3 changes: 3 additions & 0 deletions packages/bot-templates/src/templates/test/rsi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ export function* testRsi(ctx: TBotContext<any>) {
logger.info(`[TestRsi] RSI is in no trend. Do nothing.`);
}
}

testRsi.displayName = "Test RSI";
testRsi.requiredHistory = 15;
1 change: 1 addition & 0 deletions packages/bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"typescript": "^5.2.2"
},
"dependencies": {
"@opentrader/bot-templates": "workspace:*",
"@opentrader/db": "workspace:*",
"@opentrader/exchanges": "workspace:*",
"@opentrader/logger": "workspace:*",
Expand Down
Loading

0 comments on commit 4736389

Please sign in to comment.