|
|
@@ -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()
|