|
|
@@ -13,10 +13,36 @@ const orderHandler = function(context, task) {
|
|
|
Object.keys(tokenMap).forEach((tokenHash) => {
|
|
|
const token = tokenMap[tokenHash]
|
|
|
const pair = token.exchange.pair
|
|
|
+
|
|
|
+ if (token.orderPrice) {
|
|
|
+ // TODO 对接卖出交易
|
|
|
+ if (token.BinancePrice > token.orderPrice) {
|
|
|
+ // 止盈逻辑
|
|
|
+ const isStopWin = token.BinancePrice > (token.orderPrice * (100 + Config.stopWinPercentage) / 100)
|
|
|
+ if (isStopWin) {
|
|
|
+ token.orderPrice = undefined
|
|
|
+ fileLogger.info(`[止盈]${pair}, price: ${token.orderPrice}, amount: ${token.orderAmount}.`)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 止损逻辑
|
|
|
+ const isStopLoss = token.BinancePrice < (token.orderPrice * (100 - Config.stopLossPercentage) / 100)
|
|
|
+ if (isStopLoss) {
|
|
|
+ token.orderPrice = undefined
|
|
|
+ fileLogger.info(`[止损]${pair}, price: ${token.orderPrice}, amount: ${token.orderAmount}.`)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // TODO 对接买入交易
|
|
|
+ token.orderPrice = token.BinancePrice
|
|
|
+ token.orderBaseAmount = Config.baseTokenAmount
|
|
|
+ token.orderAmount = NaN
|
|
|
+
|
|
|
+ fileLogger.info(`[订单]${pair}, price: ${token.orderPrice}, amount: ${token.orderAmount}.`)
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-const table = new TableKit(['pair', 'binance'], 25)
|
|
|
+const table = new TableKit(['pair', 'binance', 'order price'], 25)
|
|
|
|
|
|
const pricesHandler = function(context, task) {
|
|
|
const logger = task.logger
|
|
|
@@ -32,13 +58,14 @@ const pricesHandler = function(context, task) {
|
|
|
const BinancePrice = token.BinancePrice ? token.BinancePrice : NaN
|
|
|
const DiffPrice = token.DiffPrice
|
|
|
const percentage = NumKit.getSubFloat((DiffPrice / OneInchPrice) * 100, 2)
|
|
|
+ const orderPrice = token.orderPrice ? token.orderPrice : 0
|
|
|
|
|
|
// 价格非法的就不处理了
|
|
|
// if ((() => {
|
|
|
//
|
|
|
// })()) return
|
|
|
|
|
|
- const rows = [pair.toString(), BinancePrice.toString()]
|
|
|
+ const rows = [pair.toString(), BinancePrice.toString(), orderPrice]
|
|
|
|
|
|
// 识别到在拉盘
|
|
|
token.isLong = (() => {
|
|
|
@@ -55,7 +82,7 @@ const pricesHandler = function(context, task) {
|
|
|
token.prevHandleTime = new Date().getTime()
|
|
|
}
|
|
|
// 打印表格
|
|
|
- table.showLine(rows, token.isLong ? fileLogger : undefined)
|
|
|
+ table.showLine(rows, undefined)
|
|
|
})
|
|
|
table.printEndLine(logger)
|
|
|
}
|