浏览代码

1. 取消止损4个小时才交易的限制
2. 普通止盈、止损都只需要等一个小时
3. 赋予强制止盈、止损单独的等待时间

龚成明 2 年之前
父节点
当前提交
dc693c565f
共有 2 个文件被更改,包括 18 次插入9 次删除
  1. 8 5
      PrivateConfig.js.sample
  2. 10 4
      scripts/one-pro.js

+ 8 - 5
PrivateConfig.js.sample

@@ -5,13 +5,16 @@ PrivateConfig.binanceAPIKey = ''
 PrivateConfig.binanceSecretKey = ''
 
 PrivateConfig.percentageLimit = 0.37           // 两交易所的差价百分比
-PrivateConfig.stopWinHandleSpaceHours = 1      // 止盈后几个小时才能交易
-PrivateConfig.stopLossHandleSpaceHours = 4     // 止损后几个小时才能交易
+
+PrivateConfig.normalStopHandleSpaceHours = 2   // 正常平仓后几个小时才能交易
+PrivateConfig.hardStopHandleSpaceHours = 6     // 强制平仓后几小时才能交易
+
 PrivateConfig.stopWinTimeOverHours = 12        // 盈利时持仓时间
-PrivateConfig.stopLossTimeOverHours = 2        // 亏损时持仓时间
+PrivateConfig.stopLossTimeOverHours = 10       // 亏损时持仓时间
 PrivateConfig.hardStopWinPercentage = 100      // 强制止盈百分比
-PrivateConfig.hardStopLossPercentage = 10      // 强制止损百分比
-PrivateConfig.baseTokenAmount = 68             // 交易额
+PrivateConfig.hardStopLossPercentage = 5       // 强制止损百分比
+
+PrivateConfig.baseTokenAmount = 50             // 交易额
 PrivateConfig.delay = 5000                     // 轮询时间
 
 PrivateConfig.tokenMapping = {

+ 10 - 4
scripts/one-pro.js

@@ -26,6 +26,7 @@ const holdingHandler = async function(context, task, token, pair) {
   const isStopLoss = isHardStopLoss || isTimeOverStopLoss
 
   const isTimeOverStop = isTimeOverStopWin || isTimeOverStopLoss
+  const isHardStop = isHardStopWin || isHardStopLoss
 
   assert.notEqual(isStopWin && isStopLoss, true, '止盈止损逻辑错误,请认真检查。')
 
@@ -35,7 +36,12 @@ const holdingHandler = async function(context, task, token, pair) {
 
     token.orderPrice = undefined
     token.orderAmount = undefined
-    token.nextHandleTime = nowTimestamp + config.stopLossHandleSpaceHours * TimeKit.ONE_HOUR
+
+    if (isHardStop) {
+      token.nextHandleTime = nowTimestamp + config.hardStopHandleSpaceHours * TimeKit.ONE_HOUR
+    } else if (isTimeOverStop) {
+      token.nextHandleTime = nowTimestamp + config.normalStopHandleSpaceHours * TimeKit.ONE_HOUR
+    }
 
     try {
       const sellMarketRst = await binanceSpot.sellMarket(pair, orderAmount)
@@ -46,11 +52,11 @@ const holdingHandler = async function(context, task, token, pair) {
       // 交易数据持久化
       await token.save()
 
-      const log = `[${isTimeOverStop ? '时' : '强'}${isStopWin ? '盈+' : '损-'}]${pair}, `
+      const log = `[${isHardStop ? '强' : '时'}${isStopWin ? '盈+' : '损-'}]${pair}, `
         + `成交额${cummulativeQuoteQty}, 均价${orderPrice}->${price}, 卖出${orderAmount}个.`
       fileLogger.info(log)
     } catch (e) {
-      const log = `[${isTimeOverStop ? '时' : '强'}止${isStopWin ? '盈' : '损'}失败]${pair}, ${e}`
+      const log = `[${isHardStop ? '强' : '时'}${isStopWin ? '盈' : '损'}失败]${pair}, ${e}`
       fileLogger.error(log)
     }
   }
@@ -70,7 +76,7 @@ const noHoldingHandler = async function(context, task, token, pair) {
   // 2. 判断余额是否够下单
   if (config.baseTokenAmount > baseAssetAmount) {
     fileLogger.info(`[余额不足]${pair}, 需要: ${config.baseTokenAmount}, 剩余: ${baseAssetAmount}.`)
-    token.nextHandleTime = nowTimestamp + config.stopLossHandleSpaceHours * TimeKit.ONE_HOUR
+    token.nextHandleTime = nowTimestamp + config.normalStopHandleSpaceHours * TimeKit.ONE_HOUR
 
     return
   }