Files

62 lines
1.4 KiB
Markdown
Raw Permalink Normal View History

2021-12-07 00:45:45 +08:00
2023-07-14 18:39:48 +08:00
> Name
2021-12-07 00:45:45 +08:00
永续合约一键市价平仓
2023-07-14 18:39:48 +08:00
> Author
2021-12-07 00:45:45 +08:00
GCC
2023-07-14 18:39:48 +08:00
> Strategy Description
2021-12-07 00:45:45 +08:00
一键平所有永续合约仓位
2023-07-14 18:39:48 +08:00
> Source (javascript)
2021-12-07 00:45:45 +08:00
``` javascript
function main(){
exchange.SetContractType('swap')
2022-03-09 16:09:19 +08:00
exchange.SetCurrency('BNB_USDT')
2021-12-07 00:45:45 +08:00
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
2022-05-20 14:42:13 +08:00
var symbol = pos[i].symbol.replace('USDT','_USDT')
//var symbol = pos[i].symbol.replace('BUSD','_BUSD')
2021-12-07 00:45:45 +08:00
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 ('完成平仓')
}
}
```
2023-07-14 18:39:48 +08:00
> Detail
2021-12-07 00:45:45 +08:00
https://www.fmz.com/strategy/322449
2023-07-14 18:39:48 +08:00
> Last Modified
2021-12-07 00:45:45 +08:00
2022-05-20 14:42:13 +08:00
2022-03-25 10:48:05