Skip to content

Commit

Permalink
feat(bot): make strategy logging optional
Browse files Browse the repository at this point in the history
  • Loading branch information
bludnic committed Sep 9, 2024
1 parent 38032f0 commit 042790f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Bot" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"type" TEXT NOT NULL,
"name" TEXT NOT NULL,
"label" TEXT,
"symbol" TEXT NOT NULL,
"enabled" BOOLEAN NOT NULL DEFAULT false,
"logging" BOOLEAN NOT NULL DEFAULT true,
"template" TEXT NOT NULL,
"timeframe" TEXT,
"processing" BOOLEAN NOT NULL DEFAULT false,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"settings" TEXT NOT NULL,
"state" TEXT NOT NULL DEFAULT '{}',
"exchangeAccountId" INTEGER NOT NULL,
"ownerId" INTEGER NOT NULL,
CONSTRAINT "Bot_exchangeAccountId_fkey" FOREIGN KEY ("exchangeAccountId") REFERENCES "ExchangeAccount" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Bot_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_Bot" ("createdAt", "enabled", "exchangeAccountId", "id", "label", "name", "ownerId", "processing", "settings", "state", "symbol", "template", "timeframe", "type") SELECT "createdAt", "enabled", "exchangeAccountId", "id", "label", "name", "ownerId", "processing", "settings", "state", "symbol", "template", "timeframe", "type" FROM "Bot";
DROP TABLE "Bot";
ALTER TABLE "new_Bot" RENAME TO "Bot";
CREATE UNIQUE INDEX "Bot_label_key" ON "Bot"("label");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;
1 change: 1 addition & 0 deletions packages/prisma/src/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ model Bot {
label String? @unique
symbol String
enabled Boolean @default(false)
logging Boolean @default(true)
// Template name that will be executed by the bot
// e.g. `gridBot`, see templates in @opentrader/templates
Expand Down
19 changes: 11 additions & 8 deletions packages/processing/src/bot/bot.processing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,17 @@ export class BotProcessing {

await xprisma.bot.setProcessing(false, this.bot.id);
await xprisma.bot.updateState(botState, this.bot.id);
await xprisma.botLog.log({
startedAt: new Date(t0),
endedAt: new Date(),
botId: this.bot.id,
context: market,
action: command,
triggerEventType,
});

if (this.bot.logging) {
await xprisma.botLog.log({
startedAt: new Date(t0),
endedAt: new Date(),
botId: this.bot.id,
context: market,
action: command,
triggerEventType,
});
}

const t1 = Date.now();
const duration = (t1 - t0) / 1000;
Expand Down
1 change: 1 addition & 0 deletions packages/trpc/src/routers/private/bot/create-bot/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const ZCreateBotInputSchema = z.object({
settings: true,
template: true,
timeframe: true,
logging: true,
}),
});

Expand Down
1 change: 1 addition & 0 deletions packages/trpc/src/routers/private/bot/update-bot/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const ZUpdateBotInputSchema = z.object({
template: true,
timeframe: true,
exchangeAccountId: true,
logging: true,
}),
});

Expand Down
2 changes: 1 addition & 1 deletion pro
Submodule pro updated from 5c300a to 55de79

0 comments on commit 042790f

Please sign in to comment.