|
@@ -21,8 +21,11 @@ const orderHandler = async function(context, task) {
|
|
|
// 价格非法判定
|
|
// 价格非法判定
|
|
|
if (!token.BinancePrice || !token.OneInchPrice) continue;
|
|
if (!token.BinancePrice || !token.OneInchPrice) continue;
|
|
|
|
|
|
|
|
|
|
+ // 更新token的实际余额
|
|
|
|
|
+ token.orderAmount = NumKit.getSubFloat(accountAssetMap[token.exchange.symbol], token.exchange.lotSize)
|
|
|
|
|
+
|
|
|
// 卖出逻辑判定
|
|
// 卖出逻辑判定
|
|
|
- if (token.orderPrice) {
|
|
|
|
|
|
|
+ if (token.orderPrice && token.orderAmount > Math.pow(10, -token.exchange.lotSize)) {
|
|
|
if (token.BinancePrice > token.orderPrice) {
|
|
if (token.BinancePrice > token.orderPrice) {
|
|
|
// 止盈逻辑
|
|
// 止盈逻辑
|
|
|
const isStopWin = token.BinancePrice > (token.orderPrice * (100 + Config.stopWinPercentage) / 100)
|
|
const isStopWin = token.BinancePrice > (token.orderPrice * (100 + Config.stopWinPercentage) / 100)
|
|
@@ -83,7 +86,16 @@ const orderHandler = async function(context, task) {
|
|
|
|
|
|
|
|
if (buyRst.executedQty) {
|
|
if (buyRst.executedQty) {
|
|
|
const cummulativeQuoteQty = NumKit.getSubFloat(buyRst.cummulativeQuoteQty, 6)
|
|
const cummulativeQuoteQty = NumKit.getSubFloat(buyRst.cummulativeQuoteQty, 6)
|
|
|
- const executedQty = NumKit.getSubFloat(buyRst.executedQty, token.exchange.lotSize)
|
|
|
|
|
|
|
+ // 计算扣除手续费后的实际成交数量
|
|
|
|
|
+ let executedQty = 0
|
|
|
|
|
+ for (const fill of orderRst.fills) {
|
|
|
|
|
+ executedQty += parseFloat(fill.qty)
|
|
|
|
|
+ // 扣除支付的手续费
|
|
|
|
|
+ if (fill.commissionAsset === 'HOOK') {
|
|
|
|
|
+ executedQty -= parseFloat(fill.commission)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ executedQty = NumKit.getSubFloat(executedQty, token.exchange.lotSize)
|
|
|
|
|
|
|
|
token.orderAmount = executedQty
|
|
token.orderAmount = executedQty
|
|
|
token.orderPrice = cummulativeQuoteQty / executedQty
|
|
token.orderPrice = cummulativeQuoteQty / executedQty
|
|
@@ -102,6 +114,7 @@ const table = new TableKit(['pair', '1inch', 'binance', 'order price', 'profit(%
|
|
|
const showInfo = function(context, task) {
|
|
const showInfo = function(context, task) {
|
|
|
const logger = task.logger
|
|
const logger = task.logger
|
|
|
const tokenMap = context.tokenMap
|
|
const tokenMap = context.tokenMap
|
|
|
|
|
+ const accountAssetMap = context.accountAssetMap
|
|
|
|
|
|
|
|
table.printTitles()
|
|
table.printTitles()
|
|
|
|
|
|
|
@@ -139,6 +152,10 @@ const showInfo = function(context, task) {
|
|
|
table.showLine(rows, undefined)
|
|
table.showLine(rows, undefined)
|
|
|
})
|
|
})
|
|
|
table.printEndLine(logger)
|
|
table.printEndLine(logger)
|
|
|
|
|
+
|
|
|
|
|
+ logger.info(`base asset amount: ${accountAssetMap[Config.baseIerc20Token.symbol]}.`)
|
|
|
|
|
+ logger.info('')
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const priceHandler = async function(context, task) {
|
|
const priceHandler = async function(context, task) {
|