Close all open positions
curl --request POST \
--url https://developers.fundingperpetuals.com/v1/accounts/{account_id}/close-all-positions \
--header 'Authorization: Bearer <token>' \
--header 'Idempotency-Key: <idempotency-key>'import requests
url = "https://developers.fundingperpetuals.com/v1/accounts/{account_id}/close-all-positions"
headers = {
"Idempotency-Key": "<idempotency-key>",
"Authorization": "Bearer <token>"
}
response = requests.post(url, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Idempotency-Key': '<idempotency-key>', Authorization: 'Bearer <token>'}
};
fetch('https://developers.fundingperpetuals.com/v1/accounts/{account_id}/close-all-positions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://developers.fundingperpetuals.com/v1/accounts/{account_id}/close-all-positions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Idempotency-Key: <idempotency-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://developers.fundingperpetuals.com/v1/accounts/{account_id}/close-all-positions"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://developers.fundingperpetuals.com/v1/accounts/{account_id}/close-all-positions")
.header("Idempotency-Key", "<idempotency-key>")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://developers.fundingperpetuals.com/v1/accounts/{account_id}/close-all-positions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"data": {
"id": "<string>",
"operation": "close_all_positions",
"account_id": "<string>",
"status": "running",
"total_count": 50,
"succeeded_count": 50,
"failed_count": 50,
"results": [
{
"position_id": "<string>",
"status": "submitted",
"order": {
"id": "<string>",
"account_id": "<string>",
"market_id": "<string>",
"provider": "<string>",
"symbol": "<string>",
"coin": "<string>",
"type": "market",
"mode": "market",
"side": "buy",
"size": 123,
"expected_price": 123,
"leverage": 123,
"margin_mode": "cross",
"reduce_only": true,
"status": "pending",
"requested_at": 123,
"initial_size": 123,
"filled_size": 123,
"fill_price": 123,
"trigger_price": 123,
"limit_price": 123,
"notional": 123,
"fee": 123,
"realized_pnl": 123,
"time_in_force": "gtc",
"gtd_expires_at": 123,
"attached_take_profit_price": 123,
"attached_stop_loss_price": 123,
"chase_offset": 123,
"chase_cap_price": 123,
"trigger_market_id": "<string>",
"trigger_direction": "above",
"target_position_id": "<string>",
"liquidity_role": "maker",
"partial_of_order_id": "<string>",
"partial_fill_root_order_id": "<string>",
"twap_order_id": "<string>",
"scaled_order_id": "<string>",
"reject_reason": "<string>",
"reject_rule_id": "<string>",
"settled_at": 123,
"canceled_at": 123
},
"failure_code": "<string>",
"rule_id": "<string>"
}
],
"created_at": 123,
"completed_at": 123
}
}{
"data": {
"id": "<string>",
"operation": "close_all_positions",
"account_id": "<string>",
"status": "running",
"total_count": 50,
"succeeded_count": 50,
"failed_count": 50,
"results": [
{
"position_id": "<string>",
"status": "submitted",
"order": {
"id": "<string>",
"account_id": "<string>",
"market_id": "<string>",
"provider": "<string>",
"symbol": "<string>",
"coin": "<string>",
"type": "market",
"mode": "market",
"side": "buy",
"size": 123,
"expected_price": 123,
"leverage": 123,
"margin_mode": "cross",
"reduce_only": true,
"status": "pending",
"requested_at": 123,
"initial_size": 123,
"filled_size": 123,
"fill_price": 123,
"trigger_price": 123,
"limit_price": 123,
"notional": 123,
"fee": 123,
"realized_pnl": 123,
"time_in_force": "gtc",
"gtd_expires_at": 123,
"attached_take_profit_price": 123,
"attached_stop_loss_price": 123,
"chase_offset": 123,
"chase_cap_price": 123,
"trigger_market_id": "<string>",
"trigger_direction": "above",
"target_position_id": "<string>",
"liquidity_role": "maker",
"partial_of_order_id": "<string>",
"partial_fill_root_order_id": "<string>",
"twap_order_id": "<string>",
"scaled_order_id": "<string>",
"reject_reason": "<string>",
"reject_rule_id": "<string>",
"settled_at": 123,
"canceled_at": 123
},
"failure_code": "<string>",
"rule_id": "<string>"
}
],
"created_at": 123,
"completed_at": 123
}
}{
"data": {
"id": "<string>",
"operation": "close_all_positions",
"account_id": "<string>",
"status": "running",
"total_count": 50,
"succeeded_count": 50,
"failed_count": 50,
"results": [
{
"position_id": "<string>",
"status": "submitted",
"order": {
"id": "<string>",
"account_id": "<string>",
"market_id": "<string>",
"provider": "<string>",
"symbol": "<string>",
"coin": "<string>",
"type": "market",
"mode": "market",
"side": "buy",
"size": 123,
"expected_price": 123,
"leverage": 123,
"margin_mode": "cross",
"reduce_only": true,
"status": "pending",
"requested_at": 123,
"initial_size": 123,
"filled_size": 123,
"fill_price": 123,
"trigger_price": 123,
"limit_price": 123,
"notional": 123,
"fee": 123,
"realized_pnl": 123,
"time_in_force": "gtc",
"gtd_expires_at": 123,
"attached_take_profit_price": 123,
"attached_stop_loss_price": 123,
"chase_offset": 123,
"chase_cap_price": 123,
"trigger_market_id": "<string>",
"trigger_direction": "above",
"target_position_id": "<string>",
"liquidity_role": "maker",
"partial_of_order_id": "<string>",
"partial_fill_root_order_id": "<string>",
"twap_order_id": "<string>",
"scaled_order_id": "<string>",
"reject_reason": "<string>",
"reject_rule_id": "<string>",
"settled_at": 123,
"canceled_at": 123
},
"failure_code": "<string>",
"rule_id": "<string>"
}
],
"created_at": 123,
"completed_at": 123
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}Accounts
Close all open positions
Takes one bounded snapshot of every open position and submits one reduce-only market close for each target. Closes use the same 2.5% maximum-slippage policy as Close All in the trading terminal. The response reports each submitted or rejected child order. Repeating the request with the same idempotency key resumes or replays the original snapshot, even when positions have since closed.
POST
/
v1
/
accounts
/
{account_id}
/
close-all-positions
Close all open positions
curl --request POST \
--url https://developers.fundingperpetuals.com/v1/accounts/{account_id}/close-all-positions \
--header 'Authorization: Bearer <token>' \
--header 'Idempotency-Key: <idempotency-key>'import requests
url = "https://developers.fundingperpetuals.com/v1/accounts/{account_id}/close-all-positions"
headers = {
"Idempotency-Key": "<idempotency-key>",
"Authorization": "Bearer <token>"
}
response = requests.post(url, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Idempotency-Key': '<idempotency-key>', Authorization: 'Bearer <token>'}
};
fetch('https://developers.fundingperpetuals.com/v1/accounts/{account_id}/close-all-positions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://developers.fundingperpetuals.com/v1/accounts/{account_id}/close-all-positions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Idempotency-Key: <idempotency-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://developers.fundingperpetuals.com/v1/accounts/{account_id}/close-all-positions"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://developers.fundingperpetuals.com/v1/accounts/{account_id}/close-all-positions")
.header("Idempotency-Key", "<idempotency-key>")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://developers.fundingperpetuals.com/v1/accounts/{account_id}/close-all-positions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"data": {
"id": "<string>",
"operation": "close_all_positions",
"account_id": "<string>",
"status": "running",
"total_count": 50,
"succeeded_count": 50,
"failed_count": 50,
"results": [
{
"position_id": "<string>",
"status": "submitted",
"order": {
"id": "<string>",
"account_id": "<string>",
"market_id": "<string>",
"provider": "<string>",
"symbol": "<string>",
"coin": "<string>",
"type": "market",
"mode": "market",
"side": "buy",
"size": 123,
"expected_price": 123,
"leverage": 123,
"margin_mode": "cross",
"reduce_only": true,
"status": "pending",
"requested_at": 123,
"initial_size": 123,
"filled_size": 123,
"fill_price": 123,
"trigger_price": 123,
"limit_price": 123,
"notional": 123,
"fee": 123,
"realized_pnl": 123,
"time_in_force": "gtc",
"gtd_expires_at": 123,
"attached_take_profit_price": 123,
"attached_stop_loss_price": 123,
"chase_offset": 123,
"chase_cap_price": 123,
"trigger_market_id": "<string>",
"trigger_direction": "above",
"target_position_id": "<string>",
"liquidity_role": "maker",
"partial_of_order_id": "<string>",
"partial_fill_root_order_id": "<string>",
"twap_order_id": "<string>",
"scaled_order_id": "<string>",
"reject_reason": "<string>",
"reject_rule_id": "<string>",
"settled_at": 123,
"canceled_at": 123
},
"failure_code": "<string>",
"rule_id": "<string>"
}
],
"created_at": 123,
"completed_at": 123
}
}{
"data": {
"id": "<string>",
"operation": "close_all_positions",
"account_id": "<string>",
"status": "running",
"total_count": 50,
"succeeded_count": 50,
"failed_count": 50,
"results": [
{
"position_id": "<string>",
"status": "submitted",
"order": {
"id": "<string>",
"account_id": "<string>",
"market_id": "<string>",
"provider": "<string>",
"symbol": "<string>",
"coin": "<string>",
"type": "market",
"mode": "market",
"side": "buy",
"size": 123,
"expected_price": 123,
"leverage": 123,
"margin_mode": "cross",
"reduce_only": true,
"status": "pending",
"requested_at": 123,
"initial_size": 123,
"filled_size": 123,
"fill_price": 123,
"trigger_price": 123,
"limit_price": 123,
"notional": 123,
"fee": 123,
"realized_pnl": 123,
"time_in_force": "gtc",
"gtd_expires_at": 123,
"attached_take_profit_price": 123,
"attached_stop_loss_price": 123,
"chase_offset": 123,
"chase_cap_price": 123,
"trigger_market_id": "<string>",
"trigger_direction": "above",
"target_position_id": "<string>",
"liquidity_role": "maker",
"partial_of_order_id": "<string>",
"partial_fill_root_order_id": "<string>",
"twap_order_id": "<string>",
"scaled_order_id": "<string>",
"reject_reason": "<string>",
"reject_rule_id": "<string>",
"settled_at": 123,
"canceled_at": 123
},
"failure_code": "<string>",
"rule_id": "<string>"
}
],
"created_at": 123,
"completed_at": 123
}
}{
"data": {
"id": "<string>",
"operation": "close_all_positions",
"account_id": "<string>",
"status": "running",
"total_count": 50,
"succeeded_count": 50,
"failed_count": 50,
"results": [
{
"position_id": "<string>",
"status": "submitted",
"order": {
"id": "<string>",
"account_id": "<string>",
"market_id": "<string>",
"provider": "<string>",
"symbol": "<string>",
"coin": "<string>",
"type": "market",
"mode": "market",
"side": "buy",
"size": 123,
"expected_price": 123,
"leverage": 123,
"margin_mode": "cross",
"reduce_only": true,
"status": "pending",
"requested_at": 123,
"initial_size": 123,
"filled_size": 123,
"fill_price": 123,
"trigger_price": 123,
"limit_price": 123,
"notional": 123,
"fee": 123,
"realized_pnl": 123,
"time_in_force": "gtc",
"gtd_expires_at": 123,
"attached_take_profit_price": 123,
"attached_stop_loss_price": 123,
"chase_offset": 123,
"chase_cap_price": 123,
"trigger_market_id": "<string>",
"trigger_direction": "above",
"target_position_id": "<string>",
"liquidity_role": "maker",
"partial_of_order_id": "<string>",
"partial_fill_root_order_id": "<string>",
"twap_order_id": "<string>",
"scaled_order_id": "<string>",
"reject_reason": "<string>",
"reject_rule_id": "<string>",
"settled_at": 123,
"canceled_at": 123
},
"failure_code": "<string>",
"rule_id": "<string>"
}
],
"created_at": 123,
"completed_at": 123
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}{
"error": {
"code": "<string>",
"message": "<string>",
"request_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
}Authorizations
API key beginning with fp_live_.
Headers
Unique printable key for this intended operation. Reuse it only for an identical retry.
Required string length:
1 - 128Path Parameters
Response
Completed operation replay.
Show child attributes
Show child attributes
⌘I