Skip to content

Commit

Permalink
fix duplicate fundingRateUpdater
Browse files Browse the repository at this point in the history
  • Loading branch information
wphan committed Oct 24, 2023
1 parent fd033d5 commit 96565b6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
20 changes: 15 additions & 5 deletions src/bots/fundingRateUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ function onTheHourUpdate(
export class FundingRateUpdaterBot implements Bot {
public readonly name: string;
public readonly dryRun: boolean;
public readonly defaultIntervalMs: number = 600000;
public readonly runOnce: boolean;
public readonly defaultIntervalMs: number = 120000; // run every 2 min

private driftClient: DriftClient;
private intervalIds: Array<NodeJS.Timer> = [];
Expand All @@ -68,6 +69,7 @@ export class FundingRateUpdaterBot implements Bot {
this.name = config.botId;
this.dryRun = config.dryRun;
this.driftClient = driftClient;
this.runOnce = config.runOnce ?? false;
}

public async init() {
Expand All @@ -81,10 +83,18 @@ export class FundingRateUpdaterBot implements Bot {
this.intervalIds = [];
}

public async startIntervalLoop(_intervalMs?: number): Promise<void> {
logger.info(`${this.name} Bot started!`);
await this.tryUpdateFundingRate();
// we don't want to run this repeatedly
public async startIntervalLoop(intervalMs?: number): Promise<void> {
logger.info(`${this.name} Bot started! runOnce ${this.runOnce}`);

if (this.runOnce) {
await this.tryUpdateFundingRate();
} else {
const intervalId = setInterval(
this.tryUpdateFundingRate.bind(this),
intervalMs
);
this.intervalIds.push(intervalId);
}
}

public async healthCheck(): Promise<boolean> {
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export function loadConfigFromOpts(opts: any): Config {
dryRun: opts.dryRun ?? false,
botId: process.env.BOT_ID ?? 'liquidator',
metricsPort: 9464,

disableAutoDerisking: opts.disableAutoDerisking ?? false,
useJupiter: opts.useJupiter ?? true,
perpMarketIndicies: loadCommaDelimitToArray(opts.perpMarketIndicies),
Expand Down
9 changes: 0 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,15 +660,6 @@ const runBot = async () => {
);
}

if (configHasBot(config, 'fundingRateUpdater')) {
bots.push(
new FundingRateUpdaterBot(
driftClient,
config.botConfigs!.fundingRateUpdater!
)
);
}

if (configHasBot(config, 'uncrossArb')) {
await userMap.subscribe();
const jitProxyClient = new JitProxyClient({
Expand Down

0 comments on commit 96565b6

Please sign in to comment.