binance-futures-connector
Advanced tools
Comparing version 1.1.8 to 1.1.9
{ | ||
"name": "binance-futures-connector", | ||
"version": "1.1.8", | ||
"description": "binance-futures-connector 币安-合约+现货-sdk,持续更新,欢迎PR一起完善。微信:wkc19891", | ||
"version": "1.1.9", | ||
"description": "binance-futures-spot 币安-合约+现货-sdk,持续更新,欢迎PR一起完善。微信:wkc19891", | ||
"main": "src/index.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
@@ -46,23 +46,2 @@ # binance-futures-connector in nodejs | ||
```javascript | ||
const { Future } = require('binance-futures-connector') | ||
const apiKey = '' | ||
const apiSecret = '' | ||
const client = new Future(apiKey, apiSecret) | ||
// Get account information | ||
client.account().then(response => client.logger.log(response.data)) | ||
// Place a new order | ||
client.newOrder('BNBUSDT', 'BUY', 'LIMIT', { | ||
price: '350', | ||
quantity: 1, | ||
timeInForce: 'GTC' | ||
}).then(response => client.logger.log(response.data)) | ||
.catch(error => client.logger.error(error)) | ||
``` | ||
### Base URL | ||
@@ -69,0 +48,0 @@ |
132
src/index.js
@@ -115,1 +115,133 @@ module.exports.Future = require('./future') | ||
module.exports.LogProfit = LogProfit | ||
/** | ||
* 合约多单买入 | ||
* @param {*} cf | ||
* @param {*} symbol | ||
* @param {*} quantity | ||
* @param {*} price | ||
* @param {*} flagPrice | ||
* @returns | ||
*/ | ||
const buy = (cf, symbol, quantity, price = -1, flagPrice = 0) => { | ||
return new Promise((resolve, reject) => { | ||
if (price < 0) { | ||
cf.newOrder(symbol, 'BUY', 'LONG', 'MARKET', { quantity: quantity }).then(res => { | ||
console.log(symbol, `市价,开多,买入成功=>数量:${quantity} | 价格:${flagPrice}`) | ||
resolve(res); | ||
}).catch(err => { | ||
console.log(symbol, `市价,开多,买入异常=>数量:${quantity} | 价格:${flagPrice}`, err) | ||
reject(err) | ||
}); | ||
} else { | ||
cf.newOrder(symbol, 'BUY', 'LONG', 'LIMIT', { quantity: quantity, price: price, timeInForce: 'GTC' }).then(res => { | ||
console.log(symbol, `限价,开多,买入成功=>数量:${quantity} | 价格:${price}`) | ||
resolve(res); | ||
}).catch(err => { | ||
console.log(symbol, `限价,开多,买入异常=>数量:${quantity} | 价格:${price}`, err) | ||
reject(err) | ||
}); | ||
} | ||
}); | ||
} | ||
/** | ||
* 合约多单-卖出平多 | ||
* @param {*} cf | ||
* @param {*} symbol | ||
* @param {*} quantity | ||
* @param {*} price | ||
* @param {*} flagPrice | ||
* @returns | ||
*/ | ||
const buy_close = (cf, symbol, quantity, price = -1, flagPrice = 0) => { | ||
return new Promise((resolve, reject) => { | ||
if (price < 0) { | ||
cf.newOrder(symbol, 'SELL', 'LONG', 'MARKET', { quantity: quantity }).then(res => { | ||
console.log(symbol, `市价,平多,卖出成功=>数量:${quantity} | 价格:${flagPrice}`) | ||
resolve(res); | ||
}).catch(err => { | ||
console.log(symbol, `市价,平多,卖出异常=>数量:${quantity} | 价格:${flagPrice}`, err) | ||
reject(err) | ||
}); | ||
} else { | ||
cf.newOrder(symbol, 'SELL', 'LONG', 'LIMIT', { quantity: quantity, price: price, timeInForce: 'GTC' }).then(res => { | ||
console.log(symbol, `限价,平多,卖出成功=>数量:${quantity} | 价格:${price}`) | ||
resolve(res); | ||
}).catch(err => { | ||
console.log(symbol, `限价,平多,卖出异常=>数量:${quantity} | 价格:${price}`, err) | ||
reject(err) | ||
}); | ||
} | ||
}); | ||
} | ||
/** | ||
* 合约卖出开空 | ||
* @param {*} cf | ||
* @param {*} symbol | ||
* @param {*} quantity | ||
* @param {*} price | ||
* @param {*} flagPrice | ||
* @returns | ||
*/ | ||
const sell = (cf, symbol, quantity, price = -1, flagPrice = 0) => { | ||
return new Promise((resolve, reject) => { | ||
if (price < 0) { | ||
cf.newOrder(symbol, 'SELL', 'SHORT', 'MARKET', { quantity: quantity }).then(res => { | ||
console.log(symbol, `市价,开空,卖出成功=>数量:${quantity} | 价格:${flagPrice}`) | ||
resolve(res); | ||
}).catch(err => { | ||
console.log(symbol, `市价,开空,卖出异常=>数量:${quantity} | 价格:${flagPrice}`, err) | ||
reject(err) | ||
}); | ||
} else { | ||
cf.newOrder(symbol, 'SELL', 'SHORT', 'LIMIT', { quantity: quantity, price: price, timeInForce: 'GTC' }).then(res => { | ||
console.log(symbol, `限价,开空,卖出成功=>数量:${quantity} | 价格:${price}`) | ||
resolve(res); | ||
}).catch(err => { | ||
console.log(symbol, `限价,开空,卖出异常=>数量:${quantity} | 价格:${price}`, err) | ||
reject(err) | ||
}); | ||
} | ||
}); | ||
} | ||
/** | ||
* 合约 空单 买入平空 | ||
* @param {*} cf | ||
* @param {*} symbol | ||
* @param {*} quantity | ||
* @param {*} price | ||
* @param {*} flagPrice | ||
* @returns | ||
*/ | ||
const sell_close = (cf, symbol, quantity, price = -1, flagPrice = 0) => { | ||
return new Promise((resolve, reject) => { | ||
if (price < 0) { | ||
cf.newOrder(symbol, 'BUY', 'SHORT', 'MARKET', { quantity: quantity }).then(res => { | ||
console.log(symbol, `市价,平空,买入成功=>数量:${quantity} | 价格:${flagPrice}`) | ||
resolve(res); | ||
}).catch(err => { | ||
console.log(symbol, `市价,平空,买入异常=>数量:${quantity} | 价格:${flagPrice}`, err) | ||
reject(err) | ||
}); | ||
} else { | ||
cf.newOrder(symbol, 'BUY', 'SHORT', 'LIMIT', { quantity: quantity, price: price, timeInForce: 'GTC' }).then(res => { | ||
console.log(symbol, `限价,平空,买入成功=>数量:${quantity} | 价格:${price}`) | ||
resolve(res); | ||
}).catch(err => { | ||
console.log(symbol, `限价,平空,买入异常=>数量:${quantity} | 价格:${price}`, err) | ||
reject(err) | ||
}); | ||
} | ||
}); | ||
} | ||
module.exports = { | ||
buy, | ||
buy_close, | ||
sell, | ||
sell_close | ||
} |
253144
7177
261