|
@@ -2,6 +2,7 @@ const OneTask = require('../../libs/one-task')
|
|
|
const OneInch = require('../../libs/web3/1inch')
|
|
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 showPrices = function(context, task) {
|
|
const showPrices = function(context, task) {
|
|
|
const logger = task.logger
|
|
const logger = task.logger
|
|
@@ -10,22 +11,30 @@ const showPrices = function(context, task) {
|
|
|
|
|
|
|
|
console.clear()
|
|
console.clear()
|
|
|
|
|
|
|
|
- console.info(`-----------------------------------------------------------------------------------------------------------------`)
|
|
|
|
|
- console.info(`| pair\t\t\t| 1inch\t\t\t\t| binance\t\t| distance\t\t\t|`)
|
|
|
|
|
- console.info(`-----------------------------------------------------------------------------------------------------------------`)
|
|
|
|
|
|
|
+ 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(`----------------------------------------------------------------------------------------------------------------------------`)
|
|
|
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
|
|
|
const OneInchPrice = token.OneInchPrice
|
|
const OneInchPrice = token.OneInchPrice
|
|
|
const BinancePrice = token.BinancePrice
|
|
const BinancePrice = token.BinancePrice
|
|
|
- const distancePrice = BinancePrice - OneInchPrice
|
|
|
|
|
|
|
+ const DistancePrice = token.DistancePrice
|
|
|
|
|
|
|
|
- if (distancePrice > 0) {
|
|
|
|
|
- fileLogger.info(`| ${pair}\t\t| ${OneInchPrice}\t\t| ${BinancePrice}\t\t| ${distancePrice}\t\t|`)
|
|
|
|
|
|
|
+ const percentage = NumKit.getSubFloat((DistancePrice / OneInchPrice) * 100, 2)
|
|
|
|
|
+
|
|
|
|
|
+ // 价格非法的就不输出了
|
|
|
|
|
+ if ((() => {
|
|
|
|
|
+ return !OneInchPrice || !BinancePrice || !DistancePrice
|
|
|
|
|
+ })()) return
|
|
|
|
|
+
|
|
|
|
|
+ // 打印逻辑
|
|
|
|
|
+ if (DistancePrice > 0) {
|
|
|
|
|
+ fileLogger.info(`| ${pair}\t\t| ${OneInchPrice}\t\t| ${BinancePrice}\t\t| ${DistancePrice}\t\t| ${percentage}\t\t|`)
|
|
|
}
|
|
}
|
|
|
- console.info(`| ${pair}\t\t| ${OneInchPrice}\t\t| ${BinancePrice}\t\t| ${distancePrice}\t\t|`)
|
|
|
|
|
|
|
+ console.info(`| ${pair}\t\t| ${OneInchPrice}\t\t| ${BinancePrice}\t\t| ${DistancePrice}\t\t| ${percentage}\t\t|`)
|
|
|
})
|
|
})
|
|
|
- console.info(`-----------------------------------------------------------------------------------------------------------------`)
|
|
|
|
|
|
|
+ console.info(`----------------------------------------------------------------------------------------------------------------------------`)
|
|
|
logger.info('')
|
|
logger.info('')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -41,11 +50,12 @@ const onTickFun = async function() {
|
|
|
const fromIerc20Token = Config.baseIerc20Token
|
|
const fromIerc20Token = Config.baseIerc20Token
|
|
|
const amount = Config.baseTokenAmount
|
|
const amount = Config.baseTokenAmount
|
|
|
|
|
|
|
|
- const OneInchPrice = await OneInch.price(fromIerc20Token.contract, tokenHash, amount)
|
|
|
|
|
- const BinancePrice = await BinanceSpot.realPrice(toToken.exchange.pair)
|
|
|
|
|
|
|
+ const OneInchPrice = NumKit.getSubFloat(await OneInch.price(fromIerc20Token.contract, tokenHash, amount), 8)
|
|
|
|
|
+ const BinancePrice = NumKit.getSubFloat(await BinanceSpot.realPrice(toToken.exchange.pair), 8)
|
|
|
|
|
|
|
|
toToken.OneInchPrice = OneInchPrice
|
|
toToken.OneInchPrice = OneInchPrice
|
|
|
toToken.BinancePrice = BinancePrice
|
|
toToken.BinancePrice = BinancePrice
|
|
|
|
|
+ toToken.DistancePrice = NumKit.getSubFloat(BinancePrice - OneInchPrice, 8)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 绘制帧
|
|
// 绘制帧
|