|
|
@@ -10,34 +10,62 @@ const showPrices = function(context, task) {
|
|
|
const fileLogger = task.fileLogger
|
|
|
const tokenMap = context.tokenMap
|
|
|
|
|
|
+ const titles = ['pair', '1inch', 'binance', 'diff', 'percentage']
|
|
|
+ const colWidth = 20
|
|
|
+ const padTitles = titles.map((title) => {
|
|
|
+ return title.padEnd(colWidth, ' ')
|
|
|
+ })
|
|
|
+ const titleLine = (() => {
|
|
|
+ let titleLine = ''
|
|
|
+
|
|
|
+ for (const padTitle of padTitles) {
|
|
|
+ titleLine = titleLine.concat('|').concat(' ').concat(padTitle)
|
|
|
+ }
|
|
|
+
|
|
|
+ return titleLine.concat('|')
|
|
|
+ })()
|
|
|
+ const splitLint = ''.padEnd((colWidth + 2) * titles.length + 1, '-')
|
|
|
+
|
|
|
console.clear()
|
|
|
|
|
|
- console.info(`----------------------------------------------------------------------------------------------------------------------------`)
|
|
|
- console.info(`| pair\t\t\t| 1inch\t\t\t\t| binance\t\t| distance\t\t\t| percentage\t\t\t|`)
|
|
|
- console.info(`----------------------------------------------------------------------------------------------------------------------------`)
|
|
|
+ console.info(splitLint)
|
|
|
+ console.info(titleLine)
|
|
|
+ console.info(splitLint)
|
|
|
Object.keys(tokenMap).forEach((tokenHash) => {
|
|
|
const token = tokenMap[tokenHash]
|
|
|
const pair = token.exchange.pair
|
|
|
const OneInchPrice = token.OneInchPrice
|
|
|
const BinancePrice = token.BinancePrice
|
|
|
- const DistancePrice = token.DistancePrice
|
|
|
+ const DiffPrice = token.DiffPrice
|
|
|
+ const percentage = NumKit.getSubFloat((DiffPrice / OneInchPrice) * 100, 2)
|
|
|
+
|
|
|
+ const cols = [pair.toString(), OneInchPrice.toString(), BinancePrice.toString(), DiffPrice.toString(), percentage.toString()]
|
|
|
+ const padCols = cols.map((col) => {
|
|
|
+ return col.padEnd(colWidth, ' ')
|
|
|
+ })
|
|
|
+ const infoLine = (() => {
|
|
|
+ let infoLine = ''
|
|
|
|
|
|
- const percentage = NumKit.getSubFloat((DistancePrice / OneInchPrice) * 100, 2)
|
|
|
+ for (const padCol of padCols) {
|
|
|
+ infoLine = infoLine.concat('|').concat(' ').concat(padCol)
|
|
|
+ }
|
|
|
+
|
|
|
+ return infoLine.concat('|')
|
|
|
+ })()
|
|
|
|
|
|
// 价格非法的就不输出了
|
|
|
if ((() => {
|
|
|
- return !OneInchPrice || !BinancePrice || !DistancePrice
|
|
|
+ return !OneInchPrice || !BinancePrice || !DiffPrice
|
|
|
})()) return
|
|
|
-
|
|
|
// 需要输出到文件的打印逻辑
|
|
|
if ((() => {
|
|
|
return percentage > PriceMonitorConfig.percentageLimit
|
|
|
})()) {
|
|
|
- fileLogger.info(`| ${pair}\t\t| ${OneInchPrice}\t\t| ${BinancePrice}\t\t| ${DistancePrice}\t\t| ${percentage}\t\t|`)
|
|
|
+ fileLogger.info(infoLine)
|
|
|
}
|
|
|
- console.info(`| ${pair}\t\t| ${OneInchPrice}\t\t| ${BinancePrice}\t\t| ${DistancePrice}\t\t| ${percentage}\t\t|`)
|
|
|
+ console.info(infoLine)
|
|
|
})
|
|
|
- console.info(`----------------------------------------------------------------------------------------------------------------------------`)
|
|
|
+ console.log(splitLint)
|
|
|
logger.info('')
|
|
|
}
|
|
|
|
|
|
@@ -58,7 +86,7 @@ const onTickFun = async function() {
|
|
|
|
|
|
toToken.OneInchPrice = OneInchPrice
|
|
|
toToken.BinancePrice = BinancePrice
|
|
|
- toToken.DistancePrice = NumKit.getSubFloat(BinancePrice - OneInchPrice, 8)
|
|
|
+ toToken.DiffPrice = NumKit.getSubFloat(BinancePrice - OneInchPrice, 8)
|
|
|
}
|
|
|
|
|
|
// 绘制帧
|