Skip to content

Commit

Permalink
Optional subAccountId config for floatingMaker
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardojmendez committed Sep 5, 2023
1 parent fb8ef7e commit 6d08ea5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions example.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/bots/floatingMaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<number>(config.perpMarketIndices);

this.metricsPort = config.metricsPort;
Expand Down Expand Up @@ -185,6 +196,7 @@ export class FloatingPerpMakerBot implements Bot {

public async init() {
logger.info(`${this.name} initing`);

this.agentState = {
marketPosition: new Map<number, PerpPosition>(),
openOrders: new Map<number, Array<Order>>(),
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type FloatingMakerConfig = BaseBotConfig & {
orderOffset?: number;
orderSize?: number;
perpMarketIndices?: Set<number>;
subAccountId?: number;
};

export type SubaccountConfig = {
Expand Down

0 comments on commit 6d08ea5

Please sign in to comment.