POST
Close Position
Account API v2Close an open position fully or partially by ticket, or close all positions on a symbol.
POST
https://api.algodeltafx.com/api/v2/forexaccount/squareoffpositionSquare off open MetaTrader 5 positions. Close one position by ticket (optionally only part of its volume), or close every position on a symbol, optionally only the BUY or SELL side.
Authentication
Send the account token as Authorization: Bearer <ACCOUNT_TOKEN>. See Authentication.
Request body
JSON body, Content-Type: application/json.
- ticketinteger
Ticket of the position to close.
- volumenumber
Lots to close for a partial close. Used with
ticket. Omit to close the full position. - symbolstring
Close positions on this symbol. Use instead of
ticket. - sidestring · BUY | SELL
Only close
BUYorSELLpositions onsymbol. Omit to close both sides.
Response
Returns the standard response envelope: status, msg and data.
Notes
- Send either
ticket(with optionalvolume), orsymbol(with optionalside).
Related endpoints
- Get Open Positions: List every open position on the MT5 account.
- Place Order: Open a market order or place a pending order (limit, stop, stop-limit) on an MT5 account.
- Cancel Order: Cancel a pending order by ticket, or all pending orders for a symbol and side.
Example request
curl -X POST https://api.algodeltafx.com/api/v2/forexaccount/squareoffposition \
-H "Authorization: Bearer $ACCOUNT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"symbol": "EURUSD"
}'import os
import requests
res = requests.post(
"https://api.algodeltafx.com/api/v2/forexaccount/squareoffposition",
headers={"Authorization": f"Bearer {os.environ['ACCOUNT_TOKEN']}"},
json={
"symbol": "EURUSD"
},
timeout=30,
)
data = res.json()
print(data["status"], data.get("msg"), data.get("data"))const res = await fetch("https://api.algodeltafx.com/api/v2/forexaccount/squareoffposition", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.ACCOUNT_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"symbol": "EURUSD"
}),
});
const { status, msg, data } = await res.json();
console.log(status, msg, data);using System.Net.Http.Headers;
using System.Text;
using var http = new HttpClient();
http.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("ACCOUNT_TOKEN"));
var body = new StringContent("""
{
"symbol": "EURUSD"
}
""", Encoding.UTF8, "application/json");
var res = await http.PostAsync("https://api.algodeltafx.com/api/v2/forexaccount/squareoffposition", body);
Console.WriteLine(await res.Content.ReadAsStringAsync());Partial close by ticket
curl -X POST https://api.algodeltafx.com/api/v2/forexaccount/squareoffposition \
-H "Authorization: Bearer $ACCOUNT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"ticket": 1093765759,
"volume": 0.25
}'import os
import requests
res = requests.post(
"https://api.algodeltafx.com/api/v2/forexaccount/squareoffposition",
headers={"Authorization": f"Bearer {os.environ['ACCOUNT_TOKEN']}"},
json={
"ticket": 1093765759,
"volume": 0.25
},
timeout=30,
)
data = res.json()
print(data["status"], data.get("msg"), data.get("data"))const res = await fetch("https://api.algodeltafx.com/api/v2/forexaccount/squareoffposition", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.ACCOUNT_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"ticket": 1093765759,
"volume": 0.25
}),
});
const { status, msg, data } = await res.json();
console.log(status, msg, data);using System.Net.Http.Headers;
using System.Text;
using var http = new HttpClient();
http.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("ACCOUNT_TOKEN"));
var body = new StringContent("""
{
"ticket": 1093765759,
"volume": 0.25
}
""", Encoding.UTF8, "application/json");
var res = await http.PostAsync("https://api.algodeltafx.com/api/v2/forexaccount/squareoffposition", body);
Console.WriteLine(await res.Content.ReadAsStringAsync());Close all SELL positions on a symbol
curl -X POST https://api.algodeltafx.com/api/v2/forexaccount/squareoffposition \
-H "Authorization: Bearer $ACCOUNT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"symbol": "EURUSD",
"side": "SELL"
}'import os
import requests
res = requests.post(
"https://api.algodeltafx.com/api/v2/forexaccount/squareoffposition",
headers={"Authorization": f"Bearer {os.environ['ACCOUNT_TOKEN']}"},
json={
"symbol": "EURUSD",
"side": "SELL"
},
timeout=30,
)
data = res.json()
print(data["status"], data.get("msg"), data.get("data"))const res = await fetch("https://api.algodeltafx.com/api/v2/forexaccount/squareoffposition", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.ACCOUNT_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"symbol": "EURUSD",
"side": "SELL"
}),
});
const { status, msg, data } = await res.json();
console.log(status, msg, data);using System.Net.Http.Headers;
using System.Text;
using var http = new HttpClient();
http.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("ACCOUNT_TOKEN"));
var body = new StringContent("""
{
"symbol": "EURUSD",
"side": "SELL"
}
""", Encoding.UTF8, "application/json");
var res = await http.PostAsync("https://api.algodeltafx.com/api/v2/forexaccount/squareoffposition", body);
Console.WriteLine(await res.Content.ReadAsStringAsync());Last updated 2026-11-04