Forráskód Böngészése

配置文件小改

龚成明 2 éve
szülő
commit
3734cd6a70
6 módosított fájl, 31 hozzáadás és 44 törlés
  1. 9 7
      PrivateConfig.js.sample
  2. 0 9
      config/config.js
  3. 0 8
      config/listen-config.js
  4. 3 3
      libs/one-task.js
  5. 5 4
      libs/test/token-test.js
  6. 14 13
      scripts/one-pro.js

+ 9 - 7
PrivateConfig.js.sample

@@ -3,11 +3,13 @@ class PrivateConfig {}
 // 币安的配置,需要开通提币权限并绑定所在服务器的IP
 PrivateConfig.binanceAPIKey = ''
 PrivateConfig.binanceSecretKey = ''
-// 币安的BSC充值地址
-PrivateConfig.exchangeAddress = ''
-// 你的钱包地址
-PrivateConfig.address = ''
-// 你的钱包私钥
-PrivateConfig.privateKey = ''
 
-module.exports = PrivateConfig
+PrivateConfig.percentageLimit = 0.37           // 两交易所的差价百分比
+PrivateConfig.stopWinHandleSpaceHours = 1      // 止盈后几个小时才能交易
+PrivateConfig.stopLossHandleSpaceHours = 4     // 止损后几个小时才能交易
+PrivateConfig.stopWinPercentage = 2            // 止盈百分比
+PrivateConfig.stopLossPercentage = 2           // 止损百分比
+PrivateConfig.baseTokenAmount = 68             // 交易额
+PrivateConfig.delay = 5000                     // 轮询时间
+
+module.exports = PrivateConfig

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 9
config/config.js


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 8
config/listen-config.js


+ 3 - 3
libs/one-task.js

@@ -10,7 +10,7 @@ OneTask.baseInit = async function() {
   this.context = new Context()
   this.context.binanceSpot = new BinanceSpot(PrivateConfig.binanceAPIKey, PrivateConfig.binanceSecretKey)
 
-  const pairs = Object.values(Config.tokenMapping).map(coin => `${coin}${Config.baseIerc20Token.symbol}` )
+  const pairs = Object.values(PrivateConfig.tokenMapping).map(coin => `${coin}${Config.baseIerc20Token.symbol}` )
   const exchangeInfo = await BinanceSpot.exchangeInfo(pairs)
 
   // 解析priceTickFilter
@@ -39,10 +39,10 @@ OneTask.baseInit = async function() {
   })()
 
   // 初始化IERC20的token
-  await IERC20.batchInit(this.context, Object.keys(Config.tokenMapping))
+  await IERC20.batchInit(this.context, Object.keys(PrivateConfig.tokenMapping))
 
   // 初始化本地token,绑定binance与IERC20
-  await Token.batchInit(this.context, Object.keys(Config.tokenMapping), priceTickFilterMap, lotSizeFilterMap)
+  await Token.batchInit(this.context, Object.keys(PrivateConfig.tokenMapping), priceTickFilterMap, lotSizeFilterMap)
 }
 
 module.exports = OneTask

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

@@ -1,7 +1,8 @@
-const logger = require('../../kit/logger-kit')
+const logger = require('../../kit/logger-kit').getLogger('token-test')
 const IERC20 = require('../web3/ierc20-token')
 const Context = require('../context')
 const Config = require('../../config/config')
+const PrivateConfig = require('../../PrivateConfig')
 const Token = require('../token')
 const BinanceKit = require('../binance/binance-kit')
 const BinanceSpot = require('../binance/binance-spot')
@@ -11,18 +12,18 @@ async function main() {
 
   // 获取priceTickFilter
   const priceTickFilterMap = await (async () => {
-    const pairs = Object.values(Config.tokenMapping).map(coin => `${coin}${Config.baseToken.symbol}` )
+    const pairs = Object.values(PrivateConfig.tokenMapping).map(coin => `${coin}${Config.baseIerc20Token.symbol}` )
     const exchangeInfo = await BinanceSpot.exchangeInfo(pairs)
     return BinanceKit.parsepriceTickFilterMap(exchangeInfo.symbols)
   })()
   logger.info(priceTickFilterMap)
 
   // 初始化IERC20的token
-  await IERC20.batchInit(context, Object.keys(Config.tokenMapping))
+  await IERC20.batchInit(context, Object.keys(PrivateConfig.tokenMapping))
   logger.info(IERC20)
 
   // 初始化本地token,绑定binance与IERC20
-  await Token.batchInit(context, Object.keys(Config.tokenMapping), priceTickFilterMap)
+  await Token.batchInit(context, Object.keys(PrivateConfig.tokenMapping), priceTickFilterMap)
   logger.info(context)
 }
 

+ 14 - 13
scripts/one-pro.js

@@ -2,6 +2,7 @@ const OneTask = require('../libs/one-task')
 const OneInch = require('../libs/web3/1inch')
 const BinanceSpot = require('../libs/binance/binance-spot')
 const Config = require('../config/config')
+const PrivateConfig = require('../PrivateConfig')
 const NumKit = require('../kit/num-kit')
 const TimeKit = require('../kit/time-kit')
 const TableKit = require('../kit/table-kit')
@@ -28,7 +29,7 @@ const orderHandler = async function(context, task) {
     if (token.orderPrice && token.orderAmount > Math.pow(10, -token.exchange.lotSize)) {
       if (token.BinancePrice > token.orderPrice) {
         // 止盈逻辑
-        const isStopWin = token.BinancePrice > (token.orderPrice * (100 + Config.stopWinPercentage) / 100)
+        const isStopWin = token.BinancePrice > (token.orderPrice * (100 + PrivateConfig.stopWinPercentage) / 100)
         if (isStopWin) {
           const sellRst = await binanceSpot.sell(pair, -1, token.orderAmount)
 
@@ -39,17 +40,17 @@ const orderHandler = async function(context, task) {
 
             fileLogger.info(`[止盈]${pair}, price: ${token.orderPrice}->${price}, amount: ${token.orderAmount}.`)
             token.orderPrice = undefined
-            token.nextHandleTime = new Date().getTime() + Config.stopWinHandleSpaceHours * (60 * 60 * 1000)
+            token.nextHandleTime = new Date().getTime() + PrivateConfig.stopWinHandleSpaceHours * (60 * 60 * 1000)
           } else {
             token.orderPrice = undefined
-            token.nextHandleTime = new Date().getTime() + Config.stopWinHandleSpaceHours * (60 * 60 * 1000)
+            token.nextHandleTime = new Date().getTime() + PrivateConfig.stopWinHandleSpaceHours * (60 * 60 * 1000)
 
             fileLogger.error(`[止盈失败]${pair}, ${JSON.stringify(sellRst)}`)
           }
         }
       } else {
         // 止损逻辑
-        const isStopLoss = token.BinancePrice < (token.orderPrice * (100 - Config.stopLossPercentage) / 100)
+        const isStopLoss = token.BinancePrice < (token.orderPrice * (100 - PrivateConfig.stopLossPercentage) / 100)
         if (isStopLoss) {
           const sellRst = await binanceSpot.sell(pair, -1, token.orderAmount)
 
@@ -60,10 +61,10 @@ const orderHandler = async function(context, task) {
 
             fileLogger.info(`[止损]${pair}, price: ${token.orderPrice}->${price}, amount: ${token.orderAmount}.`)
             token.orderPrice = undefined
-            token.nextHandleTime = new Date().getTime() + Config.stopLossHandleSpaceHours * (60 * 60 * 1000)
+            token.nextHandleTime = new Date().getTime() + PrivateConfig.stopLossHandleSpaceHours * (60 * 60 * 1000)
           } else {
             token.orderPrice = undefined
-            token.nextHandleTime = new Date().getTime() + Config.stopLossHandleSpaceHours * (60 * 60 * 1000)
+            token.nextHandleTime = new Date().getTime() + PrivateConfig.stopLossHandleSpaceHours * (60 * 60 * 1000)
 
             fileLogger.error(`[止损失败]${pair}, ${JSON.stringify(sellRst)}`)
           }
@@ -74,15 +75,15 @@ const orderHandler = async function(context, task) {
       const baseAssetAmount = accountAssetMap[Config.baseIerc20Token.symbol]
 
       // 判断余额是否够下单
-      if (Config.baseTokenAmount > baseAssetAmount) {
-        fileLogger.info(`[余额不足]${pair}, 需要: ${Config.baseTokenAmount}, 剩余: ${baseAssetAmount}.`)
-        token.nextHandleTime = new Date().getTime() + Config.stopLossHandleSpaceHours * (60 * 60 * 1000)
+      if (PrivateConfig.baseTokenAmount > baseAssetAmount) {
+        fileLogger.info(`[余额不足]${pair}, 需要: ${PrivateConfig.baseTokenAmount}, 剩余: ${baseAssetAmount}.`)
+        token.nextHandleTime = new Date().getTime() + PrivateConfig.stopLossHandleSpaceHours * (60 * 60 * 1000)
 
         continue;
       }
 
       // 2. 下单获取成交数量以及平均价格
-      const buyRst = await binanceSpot.buy(pair, -1, Config.baseTokenAmount)
+      const buyRst = await binanceSpot.buy(pair, -1, PrivateConfig.baseTokenAmount)
 
       if (buyRst.executedQty) {
         const cummulativeQuoteQty = NumKit.getSubFloat(buyRst.cummulativeQuoteQty, 6)
@@ -139,7 +140,7 @@ const showInfo = function(context, task) {
 
     // 识别到在拉盘
     token.isLong = (() => {
-      const percentageCondition = percentage > Config.percentageLimit
+      const percentageCondition = percentage > PrivateConfig.percentageLimit
 
       const isNoPrevHandleTime = !token.nextHandleTime
       const isTimeCover = new Date().getTime() > token.nextHandleTime
@@ -166,7 +167,7 @@ const priceHandler = async function(context, task) {
     const toToken = tokenMap[tokenHash]
     const priceTick = toToken.exchange.priceTick
     const fromIerc20Token = Config.baseIerc20Token
-    const amount = Config.baseTokenAmount
+    const amount = PrivateConfig.baseTokenAmount
 
     const OneInchPrice = NumKit.getSubFloat(await OneInch.price(fromIerc20Token.contract, tokenHash, amount), priceTick)
     const BinancePrice = NumKit.getSubFloat(await BinanceSpot.realPrice(toToken.exchange.pair), priceTick)
@@ -204,6 +205,6 @@ const onTickFun = async function() {
   await orderHandler(context, task)
 }
 
-const onePro = new OneTask('OnePro', Config.delay, OneTask.baseInit, onTickFun)
+const onePro = new OneTask('OnePro', PrivateConfig.delay, OneTask.baseInit, onTickFun)
 
 onePro.Start()

Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott