|
@@ -3,34 +3,18 @@ const OneInch = require('../../libs/web3/1inch')
|
|
|
const BinanceSpot = require('../../libs/binance/binance-spot')
|
|
const BinanceSpot = require('../../libs/binance/binance-spot')
|
|
|
const Config = require('../../config/config')
|
|
const Config = require('../../config/config')
|
|
|
const NumKit = require('../../kit/num-kit')
|
|
const NumKit = require('../../kit/num-kit')
|
|
|
|
|
+const TableKit = require('../../kit/table-kit')
|
|
|
const PriceMonitorConfig = require('./config/price-monitor-config')
|
|
const PriceMonitorConfig = require('./config/price-monitor-config')
|
|
|
|
|
|
|
|
|
|
+const table = new TableKit(['pair', '1inch', 'binance', 'diff', 'percentage'])
|
|
|
|
|
+
|
|
|
const showPrices = function(context, task) {
|
|
const showPrices = function(context, task) {
|
|
|
const logger = task.logger
|
|
const logger = task.logger
|
|
|
const fileLogger = task.fileLogger
|
|
const fileLogger = task.fileLogger
|
|
|
const tokenMap = context.tokenMap
|
|
const tokenMap = context.tokenMap
|
|
|
|
|
|
|
|
- const titles = ['pair', '1inch', 'binance', 'diff', 'percentage']
|
|
|
|
|
- const colWidth = 30
|
|
|
|
|
- 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()
|
|
|
|
|
|
|
+ table.printTitles()
|
|
|
|
|
|
|
|
- console.info(splitLint)
|
|
|
|
|
- console.info(titleLine)
|
|
|
|
|
- console.info(splitLint)
|
|
|
|
|
Object.keys(tokenMap).forEach((tokenHash) => {
|
|
Object.keys(tokenMap).forEach((tokenHash) => {
|
|
|
const token = tokenMap[tokenHash]
|
|
const token = tokenMap[tokenHash]
|
|
|
const pair = token.exchange.pair
|
|
const pair = token.exchange.pair
|
|
@@ -39,34 +23,20 @@ const showPrices = function(context, task) {
|
|
|
const DiffPrice = token.DiffPrice
|
|
const DiffPrice = token.DiffPrice
|
|
|
const percentage = NumKit.getSubFloat((DiffPrice / OneInchPrice) * 100, 2)
|
|
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 = ''
|
|
|
|
|
-
|
|
|
|
|
- for (const padCol of padCols) {
|
|
|
|
|
- infoLine = infoLine.concat('|').concat(' ').concat(padCol)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return infoLine.concat('|')
|
|
|
|
|
- })()
|
|
|
|
|
-
|
|
|
|
|
// 价格非法的就不输出了
|
|
// 价格非法的就不输出了
|
|
|
if ((() => {
|
|
if ((() => {
|
|
|
return !OneInchPrice || !BinancePrice
|
|
return !OneInchPrice || !BinancePrice
|
|
|
})()) return
|
|
})()) return
|
|
|
|
|
+
|
|
|
|
|
+ const rows = [pair.toString(), OneInchPrice.toString(), BinancePrice.toString(), DiffPrice.toString(), percentage.toString()]
|
|
|
|
|
+
|
|
|
// 需要输出到文件的打印逻辑
|
|
// 需要输出到文件的打印逻辑
|
|
|
- if ((() => {
|
|
|
|
|
|
|
+ const isLogToFile = (() => {
|
|
|
return percentage > PriceMonitorConfig.percentageLimit
|
|
return percentage > PriceMonitorConfig.percentageLimit
|
|
|
- })()) {
|
|
|
|
|
- fileLogger.info(infoLine)
|
|
|
|
|
- }
|
|
|
|
|
- console.info(infoLine)
|
|
|
|
|
|
|
+ })()
|
|
|
|
|
+ table.showLine(rows, isLogToFile ? fileLogger : undefined)
|
|
|
})
|
|
})
|
|
|
- console.log(splitLint)
|
|
|
|
|
- logger.info('')
|
|
|
|
|
|
|
+ table.printEndLine(logger)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const onTickFun = async function() {
|
|
const onTickFun = async function() {
|