|
|
@@ -18,25 +18,31 @@ const showPrices = function(context, task) {
|
|
|
Object.keys(tokenMap).forEach((tokenHash) => {
|
|
|
const token = tokenMap[tokenHash]
|
|
|
const pair = token.exchange.pair
|
|
|
- const OneInchPrice = token.OneInchPrice
|
|
|
- const BinancePrice = token.BinancePrice
|
|
|
+ const OneInchPrice = token.OneInchPrice ? token.OneInchPrice : NaN
|
|
|
+ const BinancePrice = token.BinancePrice ? token.BinancePrice : NaN
|
|
|
const PrevOneInchPrice = token.PrevOneInchPrice
|
|
|
const PrevBinancePrice = token.PrevBinancePrice
|
|
|
const DiffPrice = token.DiffPrice
|
|
|
const percentage = NumKit.getSubFloat((DiffPrice / OneInchPrice) * 100, 2)
|
|
|
|
|
|
// 价格非法的就不输出了
|
|
|
- if ((() => {
|
|
|
- return !OneInchPrice || !BinancePrice || PrevOneInchPrice === OneInchPrice || PrevBinancePrice === BinancePrice
|
|
|
- })()) return
|
|
|
+ // if ((() => {
|
|
|
+ // return !OneInchPrice || !BinancePrice
|
|
|
+ // })()) return
|
|
|
|
|
|
const rows = [pair.toString(), OneInchPrice.toString(), BinancePrice.toString(), DiffPrice.toString(), percentage.toString()]
|
|
|
|
|
|
// 需要输出到文件的打印逻辑
|
|
|
const isLogToFile = (() => {
|
|
|
- return percentage > PriceMonitorConfig.percentageLimit
|
|
|
+ return percentage > PriceMonitorConfig.percentageLimit && (PrevOneInchPrice !== OneInchPrice && PrevBinancePrice !== BinancePrice)
|
|
|
})()
|
|
|
table.showLine(rows, isLogToFile ? fileLogger : undefined)
|
|
|
+
|
|
|
+ // 上一帧的数据
|
|
|
+ if (isLogToFile) {
|
|
|
+ token.PrevOneInchPrice = token.OneInchPrice
|
|
|
+ token.PrevBinancePrice = token.BinancePrice
|
|
|
+ }
|
|
|
})
|
|
|
table.printEndLine(logger)
|
|
|
}
|
|
|
@@ -72,14 +78,6 @@ const onTickFun = async function() {
|
|
|
|
|
|
// 绘制帧
|
|
|
showPrices(context, task)
|
|
|
-
|
|
|
- // 赋予prev价格值
|
|
|
- Object.keys(tokenMap).forEach((tokenHash) => {
|
|
|
- const token = tokenMap[tokenHash]
|
|
|
-
|
|
|
- token.PrevOneInchPrice = token.OneInchPrice
|
|
|
- token.PrevBinancePrice = token.BinancePrice
|
|
|
- })
|
|
|
}
|
|
|
|
|
|
const priceMonitor = new OneTask('PriceMonitor',5 * 1000, OneTask.baseInit, onTickFun)
|