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'
})
};