龚成明 2 роки тому
батько
коміт
1ce0715308
1 змінених файлів з 14 додано та 5 видалено
  1. 14 5
      scripts/monitors/price-monitor.js

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

@@ -11,7 +11,7 @@ const showPrices = function(context, task) {
   const tokenMap = context.tokenMap
 
   const titles = ['pair', '1inch', 'binance', 'diff', 'percentage']
-  const colWidth = 20
+  const colWidth = 30
   const padTitles = titles.map((title) => {
     return title.padEnd(colWidth, ' ')
   })
@@ -55,7 +55,7 @@ const showPrices = function(context, task) {
 
     // 价格非法的就不输出了
     if ((() => {
-      return !OneInchPrice || !BinancePrice || !DiffPrice
+      return !OneInchPrice || !BinancePrice
     })()) return
     // 需要输出到文件的打印逻辑
     if ((() => {
@@ -78,15 +78,24 @@ const onTickFun = async function() {
   // 搜集所有价格数据
   for (const tokenHash of tokenContractAddressList) {
     const toToken = tokenMap[tokenHash]
+    const lotSize = toToken.exchange.lotSize
     const fromIerc20Token = Config.baseIerc20Token
     const amount = Config.baseTokenAmount
 
-    const OneInchPrice = NumKit.getSubFloat(await OneInch.price(fromIerc20Token.contract, tokenHash, amount), 8)
-    const BinancePrice = NumKit.getSubFloat(await BinanceSpot.realPrice(toToken.exchange.pair), 8)
+    const OneInchPrice = NumKit.getSubFloat(await OneInch.price(fromIerc20Token.contract, tokenHash, amount), lotSize)
+    const BinancePrice = NumKit.getSubFloat(await BinanceSpot.realPrice(toToken.exchange.pair), lotSize)
 
     toToken.OneInchPrice = OneInchPrice
     toToken.BinancePrice = BinancePrice
-    toToken.DiffPrice = NumKit.getSubFloat(BinancePrice - OneInchPrice, 8)
+    toToken.DiffPrice = BinancePrice - OneInchPrice
+
+    if ((() => {
+      return Math.abs(toToken.DiffPrice) < Math.pow(10, -lotSize)
+    })()) {
+      toToken.DiffPrice = 0
+    } {
+      toToken.DiffPrice = NumKit.getSubFloat(toToken.DiffPrice, lotSize)
+    }
   }
 
   // 绘制帧