// 从持仓列表中获取特定币种的持仓 function getPositionBySymbol(positions, symbol) { var index = -1; if (positions && positions.length > 0) { for (var i = 0; i < positions.length; i++) { if (positions[i][0].Symbol == symbol) { index = i; break; } } } return index == -1 ? null : positions[index]; } // 获取所有持仓列表 function getAllPositionInBinance() { var ret = exchange.IO("api", "GET", "/fapi/v2/account"); var positions = []; var i = 0; if (!ret || !ret.positions) { return null; } // 获取所有持仓 for (i = 0; i < ret.positions.length; i++) { if (ret.positions[i].positionAmt != 0 && ret.positions[i].symbol.endsWith("USDT")) { positions.push([{ Symbol: ret.positions[i].symbol.substring(0, ret.positions[i].symbol.lastIndexOf("USDT")) + "_USDT", Amount: Number(Math.abs(ret.positions[i].positionAmt)), FrozenAmount: 0, Price: Number(ret.positions[i].entryPrice), Profit: Number(ret.positions[i].unrealizedProfit), Type: ret.positions[i].positionAmt < 0 ? PD_SHORT : PD_LONG, ContractType: "swap", Margin: Number(ret.positions[i].positionInitialMargin), LevelRate: Number(ret.positions[i].leverage) }]); } } // 合并相同币种的持仓(同一币种,多空双向持仓) if (positions.length >= 2) { for (i = 0; i < positions.length; i++) { for (var j = i + 1; j < positions.length; j++) { if (positions[i][0].Symbol == positions[j][0].Symbol) { positions[i].push(JSON.parse(JSON.stringify(positions[j][0]))); positions.splice(j, 1); // 删除相同币种 break; } } } } return positions; }
eth8888ReferenceError:'main' is not defined
[Translated from Chinese]Thank you very much!
LJG658658How can you not see my comment?
LJG658658I don't understand, is this how much space you can see on the platform for all the open positions in this currency?
Light cloudsJust what I needed, congratulations!!!! thank you!!!!
Oh, my God.If you want to optimize, multi-space bidirectional storage.
Summer won't beat you.All holdings of the Binance U-Byte contract
Summer won't beat you.It's already a multi-space bidirectional holding.