feat: improve error handling in OffsetMakerEngine and enhance logging in LighterGateway for better debugging and robustness

This commit is contained in:
discountry
2025-11-12 20:34:02 +08:00
parent 870fe2b8d7
commit 28bc1d5210
3 changed files with 23 additions and 10 deletions
+1 -2
View File
@@ -162,8 +162,7 @@ export class LighterExchangeAdapter implements ExchangeAdapter {
return;
}
if (isSuccessfulResponse(error)) {
console.info(`[LighterExchangeAdapter] ${context}: ${JSON.stringify(error)}`);
return;
return; // success responses are noisy; ignore unless non-200
}
console.error(`[LighterExchangeAdapter] ${context} failed: ${extractMessage(error)}`);
}
+6 -5
View File
@@ -174,6 +174,7 @@ export class LighterGateway {
private readonly auth = { token: null as string | null, expiresAt: 0 };
private readonly l1Address: string | null;
private loggedCreateOrderPayload = false;
private readonly logTxInfo: boolean;
private httpEmptySince: number | null = null;
private lastWsPositionUpdateAt = 0;
@@ -243,6 +244,7 @@ export class LighterGateway {
this.tickerPollMs = options.tickerPollMs ?? DEFAULT_TICKER_POLL_MS;
this.klinePollMs = options.klinePollMs ?? DEFAULT_KLINE_POLL_MS;
this.l1Address = options.l1Address ?? null;
this.logTxInfo = process.env.LIGHTER_LOG_TX === "1" || process.env.LIGHTER_LOG_TX === "true";
}
async ensureInitialized(): Promise<void> {
@@ -288,10 +290,9 @@ export class LighterGateway {
apiKeyIndex,
nonce,
});
if (!this.loggedCreateOrderPayload) {
if (process.env.LIGHTER_DEBUG === "1" || process.env.LIGHTER_DEBUG === "true") {
this.logger("createOrder.txInfo", signed.txInfo);
}
const debugEnabled = process.env.LIGHTER_DEBUG === "1" || process.env.LIGHTER_DEBUG === "true";
if (this.logTxInfo && !this.loggedCreateOrderPayload) {
this.logger("createOrder.txInfo", signed.txInfo);
this.loggedCreateOrderPayload = true;
}
const auth = await this.ensureAuthToken();
@@ -299,7 +300,7 @@ export class LighterGateway {
authToken: auth,
priceProtection: false,
});
if (process.env.LIGHTER_DEBUG === "1" || process.env.LIGHTER_DEBUG === "true") {
if (debugEnabled && response.code !== 200) {
this.logger("createOrder.sendTx.response", response);
}
const clientOrderIndexStr = signParams.clientOrderIndex.toString();