为什么我会遇到“保证金不足”的错误。在安装Binance API期货订单上?
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论