-
Notifications
You must be signed in to change notification settings - Fork 18
/
check.js
62 lines (58 loc) · 1.46 KB
/
check.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 { log, error } = console;
const binance = require('./binance');
const checkFrom = 10; //last 5days
const lastTS = Date.now() - checkFrom * 24 * 60 * 60 * 1000;
const bottleneck = require('bottleneck');
const limiter = new bottleneck({
reservoir: 10, // initial value
reservoirRefreshAmount: 10,
reservoirRefreshInterval: 1 * 1000,
maxConcurrent: 10,
minTime: 100,
});
const getsymbols = async () => {
try {
const resp = await binance({
method: 'GET',
path: '/api/v3/exchangeInfo',
keys: '',
params: '',
});
return resp?.body.symbols
.filter((d) => d?.quoteAsset === 'USDT' && d?.status === 'TRADING')
.map((d) => d.symbol);
} catch (err) {
throw err;
}
};
const checkWhenListed = limiter.wrap(async (symbol) => {
try {
const resp = await binance({
method: 'GET',
path: `/api/v3/klines?symbol=${symbol}&interval=1d`,
keys: '',
params: '',
});
return { symbol, listedOn: resp.body[0][0] };
} catch (err) {
throw err;
}
});
const run = async () => {
try {
const symbols = await getsymbols();
log(`${symbols.length} USDT pairs identified.`);
const listingDate = await Promise.all(symbols.map(checkWhenListed));
log(
listingDate
.filter((d) => d.listedOn > lastTS)
.map(
(d) =>
`${d.symbol} is listed on ${new Date(d.listedOn).toLocaleString()}`
)
);
} catch (err) {
error(err);
}
};
run();