cURL
curl --request GET \
--url https://drb.coinbase.com/api/v2/private/close_position \
--header 'Content-Type: application/json' \
--data '
{
"id": 6130,
"jsonrpc": "2.0",
"method": "private/close_position",
"params": {
"instrument_name": "ETH-PERPETUAL",
"price": 145.17,
"type": "limit"
}
}
'import requests
url = "https://drb.coinbase.com/api/v2/private/close_position"
payload = {
"id": 6130,
"jsonrpc": "2.0",
"method": "private/close_position",
"params": {
"instrument_name": "ETH-PERPETUAL",
"price": 145.17,
"type": "limit"
}
}
headers = {"Content-Type": "application/json"}
response = requests.get(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'GET',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
id: 6130,
jsonrpc: '2.0',
method: 'private/close_position',
params: {instrument_name: 'ETH-PERPETUAL', price: 145.17, type: 'limit'}
})
};
fetch('https://drb.coinbase.com/api/v2/private/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://drb.coinbase.com/api/v2/private/close_position",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => json_encode([
'id' => 6130,
'jsonrpc' => '2.0',
'method' => 'private/close_position',
'params' => [
'instrument_name' => 'ETH-PERPETUAL',
'price' => 145.17,
'type' => 'limit'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$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://drb.coinbase.com/api/v2/private/close_position"
payload := strings.NewReader("{\n \"id\": 6130,\n \"jsonrpc\": \"2.0\",\n \"method\": \"private/close_position\",\n \"params\": {\n \"instrument_name\": \"ETH-PERPETUAL\",\n \"price\": 145.17,\n \"type\": \"limit\"\n }\n}")
req, _ := http.NewRequest("GET", url, payload)
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.get("https://drb.coinbase.com/api/v2/private/close_position")
.header("Content-Type", "application/json")
.body("{\n \"id\": 6130,\n \"jsonrpc\": \"2.0\",\n \"method\": \"private/close_position\",\n \"params\": {\n \"instrument_name\": \"ETH-PERPETUAL\",\n \"price\": 145.17,\n \"type\": \"limit\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://drb.coinbase.com/api/v2/private/close_position")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": 6130,\n \"jsonrpc\": \"2.0\",\n \"method\": \"private/close_position\",\n \"params\": {\n \"instrument_name\": \"ETH-PERPETUAL\",\n \"price\": 145.17,\n \"type\": \"limit\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": 6130,
"jsonrpc": "2.0",
"result": {
"order": {
"amount": 21,
"api": true,
"average_price": 202.8,
"creation_timestamp": 1590486335742,
"direction": "sell",
"filled_amount": 21,
"instrument_name": "ETH-PERPETUAL",
"is_liquidation": false,
"is_rebalance": false,
"label": "",
"last_update_timestamp": 1590486335742,
"max_show": 21,
"order_id": "ETH-584864807",
"order_state": "filled",
"order_type": "limit",
"post_only": false,
"price": 198.75,
"reduce_only": true,
"replaced": false,
"time_in_force": "good_til_cancelled",
"web": false
},
"trades": [
{
"amount": 21,
"direction": "sell",
"fee": 0.00007766,
"fee_currency": "ETH",
"index_price": 202.86,
"instrument_name": "ETH-PERPETUAL",
"liquidity": "T",
"mark_price": 202.79,
"matching_id": null,
"order_id": "ETH-584864807",
"order_type": "limit",
"post_only": false,
"price": 202.8,
"reduce_only": true,
"state": "filled",
"tick_direction": 0,
"timestamp": 1590486335742,
"trade_id": "ETH-2696097",
"trade_seq": 1966068
}
]
}
}Trading
private/close_position
Places a reduce-only order to close an existing position. Reduce-only orders can only reduce or close a position; they cannot open a new position or increase an existing one.
You can specify whether to use a market or limit order. If using a limit order, provide the price. The order will automatically be set to reduce-only to ensure it only closes the position.
Scope: rat#trade or wallet:buys:create
GET
/
private
/
close_position
cURL
curl --request GET \
--url https://drb.coinbase.com/api/v2/private/close_position \
--header 'Content-Type: application/json' \
--data '
{
"id": 6130,
"jsonrpc": "2.0",
"method": "private/close_position",
"params": {
"instrument_name": "ETH-PERPETUAL",
"price": 145.17,
"type": "limit"
}
}
'import requests
url = "https://drb.coinbase.com/api/v2/private/close_position"
payload = {
"id": 6130,
"jsonrpc": "2.0",
"method": "private/close_position",
"params": {
"instrument_name": "ETH-PERPETUAL",
"price": 145.17,
"type": "limit"
}
}
headers = {"Content-Type": "application/json"}
response = requests.get(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'GET',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
id: 6130,
jsonrpc: '2.0',
method: 'private/close_position',
params: {instrument_name: 'ETH-PERPETUAL', price: 145.17, type: 'limit'}
})
};
fetch('https://drb.coinbase.com/api/v2/private/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://drb.coinbase.com/api/v2/private/close_position",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => json_encode([
'id' => 6130,
'jsonrpc' => '2.0',
'method' => 'private/close_position',
'params' => [
'instrument_name' => 'ETH-PERPETUAL',
'price' => 145.17,
'type' => 'limit'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$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://drb.coinbase.com/api/v2/private/close_position"
payload := strings.NewReader("{\n \"id\": 6130,\n \"jsonrpc\": \"2.0\",\n \"method\": \"private/close_position\",\n \"params\": {\n \"instrument_name\": \"ETH-PERPETUAL\",\n \"price\": 145.17,\n \"type\": \"limit\"\n }\n}")
req, _ := http.NewRequest("GET", url, payload)
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.get("https://drb.coinbase.com/api/v2/private/close_position")
.header("Content-Type", "application/json")
.body("{\n \"id\": 6130,\n \"jsonrpc\": \"2.0\",\n \"method\": \"private/close_position\",\n \"params\": {\n \"instrument_name\": \"ETH-PERPETUAL\",\n \"price\": 145.17,\n \"type\": \"limit\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://drb.coinbase.com/api/v2/private/close_position")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": 6130,\n \"jsonrpc\": \"2.0\",\n \"method\": \"private/close_position\",\n \"params\": {\n \"instrument_name\": \"ETH-PERPETUAL\",\n \"price\": 145.17,\n \"type\": \"limit\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": 6130,
"jsonrpc": "2.0",
"result": {
"order": {
"amount": 21,
"api": true,
"average_price": 202.8,
"creation_timestamp": 1590486335742,
"direction": "sell",
"filled_amount": 21,
"instrument_name": "ETH-PERPETUAL",
"is_liquidation": false,
"is_rebalance": false,
"label": "",
"last_update_timestamp": 1590486335742,
"max_show": 21,
"order_id": "ETH-584864807",
"order_state": "filled",
"order_type": "limit",
"post_only": false,
"price": 198.75,
"reduce_only": true,
"replaced": false,
"time_in_force": "good_til_cancelled",
"web": false
},
"trades": [
{
"amount": 21,
"direction": "sell",
"fee": 0.00007766,
"fee_currency": "ETH",
"index_price": 202.86,
"instrument_name": "ETH-PERPETUAL",
"liquidity": "T",
"mark_price": 202.79,
"matching_id": null,
"order_id": "ETH-584864807",
"order_type": "limit",
"post_only": false,
"price": 202.8,
"reduce_only": true,
"state": "filled",
"tick_direction": 0,
"timestamp": 1590486335742,
"trade_id": "ETH-2696097",
"trade_seq": 1966068
}
]
}
}Query Parameters
Instrument name Unique instrument identifier
Example:
"BTC-PERPETUAL"
The order type
Available options:
limit, market Optional price for limit order.
Was this page helpful?
⌘I