Skip to content

Commit

Permalink
chore(templates): add debug strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
bludnic committed May 11, 2024
1 parent e78485a commit 288b6ca
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"lint:fix": "turbo run lint:fix",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"front": "turbo run dev --filter=frontend",
"postinstall": "pnpm link --global"
"postinstall": "pnpm link --global",
"debug": "ts-node --transpile-only packages/cli/src/index.ts trade debug"
},
"bin": {
"opentrader": "./bin/opentrader.sh"
Expand Down
1 change: 1 addition & 0 deletions packages/bot-templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@opentrader/bot-processor": "workspace:*",
"@opentrader/exchanges": "workspace:*",
"@opentrader/indicators": "workspace:*",
"@opentrader/logger": "workspace:*",
"@opentrader/tools": "workspace:*",
"zod": "3.22.4"
}
Expand Down
47 changes: 47 additions & 0 deletions packages/bot-templates/src/templates/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { z } from "zod";
import type { ISymbolInfo } from "@opentrader/types";
import type { IExchange } from "@opentrader/exchanges";
import type { IBotConfiguration, TBotContext } from "@opentrader/bot-processor";
import { useExchange } from "@opentrader/bot-processor";
import { logger } from "@opentrader/logger";

export function* debug(ctx: TBotContext<DebugStrategyConfig>) {
const { config: bot, onStart, onStop } = ctx;
const exchange: IExchange = yield useExchange();

logger.debug("Hello world");

if (onStart) {
logger.info(
`[DebugStrategy] Bot started. Using ${exchange.exchangeCode} exchange`,
);

if (bot.settings.fetchSymbols) {
const symbols: ISymbolInfo[] = yield exchange.getSymbols();
logger.info(`[DebugStrategy] Fetched ${symbols.length} symbols`);
} else {
logger.info(
`[DebugStrategy] Skipping fetching symbols (fetchSymbols=false)`,
);
}

return;
}
if (onStop) {
logger.info(`[DebugStrategy] Bot stopped`);
return;
}

logger.info(`[DebugStrategy] Run bot template`);

logger.info(`[DebugStrategy] Bot template executed successfully`);
}

debug.displayName = "Debug Strategy";
debug.schema = z.object({
fetchSymbols: z.boolean().optional(),
});

export type DebugStrategyConfig = IBotConfiguration<
z.infer<typeof debug.schema>
>;
1 change: 1 addition & 0 deletions packages/bot-templates/src/templates/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./grid-bot";
export * from "./grid-bot-lite";
export * from "./low-cap";
export * from "./debug";

0 comments on commit 288b6ca

Please sign in to comment.