forked from moncici007/binance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoin_scan_binance.js
66 lines (58 loc) · 2.07 KB
/
coin_scan_binance.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
import axios from 'axios';
import { axiosConfig } from '@moncici/proxy';
import { sleep } from '@moncici/sleep';
import { formatTimestamp } from '@moncici/date-time-processor';
import { notify } from 'feishu-notifier';
import { log } from '@moncici/log';
const retryDuration = 1000;
export async function getPricesByCoins(symbols) {
const url = `https://api.binance.com/api/v3/ticker/price?symbols=[${symbols}]`;
try {
const response = await axios.get(url, axiosConfig);
if (response.status == 429) {
sleep(retryDuration);
}
const data = response.data;
log(`${formatTimestamp(new Date())} ${symbols} 实时价格:`, response.data);
notify('', data);
return data
} catch(error) {
log(`无法获取 ${symbols} USD 价格:`, error.response.data);
notify('', error.response.data);
throw error; // 将错误向上抛出
}
}
export async function getPriceByCoin(symbol) {
const url = `https://api.binance.com/api/v3/ticker/price?symbol=${symbol}`;
try {
const response = await axios.get(url, axiosConfig);
if (response.status == 429) {
sleep(retryDuration);
}
const data = response.data;
log(`${symbol} 实时价格:`, response.data);
return data
} catch(error) {
log(`无法获取 ${symbol} USD 价格:`, error.response.data);
throw error; // 将错误向上抛出
}
}
// https://api.binance.com/api/v3/klines?interval=1m&limit=3&symbol=BTCUSDT
export async function getKlines(symbol) {
const url = `https://api.binance.com/api/v3/klines?interval=5m&limit=3&symbol=${symbol}`;
console.log(url);
try {
const response = await axios.get(url, axiosConfig);
if (response.status == 429) {
sleep(retryDuration);
}
const data = response.data;
// console.log(`${symbol} 实时价格:`, response.data);
return data
} catch(error) {
log(`无法获取 ${symbol} USD 价格:`, error.response.data);
throw error; // 将错误向上抛出
}
}
// getPricesByCoins(`"BTCUSDT","ETHUSDT","AVAXUSDT","ARBUSDT","LINKUSDT","MATICUSDT","OPUSDT","SOLUSDT"`);
// getPriceByCoin('ETHUSDT');