(symbol: string)
| 336 | const { data } = await axios.get(url, { timeout: 5000 }); |
| 337 | if (data && data.price) { |
| 338 | return parseFloat(data.price); |
| 339 | } |
| 340 | } catch (error) { |
| 341 | if (axios.isAxiosError(error) && error.response?.status === 400) { |
| 342 | // 交易对不存在,这不是一个严重错误,静默处理 |
| 343 | } else { |
| 344 | console.warn(`[RatePlugin] Binance API for ${symbol} failed:`, error); |
| 345 | } |
| 346 | } |
| 347 | throw new Error(`Binance pair not found for ${symbol}`); |
| 348 | } |
| 349 | |
| 350 | // (全智能) 获取任意两种货币之间的汇率 |
| 351 | private async getUniversalPrice(symbol1: string, symbol2: string, type1: 'crypto' | 'fiat', type2: 'crypto' | 'fiat'): Promise<{ price: number, lastUpdated: Date }> { |
| 352 | const s1 = symbol1.toUpperCase(); |
| 353 | const s2 = symbol2.toUpperCase(); |
| 354 | |
| 355 | // 情况1: 加密货币 -> 加密货币 |
| 356 | if (type1 === 'crypto' && type2 === 'crypto') { |
no test coverage detected