Эх сурвалжийг харах

尝试修复了打印逻辑的处理问题

龚成明 2 жил өмнө
parent
commit
4dedd5c9e0

+ 1 - 1
config/config.js

@@ -53,7 +53,7 @@ Config.tokenMapping = {
   '0x0D8Ce2A99Bb6e3B7Db580eD848240e4a0F9aE153': 'FIL',
   '0x570A5D26f7765Ecb712C0924E4De545B89fD43dF': 'SOL',
   '0x67b725d7e342d7B611fa85e859Df9697D9378B2e': 'SAND',
-  '0x728C5baC3C3e370E372Fc4671f9ef6916b814d8B': 'UNFI'
+  // '0x728C5baC3C3e370E372Fc4671f9ef6916b814d8B': 'UNFI'
 }
 
 module.exports = Config

+ 12 - 14
scripts/monitors/price-monitor.js

@@ -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)