add implementation
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
|||||||
l2WithBNToStrings,
|
l2WithBNToStrings,
|
||||||
} from '../utils/utils';
|
} from '../utils/utils';
|
||||||
import { logger } from '../utils/logger';
|
import { logger } from '../utils/logger';
|
||||||
|
import { webhookMessage } from '../utils/webhook';
|
||||||
|
|
||||||
type wsMarketL2Args = {
|
type wsMarketL2Args = {
|
||||||
marketIndex: number;
|
marketIndex: number;
|
||||||
@@ -144,12 +145,18 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
|
|||||||
asks: l2Formatted.asks.slice(0, 5),
|
asks: l2Formatted.asks.slice(0, 5),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// START HACK FOR DEBUGGING FAILURE WEBSOCKET CONNECTIONS
|
||||||
const orderSubscriberSlot = this.slotSource.getSlot();
|
const orderSubscriberSlot = this.slotSource.getSlot();
|
||||||
const dlobOracleSlot = l2Formatted['oracle']['slot'];
|
const dlobOracleSlot = parseInt(l2Formatted['oracleData']['slot']);
|
||||||
if (Math.abs(orderSubscriberSlot - dlobOracleSlot) > 50) {
|
const slotDiff = Math.abs(orderSubscriberSlot - dlobOracleSlot);
|
||||||
noticeSlack('dlobsubscirber kiling itstelf slot breakokren')
|
if (slotDiff > 50) {
|
||||||
process.exit(420);
|
const msg = `DlobPublisher bad slot in ${l2Formatted['marketType']} market ${l2Formatted['marketName']}! abs(oracleSlot (${dlobOracleSlot}) - orderSubscriberSlot (${orderSubscriberSlot})) = ${slotDiff} > 50`;
|
||||||
|
logger.error(msg);
|
||||||
|
webhookMessage(msg).then(() => {
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
// END HACK FOR DEBUGGING FAILURE WEBSOCKET CONNECTIONS
|
||||||
|
|
||||||
this.redisClient.client.publish(
|
this.redisClient.client.publish(
|
||||||
`orderbook_${marketType}_${l2Args.marketIndex}`,
|
`orderbook_${marketType}_${l2Args.marketIndex}`,
|
||||||
|
|||||||
57
src/utils/webhook.ts
Normal file
57
src/utils/webhook.ts
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
require('dotenv').config();
|
||||||
|
import { logger } from './logger';
|
||||||
|
|
||||||
|
// enum for webhook type (slack, telegram, ...)
|
||||||
|
export enum WebhookType {
|
||||||
|
Slack = 'slack',
|
||||||
|
Discord = 'discord',
|
||||||
|
Telegram = 'telegram',
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function webhookMessage(
|
||||||
|
message: string,
|
||||||
|
webhookUrl?: string,
|
||||||
|
prefix?: string,
|
||||||
|
webhookType?: WebhookType
|
||||||
|
): Promise<void> {
|
||||||
|
if (process.env.WEBHOOK_TYPE) {
|
||||||
|
webhookType = process.env.WEBHOOK_TYPE as WebhookType;
|
||||||
|
}
|
||||||
|
if (!webhookType) {
|
||||||
|
webhookType = WebhookType.Discord;
|
||||||
|
}
|
||||||
|
if (webhookUrl || process.env.WEBHOOK_URL) {
|
||||||
|
const webhook = webhookUrl || process.env.WEBHOOK_URL;
|
||||||
|
const fullMessage = prefix ? prefix + message : message;
|
||||||
|
if (fullMessage && webhook) {
|
||||||
|
try {
|
||||||
|
let data;
|
||||||
|
switch (webhookType) {
|
||||||
|
case WebhookType.Slack:
|
||||||
|
data = {
|
||||||
|
text: fullMessage,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case WebhookType.Discord:
|
||||||
|
data = {
|
||||||
|
content: fullMessage,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case WebhookType.Telegram:
|
||||||
|
data = {
|
||||||
|
text: fullMessage,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
logger.error(`webhookMessage: unknown webhookType: ${webhookType}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await axios.post(webhook, data);
|
||||||
|
} catch (err) {
|
||||||
|
logger.info('webhook error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user