From 6d08ea5997dc99e0dae1e799823b455ab7c2db56 Mon Sep 17 00:00:00 2001 From: "Ricardo J. Mendez" Date: Mon, 4 Sep 2023 15:47:40 +0200 Subject: [PATCH] Optional subAccountId config for floatingMaker --- example.config.yaml | 2 ++ src/bots/floatingMaker.ts | 12 ++++++++++++ src/config.ts | 1 + 3 files changed, 15 insertions(+) diff --git a/example.config.yaml b/example.config.yaml index a4f6c6b2..6347f60a 100644 --- a/example.config.yaml +++ b/example.config.yaml @@ -151,6 +151,8 @@ botConfigs: intervalMs: 7500 orderOffset: 95 orderSize: 5 + # If subAccountId is set, it should also be included on the subaccounts config above + subAccountId: 1 perpMarketIndices: - 0 # SOL - 9 # SUI diff --git a/src/bots/floatingMaker.ts b/src/bots/floatingMaker.ts index e8c092b6..67bbb9df 100644 --- a/src/bots/floatingMaker.ts +++ b/src/bots/floatingMaker.ts @@ -57,6 +57,7 @@ export class FloatingPerpMakerBot implements Bot { public defaultIntervalMs: number = 5000; private orderOffset: number = 90; private orderSize: number = 1; + private subAccountId: number = 0; private driftClient: DriftClient; private slotSubscriber: SlotSubscriber; @@ -115,6 +116,16 @@ export class FloatingPerpMakerBot implements Bot { this.orderOffset = config.orderOffset ?? 90; this.orderSize = config.orderSize ?? 1; + // Configure user and subaccount + this.subAccountId = config.subAccountId ?? 0; + if (this.subAccountId != 0) { + logger.warn(`Using subAccountId ${this.subAccountId}.`); + logger.warn( + `The bot will only change subaccounts once, so make sure there are no conflicting changes on other bots.` + ); + } + this.driftClient.switchActiveUser(this.subAccountId); + this.marketIndices = new Set(config.perpMarketIndices); this.metricsPort = config.metricsPort; @@ -185,6 +196,7 @@ export class FloatingPerpMakerBot implements Bot { public async init() { logger.info(`${this.name} initing`); + this.agentState = { marketPosition: new Map(), openOrders: new Map>(), diff --git a/src/config.ts b/src/config.ts index ab5e9729..548a3ddb 100644 --- a/src/config.ts +++ b/src/config.ts @@ -27,6 +27,7 @@ export type FloatingMakerConfig = BaseBotConfig & { orderOffset?: number; orderSize?: number; perpMarketIndices?: Set; + subAccountId?: number; }; export type SubaccountConfig = {