Cancel an Order

Cancel a single open order by {id}.
For all transactions related to the private endpoint, you must authorize before sending your request.
For more information you can check our Authentication V1 article.
You need to send request with [DELETE] method.
  • id parameter must be used for order cancellation.
  • Open orders can be canceled with https://api.btcturk.com/api/v1/order endpoint.

Request example:

  • https://api.btcturk.com/api/v1/order?id=123456789
delete
https://api.btcturk.com
/api/v1/order
Cancel Order

Code Example

C#
PHP
Python
GoLang
Node.js
Ruby
// You can download ApiClient .net core complete library from github https://github.com/BTCTrader/broker-api-csharp-v2
var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
var publicKey = configuration["publicKey"];
var privateKey = configuration["privateKey"];
var resourceUrl = configuration["resourceUrl"];
var apiClientV1 = new ApiClientV1(publicKey, privateKey, resourceUrl);
var orderId = 123456;
var cancelOrder = apiClientV1.CancelOrder(orderId);
if (cancelOrder.Result)
{
Console.WriteLine($"Successfully canceled order {orderId}");
}
else
{
Console.WriteLine("Could not cancel order");
}
<?php
$base = "https://api.btcturk.com";
$apiKey = "YOUR_API_PUBLIC_KEY";
$apiSecret = "YOUR_API_SECRET";
$method = "/api/v1/order?id=ORDER_ID";
$uri = $base.$method;
$nonce = time()*1000;
$message = $apiKey.$nonce;
$signatureBytes = hash_hmac("sha256", $message, base64_decode($apiSecret), true);
$signature = base64_encode($signatureBytes);
$headers = array(
"X-PCK: ".$apiKey,
"X-Stamp: ".$nonce,
"X-Signature: ".$signature,
"Cache-Control: no-cache",
"Content-Type: application/json");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_HTTP_VERSION, "CURL_HTTP_VERSION_1_2");
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
print_r(curl_error($ch));
}
$answer = json_decode($result);
print_r($answer);
import time, base64, hmac, hashlib, requests, json
base = "https://api.btcturk.com"
method = "/api/v1/order?id=ORDER_ID"
uri = base+method
apiKey = "YOUR_API_PUBLIC_KEY"
apiSecret = "YOUR_API_SECRET"
apiSecret = base64.b64decode(apiSecret)
stamp = str(int(time.time())*1000)
data = "{}{}".format(apiKey, stamp).encode("utf-8")
signature = hmac.new(apiSecret, data, hashlib.sha256).digest()
signature = base64.b64encode(signature)
headers = {"X-PCK": apiKey, "X-Stamp": stamp, "X-Signature": signature, "Content-Type" : "application/json"}
result = requests.delete(url=uri, headers=headers)
result = result.json()
print(json.dumps(result, indent=2))
publicKey := "PUBLIC_KEY_HERE"
privateKey := "PRIVATE_KEY_HERE"
key, error := base64.StdEncoding.DecodeString(privateKey)
if error != nil {
return error
}
nonce := fmt.Sprint(time.Now().UTC().UnixMilli())
message := publicKey + nonce
hmac := hmac.New(sha256.New, key)
hmac.Write([]byte(message))
signature := base64.StdEncoding.EncodeToString(hmac.Sum(nil))
request, _ := http.NewRequest("DELETE", uri, nil)
request.Header.Set("X-PCK", publicKey)
request.Header.Set("X-Stamp", nonce)
request.Header.Set("X-Signature", signature)
request.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(request)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
const API_KEY = "API_KEY_HERE"
const API_SECRET = "API_SECRET_HERE"
const base = 'https://api.btcturk.com'
const method = '/api/v1/order/ORDER_ID_HERE'
const uri = base+method;
const options = {
method: 'DELETE',
headers: authentication()
};
fetch(uri, options)
.then(res => console.log(res))
.then(json => console.log(json))
.catch(err => console.error('error:' + err));
function authentication() {
const stamp = (new Date()).getTime()
const data = Buffer.from(`${API_KEY}${stamp}`, 'utf8')
const buffer = crypto.createHmac('sha256', Buffer.from(API_SECRET, 'base64'))
buffer.update(data)
const digest = buffer.digest()
const signature = Buffer.from(digest.toString('base64'), 'utf8').toString('utf8')
return {
'Content-type': 'application/json',
"X-PCK": API_KEY,
"X-Stamp": stamp.toString(),
"X-Signature": signature,
}
}
public_key = 'PUBLIC_KEY_HERE'
private_key = 'PRIVATE_KEY_HERE'
uri = URI.parse('https://api-dev.btcturk.com/api/v1/order?{orderId}')
timestamp = Time.now.to_i*1000
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Delete.new(uri)
data = public_key + timestamp.to_s
private_key = Base64.decode64(private_key).strip
digest = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), private_key, data)
sign = Base64.encode64(digest).strip
request['Content-type'] = 'application/json'
request['X-PCK'] = public_key
request['X-Stamp'] = timestamp.to_s
request['X-Signature'] = sign
response = http.request(request)
puts response.read_body
Error Message
Description
NO_ORDER_MATCHES_YOUR_REQUEST
orderId not found. Check your orderId information.
ORDER_COULD_NOT_BE_CANCELED
Closed order cannot be cancelled. This error is received if the orderId belongs to the market order or order status is not partial or untouched or the operation fails.
ORDER_CANCEL_BLOCKED
Maintenance work is in progress for the trading pair. Visit our status page for more detailed information. https://status.btcturk.com/