为什么我会遇到“保证金不足”的错误。在安装Binance API期货订单上?

发布于 2025-01-23 20:49:29 字数 2212 浏览 2 评论 0原文

import { createRequire, runMain } from "module";
const require = createRequire(import.meta.url);

const Binance = require("node-binance-api");
const binance = new Binance().options({
  APIKEY: "<API-KEY>",
  APISECRET: "<API-SECRET>",
  useServerTime: true,
});

async function Trade(interval, { symbol, EnterAt, Type }) {
  try {
    if ((interval == "1h" || interval == "4h") & (Type == "SHORT")) {
      let response = await binance.futuresBalance();
      let pair = response.filter((el) => el.asset == "USDT");

      const leverage = 6;
      let quantity = Math.round(
        ((parseFloat(pair[0].availableBalance) * leverage) / EnterAt).toFixed(2)
      );

      let takeProfit = EnterAt - (EnterAt * 0.6) / 100;
      let stopMarket = EnterAt + (EnterAt * 1.1) / 100;

      // Adjust leverage
      let adjustLeverage = await binance.futuresLeverage(symbol, leverage);

      // Futures Market Sell
      let short = await binance.futuresMarketSell(symbol, quantity);

      // Set TAKE PROFIT
      let TP = await binance.futuresOrder("BUY", symbol, quantity, false, {
        type: "TAKE_PROFIT_MARKET",
        stopPrice: takeProfit.toFixed(2),
        closePosition: true,
      });
      // Set STOP LOSS
      let SL = await binance.futuresOrder("BUY", symbol, quantity, false, {
        type: "STOP_MARKET",
        workingType: "MARK_PRICE",
        stopPrice: stopMarket.toFixed(2),
        closePosition: true,
      });
      console.log("SHORT: ", short);
      console.log("TP: ", TP);
      console.log("SL: ", SL);
    } 
  } catch (error) {
    console.log(error.message);
  }
}

function wrapUpTrade(interval, { symbol, EnterAt }) {
  binance.useServerTime(() =>
    Trade(interval, { symbol: symbol, EnterAt: EnterAt })
  );
}
// wrapUpTrade("1h", { symbol: "XRPUSDT", shortAt: 0.774 });
export { wrapUpTrade };

该代码仅用于期货市场卖出(卖出短)。为什么我在下订单上的订单中遇到的差额不足,而我的钱包里有2.9美元?在利用(6倍)时,我将拥有(6 * $ 2.9 = $ 17.4),大于$ 4.5,但我仍然会遇到错误的错误。功能交易需要一些论点:

Interval: "4h" or "1h"
symbol: "PAIR/(USDT)" // BTCUSDT, ETHUSDT
EnterAt: It is used to calculate Stoploss and TakeProfit. The type is int.
Type: "SHORT", means futuresSell
import { createRequire, runMain } from "module";
const require = createRequire(import.meta.url);

const Binance = require("node-binance-api");
const binance = new Binance().options({
  APIKEY: "<API-KEY>",
  APISECRET: "<API-SECRET>",
  useServerTime: true,
});

async function Trade(interval, { symbol, EnterAt, Type }) {
  try {
    if ((interval == "1h" || interval == "4h") & (Type == "SHORT")) {
      let response = await binance.futuresBalance();
      let pair = response.filter((el) => el.asset == "USDT");

      const leverage = 6;
      let quantity = Math.round(
        ((parseFloat(pair[0].availableBalance) * leverage) / EnterAt).toFixed(2)
      );

      let takeProfit = EnterAt - (EnterAt * 0.6) / 100;
      let stopMarket = EnterAt + (EnterAt * 1.1) / 100;

      // Adjust leverage
      let adjustLeverage = await binance.futuresLeverage(symbol, leverage);

      // Futures Market Sell
      let short = await binance.futuresMarketSell(symbol, quantity);

      // Set TAKE PROFIT
      let TP = await binance.futuresOrder("BUY", symbol, quantity, false, {
        type: "TAKE_PROFIT_MARKET",
        stopPrice: takeProfit.toFixed(2),
        closePosition: true,
      });
      // Set STOP LOSS
      let SL = await binance.futuresOrder("BUY", symbol, quantity, false, {
        type: "STOP_MARKET",
        workingType: "MARK_PRICE",
        stopPrice: stopMarket.toFixed(2),
        closePosition: true,
      });
      console.log("SHORT: ", short);
      console.log("TP: ", TP);
      console.log("SL: ", SL);
    } 
  } catch (error) {
    console.log(error.message);
  }
}

function wrapUpTrade(interval, { symbol, EnterAt }) {
  binance.useServerTime(() =>
    Trade(interval, { symbol: symbol, EnterAt: EnterAt })
  );
}
// wrapUpTrade("1h", { symbol: "XRPUSDT", shortAt: 0.774 });
export { wrapUpTrade };

This code is only for futures Market Sell (sell short). Why do I get an error of Insufficient Margin on placing an order of coin having a price of $4.5 and I have $2.9 in my wallet? On leveraging(6x) I will be having (6 * $2.9 = $17.4) that is greater than $4.5 still I get the error of Insufficient error. Function Trade takes some arguments:

Interval: "4h" or "1h"
symbol: "PAIR/(USDT)" // BTCUSDT, ETHUSDT
EnterAt: It is used to calculate Stoploss and TakeProfit. The type is int.
Type: "SHORT", means futuresSell

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文