Ver Fonte

修复priceTick

龚成明 há 2 anos atrás
pai
commit
31e6235295

+ 5 - 5
config/config.js

@@ -39,21 +39,21 @@ Config.tokenMapping = {
   '0xa260E12d2B924cb899AE80BB58123ac3fEE1E2F0': 'HOOK',
   '0x4338665CBB7B2485A8855A139b75D5e34AB0DB94': 'LTC',
   '0x7083609fce4d1d8dc0c979aab8c869ea2c873402': 'DOT',
-  // '0x0eb3a705fc54725037cc9e008bdede697f62f335': 'ATOM',
+  '0x0eb3a705fc54725037cc9e008bdede697f62f335': 'ATOM',
   '0xaec945e04baf28b135fa7c640f624f8d90f1c3a6': 'C98',
   '0x8ff795a6f4d97e7887c79bea79aba5cc76444adf': 'BCH',
   '0xbf5140a22578168fd562dccf235e5d43a02ce9b1': 'UNI',
-  // '0xe02df9e3e622debdd69fb838bb799e3f168902c5': 'BAKE',
+  '0xe02df9e3e622debdd69fb838bb799e3f168902c5': 'BAKE',
   '0xf8a0bf9cf54bb92f17374d9e9a321e6a111a51bd': 'LINK',
-  // '0x16939ef78684453bfdfb47825f8a5f714f12623a': 'XTZ',
-  // '0xae9269f27437f0fcbc232d39ec814844a51d6b8f': 'BURGER',
+  '0x16939ef78684453bfdfb47825f8a5f714f12623a': 'XTZ',
+  '0xae9269f27437f0fcbc232d39ec814844a51d6b8f': 'BURGER',
   '0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82': 'CAKE',
   '0xba2ae424d960c26247dd6c32edc70b295c744c43': 'DOGE',
   '0x2859e4544C4bB03966803b044A93563Bd2D0DD4D': 'SHIB',
   '0x0D8Ce2A99Bb6e3B7Db580eD848240e4a0F9aE153': 'FIL',
   '0x570A5D26f7765Ecb712C0924E4De545B89fD43dF': 'SOL',
   '0x67b725d7e342d7B611fa85e859Df9697D9378B2e': 'SAND',
-  // '0x728C5baC3C3e370E372Fc4671f9ef6916b814d8B': 'UNFI'
+  '0x728C5baC3C3e370E372Fc4671f9ef6916b814d8B': 'UNFI'
 }
 
 module.exports = Config

+ 3 - 3
libs/binance/binance-kit.js

@@ -38,15 +38,15 @@ module.exports = class BinanceKit {
     return `${buffer}]`
   }
 
-  static parseLotSizeFilterMap(pairInfoList) {
+  static parsePriceTickFilterMap(pairInfoList) {
     if (pairInfoList === undefined) throw new Error('exchange info symbols is undefined!')
 
     const filterMap = {}
 
     pairInfoList.forEach(function (pairInfo) {
-      const lotSizeFilter = pairInfo.filters.filter(filterObj => filterObj.filterType === 'LOT_SIZE')[0]
+      const priceTickFilter = pairInfo.filters.filter(filterObj => filterObj.filterType === 'PRICE_FILTER')[0]
 
-      filterMap[pairInfo.symbol] = Math.log10(1 / parseFloat(lotSizeFilter.stepSize))
+      filterMap[pairInfo.symbol] = Math.log10(1 / parseFloat(priceTickFilter.tickSize))
     })
 
     return filterMap

+ 1 - 1
libs/binance/test/binance-spot-test.js

@@ -14,7 +14,7 @@ async function exchangeInfoTest() {
   const pairs = Object.values(Config.tokenMapping).map(coin => `${coin}${Config.baseToken.symbol}` )
   const exchangeInfo = await BinanceSpot.exchangeInfo(pairs)
 
-  logger.info(BinanceKit.parseLotSizeFilterMap(exchangeInfo.symbols))
+  logger.info(BinanceKit.parsepriceTickFilterMap(exchangeInfo.symbols))
   logger.info('')
 }
 

+ 4 - 4
libs/one-task.js

@@ -9,18 +9,18 @@ const Token = require("./token");
 OneTask.baseInit = async function() {
   this.context = new Context()
 
-  // 获取lotSizeFilter
-  const lotSizeFilterMap = await (async () => {
+  // 获取priceTickFilter
+  const priceTickFilterMap = await (async () => {
     const pairs = Object.values(Config.tokenMapping).map(coin => `${coin}${Config.baseIerc20Token.symbol}` )
     const exchangeInfo = await BinanceSpot.exchangeInfo(pairs)
-    return BinanceKit.parseLotSizeFilterMap(exchangeInfo.symbols)
+    return BinanceKit.parsePriceTickFilterMap(exchangeInfo.symbols)
   })()
 
   // 初始化IERC20的token
   await IERC20.batchInit(this.context, Object.keys(Config.tokenMapping))
 
   // 初始化本地token,绑定binance与IERC20
-  await Token.batchInit(this.context, Object.keys(Config.tokenMapping), lotSizeFilterMap)
+  await Token.batchInit(this.context, Object.keys(Config.tokenMapping), priceTickFilterMap)
 }
 
 module.exports = OneTask

+ 5 - 5
libs/test/token-test.js

@@ -9,20 +9,20 @@ const BinanceSpot = require('../binance/binance-spot')
 async function main() {
   const context = new Context()
 
-  // 获取lotSizeFilter
-  const lotSizeFilterMap = await (async () => {
+  // 获取priceTickFilter
+  const priceTickFilterMap = await (async () => {
     const pairs = Object.values(Config.tokenMapping).map(coin => `${coin}${Config.baseToken.symbol}` )
     const exchangeInfo = await BinanceSpot.exchangeInfo(pairs)
-    return BinanceKit.parseLotSizeFilterMap(exchangeInfo.symbols)
+    return BinanceKit.parsepriceTickFilterMap(exchangeInfo.symbols)
   })()
-  logger.info(lotSizeFilterMap)
+  logger.info(priceTickFilterMap)
 
   // 初始化IERC20的token
   await IERC20.batchInit(context, Object.keys(Config.tokenMapping))
   logger.info(IERC20)
 
   // 初始化本地token,绑定binance与IERC20
-  await Token.batchInit(context, Object.keys(Config.tokenMapping), lotSizeFilterMap)
+  await Token.batchInit(context, Object.keys(Config.tokenMapping), priceTickFilterMap)
   logger.info(context)
 }
 

+ 7 - 7
libs/token.js

@@ -5,30 +5,30 @@ module.exports = class Token {
   exchange = {}
   ierc20 = {}
 
-  constructor(exchangeSymbol, exchangeLotSize, exchangePair, ierc20Decimals) {
+  constructor(exchangeSymbol, exchangePriceTick, exchangePair, ierc20Decimals) {
     this.exchange.symbol = exchangeSymbol
-    this.exchange.lotSize = exchangeLotSize
+    this.exchange.priceTick = exchangePriceTick
     this.exchange.pair = exchangePair
 
     this.ierc20.decimals = ierc20Decimals
   }
 
-  static async init(context, tokenHash, lotSizeFilterMap) {
+  static async init(context, tokenHash, priceTickFilterMap) {
     // token初始化
     const ierc20Decimals = parseInt(await IERC20.getDecimals(tokenHash))
     const exchangeSymbol = Config.tokenMapping[tokenHash]
     const exchangePair = `${exchangeSymbol}${Config.baseIerc20Token.symbol}`
-    const exchangeLotSize = lotSizeFilterMap[exchangePair]
+    const exchangePriceTick = priceTickFilterMap[exchangePair]
 
-    context.tokenMap[tokenHash] = new Token(exchangeSymbol, exchangeLotSize, exchangePair, ierc20Decimals)
+    context.tokenMap[tokenHash] = new Token(exchangeSymbol, exchangePriceTick, exchangePair, ierc20Decimals)
   }
 
-  static async batchInit(context, ierc20TokenAddressList, lotSizeFilterMap) {
+  static async batchInit(context, ierc20TokenAddressList, priceTickFilterMap) {
     context.tokenMap = {}
 
     for (const tokenHash of ierc20TokenAddressList) {
       // 初始化token
-      await Token.init(context, tokenHash, lotSizeFilterMap)
+      await Token.init(context, tokenHash, priceTickFilterMap)
     }
   }
 }

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

@@ -48,23 +48,23 @@ const onTickFun = async function() {
   // 搜集所有价格数据
   for (const tokenHash of tokenContractAddressList) {
     const toToken = tokenMap[tokenHash]
-    const lotSize = toToken.exchange.lotSize
+    const priceTick = toToken.exchange.priceTick
     const fromIerc20Token = Config.baseIerc20Token
     const amount = Config.baseTokenAmount
 
-    const OneInchPrice = NumKit.getSubFloat(await OneInch.price(fromIerc20Token.contract, tokenHash, amount), lotSize)
-    const BinancePrice = NumKit.getSubFloat(await BinanceSpot.realPrice(toToken.exchange.pair), lotSize)
+    const OneInchPrice = NumKit.getSubFloat(await OneInch.price(fromIerc20Token.contract, tokenHash, amount), priceTick)
+    const BinancePrice = NumKit.getSubFloat(await BinanceSpot.realPrice(toToken.exchange.pair), priceTick)
 
     toToken.OneInchPrice = OneInchPrice
     toToken.BinancePrice = BinancePrice
     toToken.DiffPrice = BinancePrice - OneInchPrice
 
     if ((() => {
-      return Math.abs(toToken.DiffPrice) < Math.pow(10, -lotSize)
+      return Math.abs(toToken.DiffPrice) < Math.pow(10, -priceTick)
     })()) {
       toToken.DiffPrice = 0
     } {
-      toToken.DiffPrice = NumKit.getSubFloat(toToken.DiffPrice, lotSize)
+      toToken.DiffPrice = NumKit.getSubFloat(toToken.DiffPrice, priceTick)
     }
   }