binance-futures-connector
Advanced tools
Comparing version 1.2.3 to 1.2.4
{ | ||
"name": "binance-futures-connector", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "binance-futures-spot 币安-合约+现货-sdk,持续更新,欢迎PR一起完善。微信:wkc19891", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -273,1 +273,76 @@ module.exports.Future = require('./future') | ||
const buy_xh = (cs,symbol, quantity, price = -1) => { | ||
return new Promise((resolve, reject) => { | ||
if (price < 0) { | ||
cs.newOrder(symbol, 'BUY', 'MARKET', { quoteOrderQty: quantity, newClientOrderId: `x-${brokerId}_${uuid(16)}` }).then(res => { | ||
console.log(symbol, '现货,市价,开多,买入成功', res.status) | ||
resolve(res); | ||
}).catch(err => { | ||
console.log(symbol, '现货,市价,开多,买入异常', err.response.data) | ||
reject(err) | ||
}); | ||
} else { | ||
cs.newOrder(symbol, 'BUY', 'LIMIT', { quantity: quantity, price: price, timeInForce: 'GTC', newClientOrderId: `x-${brokerId}_${uuid(16)}` }).then(res => { | ||
console.log('现货,限价,开多,买入成功', res.status) | ||
resolive(res); | ||
}).catch(err => { | ||
console.log('现货,限价,开多,买入异常', err.response.data) | ||
reject(err) | ||
}); | ||
} | ||
}); | ||
} | ||
module.exports.buy_xh = buy_xh; | ||
const sell_xh = (cs,symbol, quantity, price = -1) => { | ||
return new Promise((resolve, reject) => { | ||
if (price < 0) { | ||
cs.newOrder(symbol, 'SELL', 'MARKET', { quantity: quantity, newClientOrderId: `x-${brokerId}_${uuid(16)}` }).then(res => { | ||
console.log(symbol, '现货,市价,卖出成功', res.status) | ||
resolve(res); | ||
}).catch(err => { | ||
console.log(symbol, '现货,市价,卖出异常', err.response.data) | ||
reject(err) | ||
}); | ||
} else { | ||
cs.newOrder(symbol, 'SELL', 'LIMIT', { quantity: quantity, price: price, timeInForce: 'GTC', newClientOrderId: `x-${brokerId}_${uuid(16)}` }).then(res => { | ||
console.log(symbol, '现货,限价,卖出成功', res.status) | ||
resolve(res); | ||
}).catch(err => { | ||
console.log(symbol, '现货,限价,卖出异常', err.response.data) | ||
reject(err) | ||
}); | ||
} | ||
}); | ||
} | ||
module.exports.sell_xh = sell_xh; | ||
/** | ||
* 标准的OHLC结构,用来画K线和指标计算分析。由exchange.GetRecords()函数返回此结构的数组。每一个Record结构代表一个K线柱,即一根K线BAR。Record其中的Time为这根K线柱周期的起始时间。 | ||
* @param {*} symbol | ||
* @param {*} interval | ||
* @param {*} limit | ||
* @returns | ||
*/ | ||
const records_xh = (cs,symbol, interval, limit = 1000) => { | ||
let records = []; | ||
return new Promise((resolve, reject) => { | ||
cs.klines(symbol, interval, { limit: limit }).then(res => { | ||
res.data.map(v => { | ||
let d = {}; | ||
d.Time = v[0] | ||
d.Open = Number(v[1]) | ||
d.High = Number(v[2]) | ||
d.Low = Number(v[3]) | ||
d.Close = Number(v[4]) | ||
d.Volume = Number(v[5]) | ||
records.push(d); | ||
}); | ||
resolve(records) | ||
}).catch(err => { | ||
console.log(err) | ||
reject(records) | ||
}) | ||
}); | ||
} | ||
module.exports.records_xh = records_xh; |
254130
7283