-
Notifications
You must be signed in to change notification settings - Fork 1
/
arbNotify.js
129 lines (111 loc) · 5.85 KB
/
arbNotify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
require('dotenv').config();
const ccxt = require('ccxt-xpr');
const { Client, GatewayIntentBits } = require('discord.js');
const TelegramBot = require('node-telegram-bot-api');
const fetchExchanges = require('./src/fetchExchanges.js');
const fetchPricesAndPrecision = require('./src/fetchPrices.js');
const exchangeSymbols = require('./src/exchangeSymbols.js');
const enableDiscord = true; // if true will send to discord bot when arb trade happens
const enableTelegram = true; // if true will send to telegram bot when arb trade happens
const arbitrageThreshold = 3;
// Exchanges and trading pairs
const exchangesAndPairs = [
{
exchangeName: 'Kucoin',
tradingPairs: [
{ symbolProtonDEX: 'XPR_XMD', symbolExchange: 'XPR/USDT' },
{ symbolProtonDEX: 'XBTC_XMD', symbolExchange: 'BTC/USDT' },
{ symbolProtonDEX: 'XLTC_XMD', symbolExchange: 'LTC/USDT' },
{ symbolProtonDEX: 'XETH_XMD', symbolExchange: 'ETH/USDT' },
{ symbolProtonDEX: 'XDOGE_XMD', symbolExchange: 'DOGE/USDT' },
{ symbolProtonDEX: 'XHBAR_XMD', symbolExchange: 'HBAR/USDT' },
// Add other trading pairs for Kucoin
],
},
{
exchangeName: 'Gateio',
tradingPairs: [
{ symbolProtonDEX: 'XPR_XMD', symbolExchange: 'XPR/USDT' },
{ symbolProtonDEX: 'XBTC_XMD', symbolExchange: 'BTC/USDT' },
{ symbolProtonDEX: 'XLTC_XMD', symbolExchange: 'LTC/USDT' },
{ symbolProtonDEX: 'XETH_XMD', symbolExchange: 'ETH/USDT' },
{ symbolProtonDEX: 'XDOGE_XMD', symbolExchange: 'DOGE/USDT' },
{ symbolProtonDEX: 'XHBAR_XMD', symbolExchange: 'HBAR/USDT' },
{ symbolProtonDEX: 'METAL_XMD', symbolExchange: 'METAL/USDT' },
// Add other trading pairs for Gate
],
},
{
exchangeName: 'MEXC',
tradingPairs: [
{ symbolProtonDEX: 'XPR_XMD', symbolExchange: 'XPR/USDT' },
{ symbolProtonDEX: 'XBTC_XMD', symbolExchange: 'BTC/USDT' },
{ symbolProtonDEX: 'XLTC_XMD', symbolExchange: 'LTC/USDT' },
{ symbolProtonDEX: 'XETH_XMD', symbolExchange: 'ETH/USDT' },
{ symbolProtonDEX: 'XDOGE_XMD', symbolExchange: 'DOGE/USDT' },
{ symbolProtonDEX: 'XHBAR_XMD', symbolExchange: 'HBAR/USDT' },
{ symbolProtonDEX: 'METAL_XMD', symbolExchange: 'METAL/USDT' },
// Add other trading pairs for MEXC
],
},
];
// Discord bot settings
const client = new Client({
intents: [GatewayIntentBits.Guilds] // Update the initialization as per the upgrade guide
});
client.login(process.env.DISCORD_BOT_TOKEN);
async function sendNotification(message) {
const channel = client.channels.cache.get(process.env.DISCORD_CHANNEL_ID); // Replace with your channel ID
if (channel) {
channel.send(message);
} else {
console.error('Channel not found');
}
}
// Telegram bot settings
const bot = new TelegramBot(process.env.TELEGRAM_BOT_TOKEN, { polling: false });
const chatId = "-1001626322562";
// Arbitrage trading function
async function arbTrading(symbolProtonDEX, symbolExchange, exchangeName) {
try {
const symbols = exchangeSymbols(symbolProtonDEX, symbolExchange, exchangeName);
const { baseTokenProtonDEX, baseTokenExchange, quoteTokenProtonDEX, quoteTokenExchange } = symbols;
const { exchangeProtonDEX, exchange } = await fetchExchanges(exchangeName); // Pass exchangeName
if (!exchange) {
console.log(`Skipping ${exchangeName}, as it's not recognized or available.`);
return;
}
const { priceProtonDEX, priceExchange } =
await fetchPricesAndPrecision(exchangeProtonDEX, exchange, symbolProtonDEX, symbolExchange, baseTokenProtonDEX, baseTokenExchange, quoteTokenProtonDEX, quoteTokenExchange);
console.log('ProtonDEX Price for:', symbolProtonDEX,' $', priceProtonDEX);
console.log(`${exchangeName} Price for :`, symbolExchange,' $', priceExchange);
if (priceProtonDEX && priceExchange) {
const spreadPercentage = Math.abs(((priceExchange - priceProtonDEX) / priceProtonDEX) * 100);
console.log('Spread Percentage:', spreadPercentage.toFixed(2) + '%');
if (spreadPercentage > arbitrageThreshold) {
console.log('Arbitrage opportunity detected!');
let action = '';
if (priceExchange > priceProtonDEX) {
action = (`🚨 ${exchangeName} ${spreadPercentage.toFixed(2)}% Arbitrage Opportunity! \n📈 Buy ${baseTokenProtonDEX} on ProtonDEX at price ${priceProtonDEX} 💰 \n📉 Sell ${baseTokenExchange} on ${exchangeName} at price ${priceExchange}\n\nUnderstand the risks before trading.`);
} else {
action = (`🚨 ${exchangeName} ${spreadPercentage.toFixed(2)}% Arbitrage Opportunity! \n📉 Sell ${baseTokenProtonDEX} on ProtonDEX at price ${priceProtonDEX} 💰 \n📈 Buy ${baseTokenExchange} on ${exchangeName} at price ${priceExchange}\n\nUnderstand the risks before trading.`);
}
console.log(action);
if (enableTelegram) {bot.sendMessage(chatId, action);}
if (enableDiscord) {sendNotification(action);}
} else {
console.log('No arbitrage opportunity at the moment.');
}
} else {
console.log('Unable to calculate spread percentage. Prices are missing.');
}
} catch (error) {
console.error(`Error with ${exchangeName}: ${error.message}`);
}
}
exchangesAndPairs.forEach(exchangeAndPairs => {
const exchangeName = exchangeAndPairs.exchangeName;
exchangeAndPairs.tradingPairs.forEach(pair => {
setInterval(arbTrading, 120000, pair.symbolProtonDEX, pair.symbolExchange, exchangeName);
});
});