0

Let's say I opened long positions by using:

await binance.futuresMarketBuy('BTCUSDT', 1);
await binance.futuresMarketBuy('BNBUSDT', 1);

And then I try to close my positions by using:

await binance.futuresMarketSell('BTCUSDT', 1);
await binance.futuresMarketSell('BTCUSDT', 1);

If everything went correctly, then it should be able to close both the positions. But, things didn't work correctly due to some unknown error. It opened a long position but it didn't close the position because of that error.

I want to force close all the opened positions at a specific time like 00:00:00 and I make a script closePositions.js for that and use it like:

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;
    }
  }
})();

What should I put inside that function to make it happen?

Psi
  • 70
  • 9

0 Answers0