Submit an Order

Create an order. You can place 4 types of orders: limit, market, stoplimit and stopmarket.
Orders can only be placed if your account has sufficient funds. Once an order is placed, your account funds will be put on hold for the duration of the order. How much and which funds are put on hold depends on the order type and parameters specified.
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 [POST] method.
  • quantity,price,stopPrice, newOrderClientId, orderMethod, orderType , pairSymbol parameters must be used for submit order.
  • price field will be ignored for market orders. Market orders get filled with different prices until your order is completely filled. There is a 5% limit on the difference between the first price and the last price. İ.e. you can't buy at a price more than 5% higher than the best sell at the time of order submission and you can't sell at a price less than 5% lower than the best buy at the time of order submission.
  • stopPrice parameter is valid only for stop orders.
  • You can use symbol parameter in this format: BTCUSDT
Decimal patterns must be used with dots (.)
  • 0.1876
  • 42.18
quantity for Market Buy Order
quantity for Market Sell Order
quantity for Limit Buy Order
quantity for Limit Sell Order
TRY, USDT or BTC
CRYPTO
CRYPTO
CRYPTO
post
https://api.btcturk.com
/api/v1/order
Submit 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 limitSellOrder = new OrderInput
{
Quantity = 0.001m,
Price = 40000m,
NewOrderClientId = "test",
OrderMethod = OrderMethod.Limit,
OrderType = OrderType.Sell,
PairSymbol = "BTCTRY"
};
////Create New Order
var orderOutput = apiClientV1.CreateOrder(limitSellOrder);
Console.WriteLine(!orderOutput.Result.Success
? $"Code:{orderOutput.Result.Code} , Message: {orderOutput.Result.Message}"
: orderOutput.Result.Data.ToString());
<?php
$base = "https://api.btcturk.com";
$apiKey = "YOUR_API_PUBLIC_KEY";
$apiSecret = "YOUR_API_SECRET";
$method = "/api/v1/order";
$uri = $base.$method;
$post_data = "{ 'quantity' : '0.12345678', 'price' : '50000', 'stopPrice' : 0, newOrderClientId: 'BtcTurk API PHPClient', 'orderMethod':'limit', 'orderType':'sell', 'pairSymbol':'BTCTRY' }";
$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_POSTFIELDS, $post_data);
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"
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"}
params={"quantity": 0.001,"price": 50000,"stopPrice": 0, "newOrderClientId":"BtcTurk Python API Test", "orderMethod":"limit", "orderType":"sell", "pairSymbol":"BTCTRY"}
result = requests.post(url=uri, headers=headers, json=params)
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))
payload := strings.NewReader("{\"quantity\":\"0.0002\",\"price\":\"500000\",\"newOrderClientId\":\"golang\",\"orderMethod\":\"limit\",\"orderType\":\"buy\",\"pairSymbol\":\"BTCTRY\"}")
request, _ := http.NewRequest("POST", uri, payload)
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'
const uri = base+method;
const options = {
method: 'POST',
headers: authentication(),
body: JSON.stringify({
quantity: '0.0001',
price: '500000',
newOrderClientId: 'nodejs-request-test',
orderMethod: 'limit',
orderType: 'buy',
pairSymbol: 'BTCTRY'
})
};
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')
timestamp = Time.now.to_i*1000
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.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
body = {"quantity": "1","price": "416200","newOrderClientId": "ruby-test","orderMethod": "limit","orderType": "buy","pairSymbol": "BTCTRY"}
request['Content-type'] = 'application/json'
request['X-PCK'] = public_key
request['X-Stamp'] = timestamp.to_s
request['X-Signature'] = sign
request.body = JSON.generate(body)
response = http.request(request)
puts response.read_body

Expected Errors

The expected errors when creating an order with the submit order endpoint are listed below. Review the meaning of the error you received.
FAILED_ORDER_PARAMETER
One of the giving parameters is not correct. For the accuracy of parameters, you can check our Submit an Order page.
BALANCE_NOT_ENOUGH
The balance amount is not enough for this operation. Check your balance amount using the /api/v1/users/balances endpoint.
FAILED_MIN_TOTAL_AMOUNT
The order quantity is less than the minimum required. You can view the minimum order amount from the /api/v2/server/exchangeinfo endpoint. You can avoid the FAILED_MIN_TOTAL_AMOUNT error with the minExchangeValue object.
STOP_PRICE_GREATER_THAN_MARKET
Stop buy price must be above current price. You can check the current price information from the /api/v2/ticker endpoint with the last object.
STOP_PRICE_LESS_THAN_MARKET
Stop sell price must be bellow current price. You can check the current price information from the /api/v2/ticker endpoint with the last object.
PRICE_MUST_BE_LESS_THAN_MAXPRICE
Buy or sell price must be less than max. You can view the maximum Price information from the /api/v2/server/exchangeinfo endpoint with the maximumLimitOrderPrice object.
FAILED_MIN_TOTAL_AMOUNT
Quantity*price must be greater than min amount. You can view the Min total amount information from the /api/v2/server/exchangeinfo endpoint with the minAmount object.
FAILED_ORDER_WITH_OPEN_ORDERS
Order submission failed due to open orders. Your free balance is not enough for this transaction. You can view your available balance with the free object from the /api/v1/users/balance endpoint. You may have an open order or a request to withdraw.
FAILED_MARKET_ORDER
Market order is not open for the pair. You can view the orderMethods values from the /api/v2/server/exchangeinfo endpoint.
ORDER_MIN_PRICE_EXCEEDED
Less than 1/10 of the current price has been set. You can view the current limits using the maximumLimitOrder Price and minimumLimitOrderPrice objects from the /api/v2/server/exchange info endpoint.
ORDER_MAX_PRICE_EXCEEDED
More than *10 of the current price has been set. You can view the current limits using the maximumLimitOrder Price and minimumLimitOrderPrice objects from the /api/v2/server/exchange info endpoint.