1つのボタンがすべての永続契約のポジションを平衡します.
function main(){ exchange.SetContractType('swap') exchange.SetCurrency('BNB_USDT') Log(exchange.GetPosition()) acc = exchange.GetAccount() //Log(exchange.GetAccount().Info) var pos = exchange.GetAccount().Info.positions var positioned = false for(var i=0;i<pos.length;i++){ if (pos[i].positionAmt != 0){ positioned = true var symbol = pos[i].symbol.replace('USDT','_USDT') //var symbol = pos[i].symbol.replace('BUSD','_BUSD') exchange.SetCurrency(symbol) var amount = parseFloat(pos[i].positionAmt.replace('-','')) if(pos[i].positionSide == 'LONG'){ exchange.SetDirection('closebuy') exchange.Sell(-1, amount) } if(pos[i].positionSide == 'SHORT'){ exchange.SetDirection('closesell') exchange.Buy(-1, amount) } } } if(positioned == false){ Log('无持仓') return ('无持仓') } else{ Log('完成平仓') return ('完成平仓') } }
チャオチャンサポート,より完璧にしたい,例えば精度を考慮して,例えば最大取引量を超えた取引量を平らにする,例えば最小取引量以下を平らにする.