curl --request POST \
--url https://api.polymarket.us/v1/order/close-position \
--header 'Content-Type: application/json' \
--header 'X-PM-Access-Key: <api-key>' \
--header 'X-PM-Signature: <api-key>' \
--header 'X-PM-Timestamp: <api-key>' \
--data '
{
"marketSlug": "<string>",
"synchronousExecution": true,
"maxBlockTime": "<string>",
"slippageTolerance": {
"bips": 123,
"ticks": 123
}
}
'import requests
url = "https://api.polymarket.us/v1/order/close-position"
payload = {
"marketSlug": "<string>",
"synchronousExecution": True,
"maxBlockTime": "<string>",
"slippageTolerance": {
"bips": 123,
"ticks": 123
}
}
headers = {
"X-PM-Access-Key": "<api-key>",
"X-PM-Timestamp": "<api-key>",
"X-PM-Signature": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'X-PM-Access-Key': '<api-key>',
'X-PM-Timestamp': '<api-key>',
'X-PM-Signature': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
marketSlug: '<string>',
synchronousExecution: true,
maxBlockTime: '<string>',
slippageTolerance: {bips: 123, ticks: 123}
})
};
fetch('https://api.polymarket.us/v1/order/close-position', 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://api.polymarket.us/v1/order/close-position",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'marketSlug' => '<string>',
'synchronousExecution' => true,
'maxBlockTime' => '<string>',
'slippageTolerance' => [
'bips' => 123,
'ticks' => 123
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-PM-Access-Key: <api-key>",
"X-PM-Signature: <api-key>",
"X-PM-Timestamp: <api-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"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.polymarket.us/v1/order/close-position"
payload := strings.NewReader("{\n \"marketSlug\": \"<string>\",\n \"synchronousExecution\": true,\n \"maxBlockTime\": \"<string>\",\n \"slippageTolerance\": {\n \"bips\": 123,\n \"ticks\": 123\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-PM-Access-Key", "<api-key>")
req.Header.Add("X-PM-Timestamp", "<api-key>")
req.Header.Add("X-PM-Signature", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.polymarket.us/v1/order/close-position")
.header("X-PM-Access-Key", "<api-key>")
.header("X-PM-Timestamp", "<api-key>")
.header("X-PM-Signature", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"marketSlug\": \"<string>\",\n \"synchronousExecution\": true,\n \"maxBlockTime\": \"<string>\",\n \"slippageTolerance\": {\n \"bips\": 123,\n \"ticks\": 123\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.polymarket.us/v1/order/close-position")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-PM-Access-Key"] = '<api-key>'
request["X-PM-Timestamp"] = '<api-key>'
request["X-PM-Signature"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"marketSlug\": \"<string>\",\n \"synchronousExecution\": true,\n \"maxBlockTime\": \"<string>\",\n \"slippageTolerance\": {\n \"bips\": 123,\n \"ticks\": 123\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"executions": [
{
"id": "<string>",
"order": {
"id": "<string>",
"marketSlug": "<string>",
"price": {
"value": "0.55",
"currency": "USD"
},
"quantity": 123,
"cumQuantity": 123,
"leavesQuantity": 123,
"goodTillTime": "2023-11-07T05:31:56Z",
"marketMetadata": {
"slug": "<string>",
"icon": "<string>",
"title": "<string>",
"outcome": "<string>",
"eventSlug": "<string>",
"teamId": 123,
"team": {
"id": 123,
"name": "<string>",
"abbreviation": "<string>",
"league": "<string>",
"record": "<string>",
"logo": "<string>",
"alias": "<string>",
"safeName": "<string>",
"homeIcon": "<string>",
"awayIcon": "<string>",
"colorPrimary": "<string>",
"ordering": "<string>",
"ranking": "<string>",
"conference": "<string>"
}
},
"commissionNotionalTotalCollected": {
"value": "0.55",
"currency": "USD"
},
"commissionsBasisPoints": "<string>",
"makerCommissionsBasisPoints": "<string>",
"avgPx": {
"value": "0.55",
"currency": "USD"
},
"cashOrderQty": {
"value": "0.55",
"currency": "USD"
},
"insertTime": "2023-11-07T05:31:56Z",
"createTime": "2023-11-07T05:31:56Z"
},
"lastShares": "<string>",
"lastPx": {
"value": "0.55",
"currency": "USD"
},
"text": "<string>",
"transactTime": "2023-11-07T05:31:56Z",
"legPrices": [
{
"marketSlug": "<string>",
"anchor": true,
"px": {
"value": "0.55",
"currency": "USD"
},
"qty": "<string>",
"referencePx": "<string>"
}
],
"tradeId": "<string>",
"aggressor": true,
"commissionNotionalCollected": {
"value": "0.55",
"currency": "USD"
},
"traceId": "<string>",
"commissionSpreadPx": {
"value": "0.55",
"currency": "USD"
},
"transactTradeDate": "2023-11-07T05:31:56Z"
}
]
}Close Position Order
Create an order to close an existing position in a market. This will sell all contracts held in the specified market.
curl --request POST \
--url https://api.polymarket.us/v1/order/close-position \
--header 'Content-Type: application/json' \
--header 'X-PM-Access-Key: <api-key>' \
--header 'X-PM-Signature: <api-key>' \
--header 'X-PM-Timestamp: <api-key>' \
--data '
{
"marketSlug": "<string>",
"synchronousExecution": true,
"maxBlockTime": "<string>",
"slippageTolerance": {
"bips": 123,
"ticks": 123
}
}
'import requests
url = "https://api.polymarket.us/v1/order/close-position"
payload = {
"marketSlug": "<string>",
"synchronousExecution": True,
"maxBlockTime": "<string>",
"slippageTolerance": {
"bips": 123,
"ticks": 123
}
}
headers = {
"X-PM-Access-Key": "<api-key>",
"X-PM-Timestamp": "<api-key>",
"X-PM-Signature": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'X-PM-Access-Key': '<api-key>',
'X-PM-Timestamp': '<api-key>',
'X-PM-Signature': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
marketSlug: '<string>',
synchronousExecution: true,
maxBlockTime: '<string>',
slippageTolerance: {bips: 123, ticks: 123}
})
};
fetch('https://api.polymarket.us/v1/order/close-position', 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://api.polymarket.us/v1/order/close-position",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'marketSlug' => '<string>',
'synchronousExecution' => true,
'maxBlockTime' => '<string>',
'slippageTolerance' => [
'bips' => 123,
'ticks' => 123
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-PM-Access-Key: <api-key>",
"X-PM-Signature: <api-key>",
"X-PM-Timestamp: <api-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"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.polymarket.us/v1/order/close-position"
payload := strings.NewReader("{\n \"marketSlug\": \"<string>\",\n \"synchronousExecution\": true,\n \"maxBlockTime\": \"<string>\",\n \"slippageTolerance\": {\n \"bips\": 123,\n \"ticks\": 123\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-PM-Access-Key", "<api-key>")
req.Header.Add("X-PM-Timestamp", "<api-key>")
req.Header.Add("X-PM-Signature", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.polymarket.us/v1/order/close-position")
.header("X-PM-Access-Key", "<api-key>")
.header("X-PM-Timestamp", "<api-key>")
.header("X-PM-Signature", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"marketSlug\": \"<string>\",\n \"synchronousExecution\": true,\n \"maxBlockTime\": \"<string>\",\n \"slippageTolerance\": {\n \"bips\": 123,\n \"ticks\": 123\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.polymarket.us/v1/order/close-position")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-PM-Access-Key"] = '<api-key>'
request["X-PM-Timestamp"] = '<api-key>'
request["X-PM-Signature"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"marketSlug\": \"<string>\",\n \"synchronousExecution\": true,\n \"maxBlockTime\": \"<string>\",\n \"slippageTolerance\": {\n \"bips\": 123,\n \"ticks\": 123\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"executions": [
{
"id": "<string>",
"order": {
"id": "<string>",
"marketSlug": "<string>",
"price": {
"value": "0.55",
"currency": "USD"
},
"quantity": 123,
"cumQuantity": 123,
"leavesQuantity": 123,
"goodTillTime": "2023-11-07T05:31:56Z",
"marketMetadata": {
"slug": "<string>",
"icon": "<string>",
"title": "<string>",
"outcome": "<string>",
"eventSlug": "<string>",
"teamId": 123,
"team": {
"id": 123,
"name": "<string>",
"abbreviation": "<string>",
"league": "<string>",
"record": "<string>",
"logo": "<string>",
"alias": "<string>",
"safeName": "<string>",
"homeIcon": "<string>",
"awayIcon": "<string>",
"colorPrimary": "<string>",
"ordering": "<string>",
"ranking": "<string>",
"conference": "<string>"
}
},
"commissionNotionalTotalCollected": {
"value": "0.55",
"currency": "USD"
},
"commissionsBasisPoints": "<string>",
"makerCommissionsBasisPoints": "<string>",
"avgPx": {
"value": "0.55",
"currency": "USD"
},
"cashOrderQty": {
"value": "0.55",
"currency": "USD"
},
"insertTime": "2023-11-07T05:31:56Z",
"createTime": "2023-11-07T05:31:56Z"
},
"lastShares": "<string>",
"lastPx": {
"value": "0.55",
"currency": "USD"
},
"text": "<string>",
"transactTime": "2023-11-07T05:31:56Z",
"legPrices": [
{
"marketSlug": "<string>",
"anchor": true,
"px": {
"value": "0.55",
"currency": "USD"
},
"qty": "<string>",
"referencePx": "<string>"
}
],
"tradeId": "<string>",
"aggressor": true,
"commissionNotionalCollected": {
"value": "0.55",
"currency": "USD"
},
"traceId": "<string>",
"commissionSpreadPx": {
"value": "0.55",
"currency": "USD"
},
"transactTradeDate": "2023-11-07T05:31:56Z"
}
]
}Authorizations
Your API key ID (UUID). Generate at polymarket.us/developer.
Unix timestamp in milliseconds. Must be within 30 seconds of server time.
Base64-encoded Ed25519 signature of timestamp + method + path. See Authentication for details.
Body
Request to create an order to close a position
Request to create an order to close a position
Market slug of the position to close
Indicates whether the order was placed manually or automatically
MANUAL_ORDER_INDICATOR_MANUAL, MANUAL_ORDER_INDICATOR_AUTOMATIC If true, will block until the order is filled, rejected, canceled, or expired, up to maxBlockTime seconds
Maximum block time in seconds if synchronous execution is requested
Slippage tolerance configuration for the close order
Show child attributes
Show child attributes