mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-11 09:18:08 +00:00
feat: improve error handling in OffsetMakerEngine and enhance logging in LighterGateway for better debugging and robustness
This commit is contained in:
@@ -162,8 +162,7 @@ export class LighterExchangeAdapter implements ExchangeAdapter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isSuccessfulResponse(error)) {
|
if (isSuccessfulResponse(error)) {
|
||||||
console.info(`[LighterExchangeAdapter] ${context}: ${JSON.stringify(error)}`);
|
return; // success responses are noisy; ignore unless non-200
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
console.error(`[LighterExchangeAdapter] ${context} failed: ${extractMessage(error)}`);
|
console.error(`[LighterExchangeAdapter] ${context} failed: ${extractMessage(error)}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,6 +174,7 @@ export class LighterGateway {
|
|||||||
private readonly auth = { token: null as string | null, expiresAt: 0 };
|
private readonly auth = { token: null as string | null, expiresAt: 0 };
|
||||||
private readonly l1Address: string | null;
|
private readonly l1Address: string | null;
|
||||||
private loggedCreateOrderPayload = false;
|
private loggedCreateOrderPayload = false;
|
||||||
|
private readonly logTxInfo: boolean;
|
||||||
private httpEmptySince: number | null = null;
|
private httpEmptySince: number | null = null;
|
||||||
private lastWsPositionUpdateAt = 0;
|
private lastWsPositionUpdateAt = 0;
|
||||||
|
|
||||||
@@ -243,6 +244,7 @@ export class LighterGateway {
|
|||||||
this.tickerPollMs = options.tickerPollMs ?? DEFAULT_TICKER_POLL_MS;
|
this.tickerPollMs = options.tickerPollMs ?? DEFAULT_TICKER_POLL_MS;
|
||||||
this.klinePollMs = options.klinePollMs ?? DEFAULT_KLINE_POLL_MS;
|
this.klinePollMs = options.klinePollMs ?? DEFAULT_KLINE_POLL_MS;
|
||||||
this.l1Address = options.l1Address ?? null;
|
this.l1Address = options.l1Address ?? null;
|
||||||
|
this.logTxInfo = process.env.LIGHTER_LOG_TX === "1" || process.env.LIGHTER_LOG_TX === "true";
|
||||||
}
|
}
|
||||||
|
|
||||||
async ensureInitialized(): Promise<void> {
|
async ensureInitialized(): Promise<void> {
|
||||||
@@ -288,10 +290,9 @@ export class LighterGateway {
|
|||||||
apiKeyIndex,
|
apiKeyIndex,
|
||||||
nonce,
|
nonce,
|
||||||
});
|
});
|
||||||
if (!this.loggedCreateOrderPayload) {
|
const debugEnabled = process.env.LIGHTER_DEBUG === "1" || process.env.LIGHTER_DEBUG === "true";
|
||||||
if (process.env.LIGHTER_DEBUG === "1" || process.env.LIGHTER_DEBUG === "true") {
|
if (this.logTxInfo && !this.loggedCreateOrderPayload) {
|
||||||
this.logger("createOrder.txInfo", signed.txInfo);
|
this.logger("createOrder.txInfo", signed.txInfo);
|
||||||
}
|
|
||||||
this.loggedCreateOrderPayload = true;
|
this.loggedCreateOrderPayload = true;
|
||||||
}
|
}
|
||||||
const auth = await this.ensureAuthToken();
|
const auth = await this.ensureAuthToken();
|
||||||
@@ -299,7 +300,7 @@ export class LighterGateway {
|
|||||||
authToken: auth,
|
authToken: auth,
|
||||||
priceProtection: false,
|
priceProtection: false,
|
||||||
});
|
});
|
||||||
if (process.env.LIGHTER_DEBUG === "1" || process.env.LIGHTER_DEBUG === "true") {
|
if (debugEnabled && response.code !== 200) {
|
||||||
this.logger("createOrder.sendTx.response", response);
|
this.logger("createOrder.sendTx.response", response);
|
||||||
}
|
}
|
||||||
const clientOrderIndexStr = signParams.clientOrderIndex.toString();
|
const clientOrderIndexStr = signParams.clientOrderIndex.toString();
|
||||||
|
|||||||
@@ -546,10 +546,20 @@ export class OffsetMakerEngine {
|
|||||||
this.lastEntryOrderBySide[target.side] = { price: target.price, ts: Date.now() };
|
this.lastEntryOrderBySide[target.side] = { price: target.price, ts: Date.now() };
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const dustClosed = await this.tryDustMarketClose(target, error);
|
if (isRateLimitError(error)) {
|
||||||
if (!dustClosed) {
|
throw error;
|
||||||
this.tradeLog.push("error", `挂单失败(${target.side} ${target.price}): ${String(error)}`);
|
|
||||||
}
|
}
|
||||||
|
let dustClosed = false;
|
||||||
|
try {
|
||||||
|
dustClosed = await this.tryDustMarketClose(target, error);
|
||||||
|
} catch (dustError) {
|
||||||
|
if (isRateLimitError(dustError)) {
|
||||||
|
throw dustError;
|
||||||
|
}
|
||||||
|
this.tradeLog.push("error", `小额市价平仓失败: ${String(dustError)}`);
|
||||||
|
}
|
||||||
|
if (dustClosed) continue;
|
||||||
|
this.tradeLog.push("error", `挂单失败(${target.side} ${target.price}): ${String(error)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -760,6 +770,9 @@ export class OffsetMakerEngine {
|
|||||||
this.tradeLog.push("order", `小额仓位使用市价平仓 ${target.side} 数量 ${absQty.toFixed(6)}`);
|
this.tradeLog.push("order", `小额仓位使用市价平仓 ${target.side} 数量 ${absQty.toFixed(6)}`);
|
||||||
return true;
|
return true;
|
||||||
} catch (closeError) {
|
} catch (closeError) {
|
||||||
|
if (isRateLimitError(closeError)) {
|
||||||
|
throw closeError;
|
||||||
|
}
|
||||||
this.tradeLog.push("error", `小额市价平仓失败: ${String(closeError)}`);
|
this.tradeLog.push("error", `小额市价平仓失败: ${String(closeError)}`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user