Submit Order
post
https://api.btcturk.com
/api/v1/order
Submit Order

C# Code Example

1
// You can download ApiClient .net core complete library from github https://github.com/BTCTrader/broker-api-csharp-v2
2
3
var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
4
5
var publicKey = configuration["publicKey"];
6
var privateKey = configuration["privateKey"];
7
var resourceUrl = configuration["resourceUrl"];
8
var apiClientV1 = new ApiClientV1(publicKey, privateKey, resourceUrl);
9
10
var limitSellOrder = new OrderInput
11
{
12
Quantity = 0.001m,
13
Price = 40000m,
14
NewOrderClientId = "test",
15
OrderMethod = OrderMethod.Limit,
16
OrderType = OrderType.Sell,
17
PairSymbol = "BTC_TRY"
18
};
19
20
////Create New Order
21
var orderOutput = apiClientV1.CreateOrder(limitSellOrder);
22
23
Console.WriteLine(!orderOutput.Result.Success
24
? quot;Code:{orderOutput.Result.Code} , Message: {orderOutput.Result.Message}"
25
: orderOutput.Result.Data.ToString());
Copied!

Python Code Example

1
import time, base64, hmac, hashlib, requests, json
2
3
base = "https://api.btcturk.com"
4
method = "/api/v1/order"
5
uri = base+method
6
7
apiKey = "YOUR_API_PUBLIC_KEY"
8
apiSecret = "YOUR_API_SECRET"
9
apiSecret = base64.b64decode(apiSecret)
10
11
stamp = str(int(time.time())*1000)
12
data = "{}{}".format(apiKey, stamp).encode("utf-8")
13
signature = hmac.new(apiSecret, data, hashlib.sha256).digest()
14
signature = base64.b64encode(signature)
15
headers = {"X-PCK": apiKey, "X-Stamp": stamp, "X-Signature": signature, "Content-Type" : "application/json"}
16
17
params={"quantity": 0.001,"price": 50000,"stopPrice": 0, "newOrderClientId":"BtcTurk Python API Test", "orderMethod":"limit", "orderType":"sell", "pairSymbol":"BTC_TRY"}
18
19
result = requests.post(url=uri, headers=headers, json=params)
20
result = result.json()
21
print(json.dumps(result, indent=2))
Copied!

PHP Code Example

1
<?php
2
$base = "https://api.btcturk.com";
3
$apiKey = "YOUR_API_PUBLIC_KEY";
4
$apiSecret = "YOUR_API_SECRET";
5
$method = "/api/v1/order";
6
$uri = $base.$method;
7
8
$post_data = "{ 'quantity' : '0.12345678', 'price' : '50000', 'stopPrice' : 0, newOrderClientId: 'BtcTurk API PHPClient', 'orderMethod':'limit', 'orderType':'sell', 'pairSymbol':'BTC_TRY' }";
9
10
$nonce = time()*1000;
11
$message = $apiKey.$nonce;
12
$signatureBytes = hash_hmac("sha256", $message, base64_decode($apiSecret), true);
13
$signature = base64_encode($signatureBytes);
14
$headers = array(
15
"X-PCK: ".$apiKey,
16
"X-Stamp: ".$nonce,
17
"X-Signature: ".$signature,
18
"Cache-Control: no-cache",
19
"Content-Type: application/json");
20
21
$ch = curl_init();
22
curl_setopt($ch, CURLOPT_URL, $uri);
23
curl_setopt($ch, CURLOPT_HTTP_VERSION, "CURL_HTTP_VERSION_1_2");
24
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
25
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
26
curl_setopt($ch, CURLOPT_POST, 1);
27
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
28
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
29
$result = curl_exec($ch);
30
31
if (curl_errno($ch)) {
32
print_r(curl_error($ch));
33
}
34
$answer = json_decode($result);
35
print_r($answer);
Copied!

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
Last modified 4mo ago