假设我使用以下方法开立多头头寸:
await binance.futuresMarketBuy('BTCUSDT', 1);
await binance.futuresMarketBuy('BNBUSDT', 1);
然后我尝试使用以下方法平仓:
await binance.futuresMarketSell('BTCUSDT', 1);
await binance.futuresMarketSell('BTCUSDT', 1);
如果一切顺利,那么它应该能够平掉两个头寸。但是,由于一些未知错误,事情没有正常工作。它开了一个多头头寸,但由于那个错误而没有平仓。
我想在特定时间(例如 00:00:00)强制关闭所有已开仓位,我为此编写了一个脚本 closePositions.js 并使用它:
const Binance = require('node-binance-api');
const binance = new Binance().options({
APIKEY: "someRandomKey",
APISECRET: "someRandomKey",
});
async function forceClosePositions {
//Close all the opened positions.
}
(async () => {
while (true) {
let time = new Date();
time =
time.getHours() +
":" +
time.getMinutes() +
":" +
time.getSeconds() +
":" +
time.getMilliseconds();
if (time == "0:0:0:0") {
await forceClosePositions();
break;
}
}
})();
我应该在该函数中放入什么来实现它?