Submit Order

post
Submit Order

https://api.btcturk.com/api/v1/order
Request
Response
Request
Headers
X-PCK
required
string
API public key. You can create the API key from the Account > API Access page in your exchange account.
X-Stamp
required
integer
Nonce must be current timestamp in miliseconds. It is a must to sync your current time with API server time which is in miliseconds format. Our servers are using UTC timezone.
X-Signature
required
string
Signature is a HMAC-SHA256 encoded message. The HMAC-SHA256 code must be generated using a private key that contains a timestamp as nonce and your API key.
Query Parameters
quantity
required
number
decimal, mandatory for market or limit orders.
price
optional
number
decimal, 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
optional
number
decimal, for stop orders
newOrderClientId
optional
string
string, GUID if user did not set.
orderMethod
required
string
enum, "limit", "market" or "stoplimit"
orderType
required
string
enum, "buy" or "sell"
pairSymbol
required
string
BTCTRY, ETHTRY etc.
Response
200: OK
{
"success": true,
"message": "OK",
"code": 0,
"data": {
"id": 9932534,
"datetime": 1543996112263,
"type": "Buy",
"method": "Limit",
"price": "20000.00",
"stopPrice": "20000.00",
"quantity": "0.001",
"pairSymbol": "BTCTRY",
"pairSymbolNormalized": "BTC_TRY",
"newOrderClientId": "test"
}
}

C# Code Example

// 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 = "BTC_TRY"
};
////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());

Python Code Example

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":"BTC_TRY"}
result = requests.post(url=uri, headers=headers, json=params)
result = result.json()
print(json.dumps(result, indent=2))

PHP Code Example

<?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':'BTC_TRY' }";
$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);

Expected Errors

  • PARAMETERS_ERROR: One of the giving parameters is not correct.

  • BALANCE_NOT_ENOUGH_WITHOUT_OPEN_ORDERS: You do not have enough funds for this operation.

  • BALANCE_NOT_ENOUGH: The available funds is not enough for this operation.

  • MIN_TOTAL: The order quantity is less than the minimum required.

  • STOP_PRICE_GREATER_THAN_MARKET: Stop buy price must be above current price.

  • STOP_PRICE_LESS_THAN_MARKET: Stop sell price must be bellow current price.

  • PRICE_MUST_BE_LESS_THAN_MAXPRICE: Buy or sell price must be less than max

  • FAILED_MIN_TOTAL_AMOUNT: quantity*price must be greater than min amount

  • FAILED_ORDER_WITH_OPEN_ORDERS: order submission failed due to open orders

  • FAILED_MARKET_ORDER: market order is not open for the pair