mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-11 17:28:08 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
445e634aa1 | ||
|
|
4bb1fee995 | ||
|
|
aad14395e0 |
@@ -21,6 +21,8 @@ const TYPE_EMOJI: Record<string, string> = {
|
|||||||
custom: "📢",
|
custom: "📢",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const LOG_PREFIX = "[Telegram]";
|
||||||
|
|
||||||
function formatNotificationMessage(notification: TradeNotification, accountLabel?: string): string {
|
function formatNotificationMessage(notification: TradeNotification, accountLabel?: string): string {
|
||||||
const levelEmoji = LEVEL_EMOJI[notification.level] ?? "";
|
const levelEmoji = LEVEL_EMOJI[notification.level] ?? "";
|
||||||
const typeEmoji = TYPE_EMOJI[notification.type] ?? "";
|
const typeEmoji = TYPE_EMOJI[notification.type] ?? "";
|
||||||
@@ -94,12 +96,14 @@ export class TelegramNotifier implements NotificationSender {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (response.ok) {
|
||||||
const errorText = await response.text().catch(() => "unknown error");
|
console.info(`${LOG_PREFIX} Notification sent (status ${response.status}).`);
|
||||||
console.error(`[Telegram] Failed to send notification: ${response.status} ${errorText}`);
|
return;
|
||||||
}
|
}
|
||||||
|
const errorText = await response.text().catch(() => "unknown error");
|
||||||
|
console.error(`${LOG_PREFIX} Failed to send notification: ${response.status} ${errorText}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`[Telegram] Failed to send notification: ${error instanceof Error ? error.message : String(error)}`);
|
console.error(`${LOG_PREFIX} Failed to send notification: ${error instanceof Error ? error.message : String(error)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -645,7 +645,7 @@ export class MakerPointsEngine {
|
|||||||
"stop",
|
"stop",
|
||||||
`触发止损: 未实现亏损 ${position.unrealizedProfit.toFixed(4)} USDT`
|
`触发止损: 未实现亏损 ${position.unrealizedProfit.toFixed(4)} USDT`
|
||||||
);
|
);
|
||||||
this.notifier.send({
|
this.notify({
|
||||||
type: "stop_loss",
|
type: "stop_loss",
|
||||||
level: "error",
|
level: "error",
|
||||||
symbol: this.config.symbol,
|
symbol: this.config.symbol,
|
||||||
@@ -802,6 +802,10 @@ export class MakerPointsEngine {
|
|||||||
return getMidOrLast(this.depthSnapshot, this.tickerSnapshot);
|
return getMidOrLast(this.depthSnapshot, this.tickerSnapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private notify(notification: TradeNotification): void {
|
||||||
|
this.notifier.send(notification);
|
||||||
|
}
|
||||||
|
|
||||||
private logReadinessBlockers(): void {
|
private logReadinessBlockers(): void {
|
||||||
if (!this.feedStatus.account && !this.readinessLogged.account) {
|
if (!this.feedStatus.account && !this.readinessLogged.account) {
|
||||||
this.tradeLog.push("info", t("log.maker.waitAccount"));
|
this.tradeLog.push("info", t("log.maker.waitAccount"));
|
||||||
@@ -887,7 +891,7 @@ export class MakerPointsEngine {
|
|||||||
const reference = this.getReferencePrice() ?? 0;
|
const reference = this.getReferencePrice() ?? 0;
|
||||||
|
|
||||||
if (prevSide === "FLAT" && currentSide !== "FLAT") {
|
if (prevSide === "FLAT" && currentSide !== "FLAT") {
|
||||||
this.notifier.send({
|
this.notify({
|
||||||
type: "position_opened",
|
type: "position_opened",
|
||||||
level: "info",
|
level: "info",
|
||||||
symbol: this.config.symbol,
|
symbol: this.config.symbol,
|
||||||
@@ -902,7 +906,7 @@ export class MakerPointsEngine {
|
|||||||
} else if (currentSide === "FLAT" && prevSide !== "FLAT") {
|
} else if (currentSide === "FLAT" && prevSide !== "FLAT") {
|
||||||
const pnl = position.unrealizedProfit;
|
const pnl = position.unrealizedProfit;
|
||||||
const closeType = this.tokenExpiredCloseOnlyMode ? "Token过期平仓" : "平仓";
|
const closeType = this.tokenExpiredCloseOnlyMode ? "Token过期平仓" : "平仓";
|
||||||
this.notifier.send({
|
this.notify({
|
||||||
type: "position_closed",
|
type: "position_closed",
|
||||||
level: "success",
|
level: "success",
|
||||||
symbol: this.config.symbol,
|
symbol: this.config.symbol,
|
||||||
@@ -917,7 +921,7 @@ export class MakerPointsEngine {
|
|||||||
} else if (currentSide === prevSide && absChange > EPS) {
|
} else if (currentSide === prevSide && absChange > EPS) {
|
||||||
const isIncrease = Math.abs(currentAmt) > Math.abs(prevAmt);
|
const isIncrease = Math.abs(currentAmt) > Math.abs(prevAmt);
|
||||||
if (isIncrease) {
|
if (isIncrease) {
|
||||||
this.notifier.send({
|
this.notify({
|
||||||
type: "order_filled",
|
type: "order_filled",
|
||||||
level: "info",
|
level: "info",
|
||||||
symbol: this.config.symbol,
|
symbol: this.config.symbol,
|
||||||
@@ -930,7 +934,7 @@ export class MakerPointsEngine {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.notifier.send({
|
this.notify({
|
||||||
type: "order_filled",
|
type: "order_filled",
|
||||||
level: "info",
|
level: "info",
|
||||||
symbol: this.config.symbol,
|
symbol: this.config.symbol,
|
||||||
@@ -944,7 +948,7 @@ export class MakerPointsEngine {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (currentSide !== prevSide && currentSide !== "FLAT" && prevSide !== "FLAT") {
|
} else if (currentSide !== prevSide && currentSide !== "FLAT" && prevSide !== "FLAT") {
|
||||||
this.notifier.send({
|
this.notify({
|
||||||
type: "position_opened",
|
type: "position_opened",
|
||||||
level: "info",
|
level: "info",
|
||||||
symbol: this.config.symbol,
|
symbol: this.config.symbol,
|
||||||
@@ -995,7 +999,7 @@ export class MakerPointsEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!this.tokenExpiryNotified) {
|
if (!this.tokenExpiryNotified) {
|
||||||
this.notifier.send({
|
this.notify({
|
||||||
type: "token_expired",
|
type: "token_expired",
|
||||||
level: "warn",
|
level: "warn",
|
||||||
symbol: this.config.symbol,
|
symbol: this.config.symbol,
|
||||||
|
|||||||
Reference in New Issue
Block a user