-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
62 lines (59 loc) · 2.02 KB
/
tests.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
const axios = require("axios");
const { bot } = require("./index");
async function checkPriceChange(bool) {
if (bool === false) {
return bot.sendMessage(chatId, `Вы остановили бот`);
} else {
let coins = [];
// Получение списка монет
const responseSymbols = await axios.get(
"https://api.bybit.com/spot/v3/public/symbols"
);
if (responseSymbols.status === 200) {
const quotes = responseSymbols.data.result.list;
for (const coin of quotes) {
coins.push(coin.name);
}
}
while (bool) {
try {
// Запрос всех пар
for (const symbol of coins) {
const intervalResponse = await axios.get(
`https://api.bybit.com/spot/v3/public/quote/kline?symbol=${symbol}&interval=1m&limit=5`
);
if (intervalResponse.status === 200) {
const prices = intervalResponse.data.result.list;
if (prices === null) {
continue;
}
// Расчет разницы в процентах
for (const price of prices) {
const priceChangePercent = ((price.c - price.o) / price.o) * 100;
const priceChangeLow = ((price.l - price.o) / price.o) * 100;
const priceChangeHi = ((price.h - price.o) / price.o) * 100;
if (
priceChangePercent >= 2 ||
priceChangePercent <= -2 ||
priceChangeLow >= 2 ||
priceChangeLow <= -2 ||
priceChangeHi >= 2 ||
priceChangeHi <= -2
) {
console.log(
`Symbol: ${symbol}, Price Change: ${priceChangePercent.toFixed(
2
)} % за 1мин. Объем: ${price.v}$`
);
}
}
}
}
} catch (error) {
console.error(`For of: ${error.message}`);
}
}
}
}
const date = new Date();
console.log(checkPriceChange(true), date);