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.
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
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
The expected errors when creating an order with the submit order endpoint are listed below. Review the meaning of the error you received.
Message | Code | Description |
---|---|---|
BALANCE_NOT_ENOUGH | 1055 | The balance amount is not enough for this operation. Check your balance amount using the /api/v1/users/balances endpoint. |
FAILED_MARKET_ORDER | 1118 | You might be sending wrong quantity or pairSymbol parameter. Quantity fields must be greater than zero, also pairSymbol field should be valid. You can check valid pairs from /api/v2/server/exchangeinfo endpoint. |
FAILED_LIMIT_ORDER | 1120 | You might be sending wrong price, quantity or pairSymbol parameter. Price and quantity fields must be greater than zero, also pairSymbol field should be valid. You can check valid pairs from /api/v2/server/exchangeinfo endpoint. |
FAILED_ORDER_WITH_OPEN_ORDERS | 1122 | 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 field from the /api/v1/users/balance endpoint. You may have an open order or a request to withdraw. For more details on open orders, please check documentation.
Get Open Orders |
FAILED_MIN_TOTAL_AMOUNT | 1123 | The order quantity is less than the minimum required. You can view the minimum order amount from the /api/v2/server/exchangeinfo endpoint. minExchangeValue value of a pair represents the correct minimum amount for order submitting. |
FAILED_STOP_PRICE_GREATER_THAN_BEST_ASK | 1124 | Stop buy price must be above best ask price. You can check the best ask price information from the /api/v2/ticker endpoint with the askfield. |
FAILED_STOP_PRICE_LESS_THAN_BEST_BID | 1125 | Stop sell price must be below best bid price. You can check the best bid price information from the /api/v2/ticker endpoint with the bidobject. |
FAILED_INVALID_PRICE_SCALE | 1126 | This error indicates that scale of the price you send is not valid for that pair. You can check denominatorScale field from /api/v2/server/exchangeinfo endpoint. |
FAILED_INVALID_QUANTITY_SCALE | 1127 | This error indicates that scale of the quantity you send is not valid for that pair. You can check numeratorScale field from /api/v2/server/exchangeinfo endpoint. |
FAILED_INVALID_STOP_PRICE_SCALE | 1128 | This error indicates that scale of the stopPrice you send is not valid for that pair. You can check denominatorScale field from /api/v2/server/exchangeinfo endpoint. |
ORDER_METHOD_NOT_SUPPORTED | 1134 | You might be sending invalid orderMethod parameter. valid orderMethod parameters should be one of this: limit, market, stopLimit, stopMarket Sometimes even though you send valid orderMethod parameter, that order method might not be allowed for a temporary time period for that pair. You can check orderMethods field from /api/v2/server/exchangeinfo endpoint. |
ORDER_TYPE_NOT_SUPPORTED | 1193 | You might be sending invalid orderTypeparameter. valid orderType parameters should be one of this: buy, sell. |
PRICE_MUST_BE_LESS_THAN_MAXPRICE | 1226 | Buy price must be less than maximum price for Limit and Stop-Limit order methods, for relevant pair.
You can view the maximum price information from the /api/v2/server/exchangeinfo endpoint with the maxPrice field. Please ensure that you’re checking correct pair. |
PRICE_MUST_BE_LESS_THAN_MINPRICE | 1227 | Sell price must be greater than min price for Limit and Stop-Limit order methods, for relevant pair.
You can view the minimum price information from the /api/v2/server/exchangeinfo endpoint with the minPrice field. Note: There is an conflict between error message and explanation. Please take description into consideration. |
ORDER_MAX_PRICE_EXCEEDED | 8003 | Limit or StopLimit order price is greater than maximumLimitOrderPrice . You can check the maximumLimitOrderPrice value from the /api/v2/server/exchangeinfo endpoint. |
ORDER_MIN_PRICE_EXCEEDED | 8004 | Limit or StopLimit order price is less than minimumLimitOrderPrice . You can check the minimumLimitOrderPrice value from the /api/v2/server/exchangeinfo endpoint. |
ORDER_INSERT_BLOCKED | 8005 | Maintenance work is in progress for the trading pair. You can implement one of the retry strategies or you can stop order insertions and follow our status page before starting to send order submit requests.
BtcTurk Status
Also please check the retry strategy guideline documentation before implementing retry strategy.
https://docs.btcturk.com/error-handling-for-order-operations/retry-strategy-guideline |
Last modified 1mo ago