-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(templates): add debug strategy
- Loading branch information
Showing
4 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |