Introduction
Welcome to Btcturk API for trader and developers.
We have language bindings in C#, Python and PHP! You can view code examples in the dark area to the right, and you can switch the programming language of the examples with the tabs in the top right.
General Information
- API Base: https://api.btcturk.com
- All timestamps except OHLC Graph are in miliseconds. OHCL Graph returns values in seconds.
- Authentication related requests must be send as
application/json
- For
GET
endpoints, parameters must be sent as aquery string
. - For
POST
,PUT
, andDELETE
endpoints, the parameters may be sent as aquery string
or in therequest body
with content typeapplication/x-www-form-urlencoded
. You may mix parameters between both thequery string
andrequest body
if you wish to do so. - Parameters may be sent in any order.
- If a parameter sent in both the
query string
andrequest body
, thequery string
parameter will be used. - You can send pair symbol parameter in two formats, ex: BTCTRY or BTC_TRY
- All endpoints successful requests return JSON object model
Authentication
This API supports two types of authentication:
- API key (V1)
- OAuth2 (V2)
Authentication V1
To authorize, use the following code:
var apiKey = YOUR_API_PUBLIC_KEY;
var apiSecret = YOUR_API_SECRET;
var nonce = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliSeconds();
string message = apiKey + nonce;
using (HMACSHA256 hmac = new HMACSHA256(Convert.FromBase64String(apiSecret)))
{
byte[] signatureBytes = hmac.ComputeHash(Encoding.UTF8.GetBytes(message));
string X_Signature = Convert.ToBase64String(signatureBytes));
}
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": str(nonce),
"X-Signature": str(base64.b64encode(signature).decode('utf-8')),
"Content-Type: application/json"
}
<?php
$apiKey = YOUR_API_PUBLIC_KEY;
$apiSecret = YOUR_API_SECRET;
$message = $apiKey.(time()*1000);
$signatureBytes = hash_hmac('sha256', $message, base64_decode($apiSecret), true);
$signature = base64_encode($signatureBytes);
$nonce = time()*1000;
$headers = array(
'X-PCK: '.$apiKey,
'X-Stamp: '.$nonce,
'X-Signature: '.$signature,
'Content-Type: application/json',
);
All API calls related to a user account, require authentication.
You need to provide 3 parameters to authenticate a request:
- "X-PCK": API Public Key
- "X-Stamp": Nonce
- "X-Signature": Signature
API Public key
You can create the API key from the Account > API Access page in your exchange account.
Nonce
Nonce is a regular integer number. It must be current timestamp in milliseconds.
Signature
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
Usage
Append [https://api.btcturk.com/] URL to the beginning of the methods to use the API.
For example, to get ticker info from BTCTurk, use https://api.btcturk.com/api/v2/ticker
Testing
You can use our testing platforms to test the APIs. The balances on the test sites are not real and do not represent any real value. The testing platforms work on TESTNET and you can deposit TESTNET coins to your account. The testing platforms are:
- BTCTurk Test to create your test API keys.
- BTCTurk Test API
Questions & Problems
Please check the F.A.Q for Frequently Asked Questions. You can use the issues on this github project to ask questions and report bugs.
Public Endpoints
Ticker
// 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 tickerList = apiClientV1.GetTicker("BTC_TRY");
if (tickerList.Result.Success)
{
foreach (var ticker in tickerList.Result.Data)
{
Console.WriteLine(ticker.ToString());
}
}
else
{
Console.WriteLine(tickerList.Result.ToString());
}
import time, base64, hmac, hashlib, requests, json
base = "https://api.btcturk.com"
method = "/api/v2/ticker?pairSymbol=BTC_TRY"
uri = base+method
result = requests.get(url=uri)
result = result.json()
print(json.dumps(result, indent=2))
<?php
$base = "https://api.btcturk.com";
$method = "/api/v2/ticker?pairSymbol=BTC_TRY";
$uri = $base.$method;
$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);
$result = curl_exec($ch);
if (curl_errno($ch)) {
print_r(curl_error($ch));
}
$answer = json_decode($result);
print_r($answer);
Result:
{
"data": [
{
"pair": "BTCTRY",
"pairNormalized": "BTC_TRY",
"timestamp": 1570024156166,
"last": 47500,
"high": 48710,
"low": 47000,
"bid": 47472,
"ask": 47670,
"open": 47988,
"volume": 304.41,
"average": 47850.41,
"daily": -318,
"dailyPercent": -1.02,
"denominatorSymbol": "TRY",
"numeratorSymbol": "BTC"
},
{
"pair": "ETHTRY",
"pairNormalized": "ETH_TRY",
"timestamp": 1570024156166,
"last": 1020,
"high": 1034,
"low": 999,
"bid": 1019,
"ask": 1023,
"open": 1032,
"volume": 5038.27,
"average": 1015.66,
"daily": -9,
"dailyPercent": -1.16,
"denominatorSymbol": "TRY",
"numeratorSymbol": "ETH"
}
...
],
"success": true,
"message": "",
"code": 0,
}
If pairSymbol is not set, ticker for all pairs will be returned in a json array.
GET
../api/v2/ticker
OR
GET
.../api/v2/ticker?pairSymbol=BTC_TRY
OR
GET
.../api/v2/ticker/currency?symbol=USDT
- pair: Requested pair symbol
- pairNormalized: Requested pair symbol with "_" in between.
- timestamp: Current Unix time in milliseconds
- last: Last price
- high: Highest trade price in last 24 hours
- low: Lowest trade price in last 24 hours
- bid: Highest current bid
- ask: Lowest current ask
- open: Price of the opening trade in last 24 hours
- volume: Total volume in last 24 hours
- average: Average Price in last 24 hours
- daily: Price change in last 24 hours
- dailyPercent: Price change percent in last 24 hours
- denominatorSymbol: Denominator currency symbol of the pair
- numeratorSymbol: Numerator currency symbol of the pair
Order Book
// 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 orderbook = apiClientV1.GetOrderBook("BTC_TRY");
if (orderbook.Result.Success)
{
var bestBidPrice = orderbook.Result.Data.Bids[0][0];
var bestBidAmount = orderbook.Result.Data.Bids[0][1];
Console.WriteLine("Best bid price:" + bestBidPrice);
Console.WriteLine("Best bid amount:" + bestBidAmount);
}
else
{
Console.WriteLine(orderbook.Result.ToString());
}
import time, base64, hmac, hashlib, requests, json
base = "https://api.btcturk.com"
method = "/api/v2/orderbook?pairSymbol=BTC_TRY"
uri = base+method
result = requests.get(url=uri)
result = result.json()
print(json.dumps(result, indent=2))
<?php
$base = "https://api.btcturk.com";
$method = "/api/v2/orderbook?pairSymbol=BTC_TRY&limit=100";
$uri = $base.$method;
$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);
$result = curl_exec($ch);
if (curl_errno($ch)) {
print_r(curl_error($ch));
}
$answer = json_decode($result);
print_r($answer);
Result:
{
"success": true,
"message": null,
"code": 0,
"data": {
"timestamp": 1543836448605,
"bids": [
[
"33245.00",
"2.10695265"
],
[
"33209.00",
"0.001"
]
],
"asks": [
[
"33490.00",
"0.03681877"
],
[
"33499.00",
"1.00000000"
]
]
}
}
GET
.../api/v2/orderbook?pairSymbol=BTC_TRY
OR
GET
.../api/v2/orderbook?pairSymbol=BTC_TRY&limit=100
- pairSymbol: string Mandatory
- limit: int Optional (default 100 max 1000)
- timestamp: Current Unix time in milliseconds
- bids: Array of current open bids on the orderbook.
- asks: Array of current open askss on the orderbook.
Trades
// 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 trades = apiClientV1.GetLastTrades("BTC_TRY", 10);
if (trades.Result.Success)
{
Console.WriteLine("Last 10 trades in the market");
foreach (var trade in trades.Result.Data)
{
Console.WriteLine(trade.ToString());
}
}
else
{
Console.WriteLine(trades.Result.ToString());
}
import time, base64, hmac, hashlib, requests, json
base = "https://api.btcturk.com"
method = "/api/v2/trades?pairSymbol=BTC_TRY&last=50"
uri = base+method
result = requests.get(url=uri)
result = result.json()
print(json.dumps(result, indent=2))
<?php
$base = "https://api.btcturk.com";
$method = "/api/v2/trades?pairSymbol=BTC_TRY&last=50";
$uri = $base.$method;
$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);
$result = curl_exec($ch);
if (curl_errno($ch)) {
print_r(curl_error($ch));
}
$answer = json_decode($result);
print_r($answer);
Result:
{
"success": true,
"message": null,
"code": 0,
"data": [
{
"pair": BTCTRY,
"pairNormalized": BTC_TRY,
"numerator": BTC,
"denominator": TRY,
"date": 1533650242300,
"tid": "636692470417865271",
"price": "33490",
"amount": "0.00032747"
},
{
"pair": BTCTRY,
"pairNormalized": BTC_TRY,
"numerator": BTC,
"denominator": TRY,
"date": 1533650237143,
"tid": "636692470367947749",
"price": "33245",
"amount": "0.00471901"
}
]
}
GET
.../api/v2/trades?pairSymbol=BTC_TRY
OR
GET
.../api/v2/trades?pairSymbol=BTC_TRY&last=COUNT (Max. value for count parameter is 50)
- pair: Requested pair symbol
- pairNormalized: Request Pair symbol with "_" in between.
- numerator: Numerator currency for the requested pair
- denominator: Denominator currency for the requested pair
- date: Unix time of the trade in milliseconds
- tid: Trade ID
- price: Price of the trade
- amount: Amount of the trade
OHCL Data (Returns daily cumulative data)
import time, base64, hmac, hashlib, requests, json
base = "https://graph-api.btcturk.com"
method = "/v1/ohlcs?pair=BTC_TRY"
uri = base+method
result = requests.get(url=uri)
result = result.json()
print(json.dumps(result, indent=2))
<?php
$base = "https://graph-api.btcturk.com";
$method = "/v1/ohlcs?pair=BTC_TRY";
$uri = $base.$method;
$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);
$result = curl_exec($ch);
if (curl_errno($ch)) {
print_r(curl_error($ch));
}
$answer = json_decode($result);
print_r($answer);
GET
https://graph-api.btcturk.com/v1/ohlcs?pair=BTC_TRY
OR
GET
https://graph-api.btcturk.com/v1/ohlcs?pair=BTC_TRY&from=1582132083&to=1582532083
Result:
[
{
"pair": "BTCTRY",
"time": 1582070400,
"open": 61940,
"high": 62698,
"low": 58500,
"close": 58801,
"volume": 549.1858885452384,
"total": 33566080.63598728,
"average": 61119.71,
"dailyChangeAmount": -3139,
"dailyChangePercentage": -5.07
},
{
"pair": "BTCTRY",
"time": 1582156800,
"open": 59150,
"high": 61000,
"low": 58477,
"close": 59100,
"volume": 663.4533811472954,
"total": 39211283.23027989,
"average": 59101.79,
"dailyChangeAmount": -50,
"dailyChangePercentage": -0.08
},
{
"pair": "BTCTRY",
"time": 1582243200,
"open": 59104,
"high": 60399,
"low": 58801,
"close": 59704,
"volume": 387.62553661495724,
"total": 23127026.682461508,
"average": 59663.32,
"dailyChangeAmount": 600,
"dailyChangePercentage": 1.02
}
]
- pair: Requested pair symbol
- timestamp: Unix time in seconds
- open: Price of the opening trade on the time
- high: Highest trade price on the time
- low: Lowest trade price on the time
- close: Price of the closing trade on the time
- volume: Total volume on the time
- average: Average price on the time
- total: Total order amount on the time
- dailyChangeAmount: Amount of difference between Close and Open on the Date
- dailyChangePercentage: Percentage of difference between Close and Open on the Date
Private Endpoints
Account Balance
// 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 balances = apiClientV1.GetBalances();
if (balances.Result != null && balances.Result.Success)
{
foreach (var balance in balances.Result.Data)
{
Console.WriteLine(balance.ToString());
}
}
import time, base64, hmac, hashlib, requests, json
base = "https://api.btcturk.com"
method = "/api/v1/users/balances"
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"}
result = requests.get(url=uri, headers=headers)
result = result.json()
print(json.dumps(result, indent=2))
<?php
$base = "https://api.btcturk.com";
$apiKey = "YOUR_API_PUBLIC_KEY";
$apiSecret = "YOUR_API_SECRET";
$method = "/api/v1/users/balances";
$uri = $base.$method;
$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_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
print_r(curl_error($ch));
}
$answer = json_decode($result);
print_r($answer);
GET
.../api/v1/users/balances
Result:
{
"data": [
{
"asset": "TRY",
"assetname": "Türk Lirası",
"balance": "103158.9412490031968651",
"locked": "1023.5699999896000000",
"free": "102135.3712490135968651"
},
{
"asset": "BTC",
"assetname": "Bitcoin",
"balance": "29.6027353000000000",
"locked": "0.0010000000000000",
"free": "29.6017353000000000"
}
...
],
"success": true,
"message": null,
"code": 0
}
- asset: Asset symbol
- assetname: Asset name
- balance: Total asset balance including open orders and pending withdrawal requests
- locked: Asset locked amount in open orders and withdrawal requests
- free: Asset available amount for trading
User Transactions
// 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 startdate = new DateTime(2019, 11, 19);
var endatet = new DateTime(2019, 12, 19);
var userTrades = apiClientV1.GetUserTrades(new[] { "buy", "sell" }, new[] { "try", "btc" }, startdate.ToUnixTime(), endatet.ToUnixTime());
if (userTrades.Result.Success)
{
foreach (var userTrade in userTrades.Result.Data)
{
Console.WriteLine(userTrade);
}
}
import time, base64, hmac, hashlib, requests, json
base = "https://api.btcturk.com"
method = "/api/v1/users/transactions/trade?type=buy&type=sell&symbol=btc&symbol=try&symbol=usdt"
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"}
result = requests.get(url=uri, headers=headers)
result = result.json()
print(json.dumps(result, indent=2))
<?php
$base = "https://api.btcturk.com";
$apiKey = "YOUR_API_PUBLIC_KEY";
$apiSecret = "YOUR_API_SECRET";
$method = "/api/v1/users/transactions/trade?type=buy&type=sell&symbol=btc&symbol=try&symbol=usdt";
$uri = $base.$method;
$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_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
print_r(curl_error($ch));
}
$answer = json_decode($result);
print_r($answer);
Get
.../api/v1/users/transactions/trade?type=buy&type=sell&symbol=btc&symbol=try&symbol=usdt
Result:
{
"success": true,
"message": "SUCCESS",
"code": 0,
"data": [
{
"price": 33700,
"numeratorSymbol": "BTC",
"denominatorSymbol": "TRY",
"orderType": "sell",
"id": 5553445,
"timestamp": 1533314288287,
"amount": -0.003,
"fee": -0.0685423626,
"tax": -0.012337625268
},
{
"price": 33700,
"numeratorSymbol": "BTC",
"denominatorSymbol": "TRY",
"orderType": "sell",
"id": 5553444,
"timestamp": 1533314254297,
"amount": -0.001,
"fee": -0.0514067888,
"tax": -0.009253221984
},
{
"price": 4.77,
"numeratorSymbol": "USDT",
"denominatorSymbol": "TRY",
"orderType": "buy",
"id": 5553442,
"timestamp": 1533313928057,
"amount": 2.09,
"fee": -0.0152074094832,
"tax": -0.002737333706976
} ...
}
Params
- type: string array, {"buy", "sell"}
- symbol: string array, {"btc", "try", ...etc.}
- startDate: long Optional timestamp if null will return last 30 days
- endDate: long Optional timestamp if null will return last 30 days
Result
- price: Trade price
- numeratorSymbol: Trade pair numerator symbol
- denominatorSymbol: Trade pair denominator symbol
- orderType: Trade type (buy,sell)
- id: Trade id
- orderId: Order id which traded
- timestamp: Unix timestamp
- amount: Trade Amount (always negative if order type is sell)
- fee: Trade fee
- tax: Trade tax
POST
.../api/v1/users/transactions/crypto
// 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 userCryptoTransactions = apiClientV1.GetUserCryptoTransactions(new[] { "deposit", "withdrawal" }, new[] { "btc", "eth", "xrp" }, DateTime.UtcNow.AddDays(-30).ToUnixTime(), DateTime.UtcNow.ToUnixTime());
if (userCryptoTransactions.Result.Success)
{
foreach (var userCryptoTransaction in userCryptoTransactions.Result.Data)
{
Console.WriteLine(userCryptoTransaction);
}
}
import time, base64, hmac, hashlib, requests, json
base = "https://api.btcturk.com"
method = "/api/v1/users/transactions/crypto"
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"}
result = requests.get(url=uri, headers=headers)
result = result.json()
print(json.dumps(result, indent=2))
<?php
$base = "https://api.btcturk.com";
$apiKey = "YOUR_API_PUBLIC_KEY";
$apiSecret = "YOUR_API_SECRET";
$method = "/api/v1/users/transactions/crypto";
$uri = $base.$method;
$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_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
print_r(curl_error($ch));
}
$answer = json_decode($result);
print_r($answer);
Result:
{
"success": true,
"message": "SUCCESS",
"code": 0,
"data": [
{
"balanceType": "Deposit",
"currencySymbol": "XRP",
"id": 676961,
"timestamp": 1544079921450,
"funds": 10.8,
"amount": 0.9,
"fee": 0,
"tax": 0
},
{
"balanceType": "Withdrawal",
"currencySymbol": "XRP",
"id": 516136,
"timestamp": 1544079921450,
"funds": 8.9,
"amount": -1,
"fee": 0,
"tax": 0
} ...
]
}
Params
- type: string array , {'deposit', 'withdrawal'}
- symbol: string array , {'btc', 'eth', 'xrp, ...etc.}
- startDate: long Optional timestamp if null will return last 30 days
- endDate: long Optional timestamp if null will return last 30 days
POST
.../api/v1/users/transactions/fiat
// 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 userFiatTransactions = apiClientV1.GetUserFiatTransactions(new[] { "deposit", "withdrawal" }, new[] { "try" }, DateTime.UtcNow.AddDays(-30).ToUnixTime(), DateTime.UtcNow.ToUnixTime());
if (userFiatTransactions.Result.Success)
{
foreach (var userFiatTransaction in userFiatTransactions.Result.Data)
{
Console.WriteLine(userFiatTransaction);
}
}
import time, base64, hmac, hashlib, requests, json
base = "https://api.btcturk.com"
method = "/api/v1/users/transactions/fiat"
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"}
result = requests.get(url=uri, headers=headers)
result = result.json()
print(json.dumps(result, indent=2))
<?php
$base = "https://api.btcturk.com";
$apiKey = "YOUR_API_PUBLIC_KEY";
$apiSecret = "YOUR_API_SECRET";
$method = "/api/v1/users/transactions/fiat";
$uri = $base.$method;
$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_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
print_r(curl_error($ch));
}
$answer = json_decode($result);
print_r($answer);
Result:
{
"success": true,
"message": "SUCCESS",
"code": 0,
"data": [
{
"balanceType": "Deposit",
"currencySymbol": "TRY",
"id": 93214,
"timestamp": 1544079972687,
"funds": 100000,
"amount": 1000,
"fee": 0,
"tax": 0
},
{
"balanceType": "Deposit",
"currencySymbol": "TRY",
"id": 919664,
"timestamp": 1544079972687,
"funds": 100000.04,
"amount": 100000,
"fee": 0,
"tax": 0
} ...
}
Params
- balanceTypes: string array, {"deposit", "withdrawal"}
- currencySymbols: string array, {"try" ...etc.}
- startDate: long Optional timestamp if null will return last 30 days
- endDate: long Optional timestamp if null will return last 30 days
Result
- balanceType: Type of transaction (deposit, withdrawal)
- currencySymbol: Transaction currency symbol
- id: Transaction id
- timestamp: Unix timestamp
- amount: Transaction Amount
- fee: Transaction fee
- tax: Transaction tax
Open Orders
// 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 openOrders = apiClientV1.GetOpenOrders();
if (openOrders.Result != null && openOrders.Result.Success)
{
foreach (var askOrder in openOrders.Result.Data.Asks)
{
Console.WriteLine(askOrder);
}
foreach (var bidOrder in openOrders.Result.Data.Bids)
{
Console.WriteLine(bidOrder);
}
}
import time, base64, hmac, hashlib, requests, json
base = "https://api.btcturk.com"
method = "/api/v1/openOrders?pairSymbol=BTC_TRY"
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"}
result = requests.get(url=uri, headers=headers)
result = result.json()
print(json.dumps(result, indent=2))
<?php
$base = "https://api.btcturk.com";
$apiKey = "YOUR_API_PUBLIC_KEY";
$apiSecret = "YOUR_API_SECRET";
$method = "/api/v1/openOrders?pairSymbol=BTC_TRY";
$uri = $base.$method;
$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_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
print_r(curl_error($ch));
}
$answer = json_decode($result);
print_r($answer);
GET
.../api/v1/openOrders?pairSymbol=BTC_TRY
Result:
{ "success": true,
"message": null,
"code": 0,
"data": {
"asks": [{
"id": 16060235,
"price": "66800.00",
"amount": "0.09733687",
"quantity": "0.09733687",
"stopPrice": "0.00",
"pairSymbol": "BTCTRY",
"pairSymbolNormalized": "BTC_TRY",
"type": "sell",
"method": "limit",
"orderClientId": "da593000-6eb3-4a1c-ba26-c616122a0210",
"time": 0,
"updateTime": 1591286401373,
"status": "Untouched",
"leftAmount": "0.09733687"
},
{
"id": 16060237,
"price": "66867.00",
"amount": "0.04971904",
"quantity": "0.04971904",
"stopPrice": "0.00",
"pairSymbol": "BTCTRY",
"pairSymbolNormalized": "BTC_TRY",
"type": "sell",
"method": "limit",
"orderClientId": "da593000-6eb3-4a1c-ba26-c616122a0210",
"time": 0,
"updateTime": 1591286411913,
"status": "Partial",
"leftAmount": "0.0412345"
},
],
"bids": [{
"id": 16071095,
"price": "65817.00",
"amount": "0.08956055",
"quantity": "0.08956055",
"stopPrice": "0.00",
"pairSymbol": "BTCTRY",
"pairSymbolNormalized": "BTC_TRY",
"type": "buy",
"method": "limit",
"orderClientId": "da593000-6eb3-4a1c-ba26-c616122a0210",
"time": 0,
"updateTime": 1591352311273,
"status": "Untouched",
"leftAmount": "0.08956055"
},
{
"id": 14703840,
"price": "30451.00",
"amount": "0.06140209",
"quantity": "0.06140209",
"stopPrice": "0.00",
"pairSymbol": "BTCTRY",
"pairSymbolNormalized": "BTC_TRY",
"type": "buy",
"method": "limit",
"orderClientId": "da593000-6eb3-4a1c-ba26-c616122a0210",
"time": 0,
"updateTime": 1584426660947,
"status": "Partial",
"leftAmount": "0.04909774"
}]
}
}
- id: Order id
- price: Price of the order
- amount: Amount of the order
- quantity: quantity of the order
- stopPrice: stop order price if method is stop limit
- pairsymbol: Pair of the order
- pairSymbolNormalized: Pair of the order with "_" in between.
- type: Type of order. Buy or Sell
- method: Method of order. Limit, Stop Limit
- orderClientId: Order client id created with (GUID if not set by user)
- time: Unix time the order was inserted at
- updateTime: Unix time last updated
- status: Status of the order. Untouched (not matched), Partial (matched partially)
- leftAmount: Order left amount if it matched partialy
Cancel Order
// 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 orderId = 123456;
var cancelOrder = apiClientV1.CancelOrder(orderId);
if (cancelOrder.Result)
{
Console.WriteLine($"Successfully canceled order {orderId}");
}
else
{
Console.WriteLine("Could not cancel order");
}
import time, base64, hmac, hashlib, requests, json
base = "https://api.btcturk.com"
method = "/api/v1/order?id=ORDER_ID"
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"}
result = requests.delete(url=uri, headers=headers)
result = result.json()
print(json.dumps(result, indent=2))
<?php
$base = "https://api.btcturk.com";
$apiKey = "YOUR_API_PUBLIC_KEY";
$apiSecret = "YOUR_API_SECRET";
$method = "/api/v1/order?id=ORDER_ID";
$uri = $base.$method;
$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_CUSTOMREQUEST, "DELETE");
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);
DELETE
.../api/v1/order?id=1
Result:
{
"success": true,
"message": "string",
"code": "",
"data": {
}
}
- Result: Success true if the order cancellation succeeded. False if it failed.
Submit Order
// 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());
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
$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);
POST
.../api/v1/order
Result:
{
"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"
}
}
Params:
- quantity: "decimal", Mandatory for market or limit orders.
- price: "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: "decimal", For stop orders
- newOrderClientId: "string", GUID if user did not set.
- orderMethod: "enum", "limit", "market" or "stoplimit"
- orderType: "enum", "buy", "sell"
pairSymbol: "string", ex: "BTCTRY", "ETHTRY"
The result is a JSON object containing your order details and order ID if the request succeeded.
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.
All Orders
import time, base64, hmac, hashlib, requests, json
base = "https://api.btcturk.com"
method = "/api/v1/allOrders?pairSymbol=BTCTRY"
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"}
result = requests.get(url=uri, headers=headers)
result = result.json()
print(json.dumps(result, indent=2))
<?php
$base = "https://api.btcturk.com";
$apiKey = "YOUR_API_PUBLIC_KEY";
$apiSecret = "YOUR_API_SECRET";
$method = "/api/v1/allOrders?pairSymbol=BTCTRY";
$uri = $base.$method;
$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_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
print_r(curl_error($ch));
}
$answer = json_decode($result);
print_r($answer);
GET
.../api/v1/allOrders?pairSymbol=BTC_TRY
Result
{
"success": true,
"message": null,
"code": 0,
"data": [
{
"id": 9932534,
"price": "20000.00",
"amount": "0.001",
"quantity": "0.001",
"pairsymbol": "BTCTRY",
"pairsymbolnormalized":"BTC_TRY",
"type": "Buy",
"method": "Limit",
"orderClientId": "test",
"time": 1543996112263,
"updateTime": 1543996112263,
"status": "Untouched"
},
{
"id": 9932533,
"price": "21000.00",
"amount": "0.001",
"quantity": "0.001",
"pairsymbol": "BTCTRY",
"pairsymbolnormalized":"BTC_TRY",
"type": "Buy",
"method": "Limit",
"orderClientId": "test",
"time": 1543994632920,
"updateTime": 1543994632920,
"status": "Untouched"
},
{
"id": 9932523,
"price": "2000.00",
"amount": "0.01",
"quantity": "0.01",
"pairsymbol": "BTCTRY",
"pairsymbolnormalized":"BTC_TRY",
"type": "Buy",
"method": "Limit",
"orderClientId": "test",
"time": 1543500891493,
"updateTime": 1543501769613,
"status": "Canceled"
}
]
}
Params:
- orderId: integer optional, If orderId set, it will return all orders greater than or equals to this order id
- pairSymbol: pair symbol
- startTime: integer optional, start time
- endTime: integer optional, end time
- page: integer optional, page number
- limit: integer optional, default 100 max 1000
Result
- id: Order id
- price: Price of the order
- amount: Amount of the order
- quantity: quantity of the order
- pairsymbol: Pair of the order
- pairSymbolNormalized: Pair of the order with "_" in between.
- type: Type of order. Buy or Sell
- method: Method of order.
- orderClientId: Order client id created with (GUID if not set by user)
- time: Unix time the order was inserted at
- updateTime: Unix time last updated
- status: Status of the order. Untouched, Matched partialy, Canceled
Rate Limits
Retry-After When you receive 429 (Too Many Requests) response, this indicates how long you have to wait before making a new request. Please refer to this link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
Endpoints | Method | Requests per minute |
All Endpoints | ||
api/v1/* | * | 600 |
Balance | ||
/api/v1/users/balances | GET | 90 |
CryptoWithdrawal | ||
/api/v1/withdrawals/crypto | POST | 10 |
Order | ||
/api/v1/order | POST | 300 |
/api/v1/order | DELETE | 300 |
/api/v1/openOrders | GET | 300 |
/api/v1/allOrders | GET | 300 |
Trade | ||
/api/v1/trades | GET | 90 |
UserTransactions | ||
/api/v1/users/transactions/ |
GET | 90 |
/api/v1/users/transactions/ |
GET | 90 |
/api/v1/users/transactions/ |
GET | 90 |
/api/v1/users/transactions/ |
GET | 90 |
Ticker | ||
/api/v2/ticker | GET | 600 |
/api/v2/orderBook | GET | 60 |
Websocket Feed
Btcturk websocket feed provides real-time market data for orders and trades.
- Live : wss://ws-feed-pro.btcturk.com/
- Test : wss://ws-feed-sandbox.btctrader.com
We can list the general information about the life cycle after the connection to the server is as follows.
Once the connection is established, the server does not send messages directly to the client.
The user sends the first message. This is usually a member login message.
After sending messages such as client login, subscription, the server will return the response with the result model. This information may be used for information and control purposes.
After the user is logged in, the server can now receive messages that are specific to this user, of type U. The client should listen to these messages and process them according to incoming messages.
If the client wants to track a particular event, it must subscribe to it. Events are located inside the channels. To subscribe to an event, the channel name and event name must be specified.
After subscribing to an event, messages about this event are continuously sent from the server to the client.
If the client does not want to receive messages for this event, it sends unsubscribe messages. For example, when BTCTRY pair is selected in the application, BTCTRY events are subscribed. Then, when user selects ETHTRY pair, BTCTRY subscriptions must be exited and ETHTRY subscriptions must be entered.
There is no limit to the event subscription. All events can be subscribed at the same time. However, this client can use the traffic heavily. Subscriptions to all events are not recommended for restricted or paid connections.
General information about server connection and user login operations can be listed as follows:
- If the client is not a guest, the user sends the login package.
- The login package (to indicate that the guest has been entered as a guest) can also be sent for guest users. In this case, user id value is 0, user name is “guest” and token value is null.
- Only one user login is required on a WebSocket connection.
- If the WebSocket connection is lost, the user login package must be sent again when the connection is established.
- Once a user is logged in, re-logging is not supported. However, if a guest login notification has already been made, user login can be made through the same connection.
Porotocol
The websocket feed uses a bidirectional protocol, which encodes all messages as JSON objects. All messages have a type attribute that can be used to handle the message appropriately.
Please note that new message types can be added at any point in time. Clients are expected to ignore messages they do not support.
Channels and Events
Data such as order book, ticker, last transactions are not sent directly after connection or user login is made. There is a specific channel and event for each process. By subscribing to these channels and events, this data is received. Once subscribed to a channel, the server sends events to that channel continuously to the client, unless the unsubscribe message is sent.
On the server, the channels generally represent the places where the transaction takes place (order book,last transactions, etc.) and the events represent the pair value (such as BTCTRY, ETHTRY, XLMUSDT) where the transaction takes place. In some special cases, these values may change. For example, to receive ticker data for all pairs, it is necessary to subscribe to the all event of the ticker channel . The server runs on 3 channels:
1) orderbook : Sends the transactions in the order book. The event name is the upper-case name of the pair. Ex: BTCTRY
2) trade : Sends data for recent transactions. Depending on the data type, incoming data can be individual or aggregated. The event name is the upper-case name of the pair. Ex: BTCTRY
3) ticker : Sends the current ticker data. There are two types of events. In the all event, the data for all pairs comes. To receive only events of a particular pair, you must subscribe to the upper-case pair name event. Ex: BTCTRY
The sample code to subscribe to the event is as follows:
[151,
{
type: 151,
channel: 'trade',
event: 'ETHTRY',
join: true
}
]
Similarly, a message like the following is sent to exit the subscribed event
[151,
{
type: 151,
channel: 'ticker',
event: 'all',
join: false
}
]
Models
The supported model types between Server and Client are given in the following tables.
- The Code in the table is the type value of the model. (The number on the top left of the model)
- ShortName is the model code (which we use this way) that can be used as a variable, class, or enum name.
- Mixes of types (letter code at the top right of the model) and usage patterns are as follows:
- P: general packages. Contains type. There is no need to subscribe or login to any channel to receive or send.
- U: General packages that are accessed only by logged-in users. These packages also do not have a /channel and subscription connection.
- A: Packages received only when subscribed to events on the channels. In the models of these packages, besides the type variable, there are string variables named channel and event.
100 | Result | P | |
A message sent from the server to the client. These are model-free results returned from requests sent to the server. For example, UserLogin, Subscription, and so on. | |||
Type | number | Model type | |
ID | number | Id value of the model being processed. It is used in some Result models. The value can be 0 when not in use. | |
Ok | boolean | Transaction success | |
message | string | transaction message. It usually contains short codes for the transaction. It should not be shown to the end user. For example, the value returned as subscription result: “join | trade: BTCTRY” is similar. |
101 | Request | P | ||
Extra requests sent to the server. For example, the Request model is sent when the last operations list is requested again. | ||||
type | number | Model type | ||
code | number | The request code. Designed in the same way as possible with package types. These request codes are listed at the end of the document. For example, the client must send this code value 421 (model type of final operations) to request that the last transactions be sent back to it. | ||
channel | string | If the request is sent over a particular channel, this value must be written to the channel name. For non-channel requests, null can be sent. | ||
event | string | If the request is sent over a particular event, this value must be written to the name of the event. For non-event requests, null can be sent. |
111 | UserLogin | P | |
A message sent from the client to the server. User input model. | |||
type | number | Model type | |
ID | number | The id value of the user. Must be sent. The server checks for its equality with the value read from the Token. If you want to make a guest login notification, send 0 to this value. (Guest login notification is not mandatory in the system) | |
username | string | User name. E-mail address for BtcTurk. Giriş guest. Should be written in the guest entrance notifications. | |
token | string | The current token value of the user from SSO. Null must be sent in guest notifications. | |
app | string | Application name: “pro” or “easy” | |
platform | string | User's operating system or browser information: “android”, “ios”, “windows”, “linux” |
112 | UserLoginResult | P |
A message sent from the server to the client. This is the answer to the user input model. It is exactly the same as the Result model. Only the model type is 112. |
113 | UserLogout | U | ||
It is a message that is sent back from client to server and back from server to client. The user is the output model. After this model is taken, the server will terminate the socket connection. | ||||
type | number | Model type | ||
ID | number | User Id |
151 | Subscription | P | ||
A message sent from the client to the server. A model sent to subscribe to or unsubscribe from an event on a channel. Messages related to subscribed events are continuously sent to the user. | ||||
type | number | Model type | ||
channel | string | The name of the channel. For example; trade, orderbook, ticker etc. | ||
event | string | speak event name event name. Event names are often used as “all” or upper-case as pair name (eg BTCTRY, ETHTRY). | ||
jon | boolean | If true, it means that you want to subscribe, if false, you can unsubscribe. |
201 | BalanceUpdated | U | ||
The model sent by the server when the user's balance changes for any reason (confirmation, withdrawal request, deposit request, request confirmations, etc.). When this message is received, the user's balance must be updated from the API endpoint. | ||||
type | number | Model type | ||
UserID | number | User Id | ||
payload | string | Transaction description. For informational purposes. |
401 | TickerAll | C | ||
A message sent from the server to the client. It is the model of all ticker data belonging to all Pairs. | ||||
type | number | Model type | ||
items | TickerPair [] | An array of type TickerPair. The only difference is that there is no type variable in every TickerPair model. The TickerPair model is described below. |
402 | TickerPair | C | ||
A message sent from the server to the client. It is only a model of all ticker data for a particular Pair. | ||||
type | number | Model type | ||
PS | string | Pair Symbol. For example; BTCTRY | ||
H | string | High. Highest price in the last 24 hours. | ||
L | string | Lower. The lowest price in the last 24 hours. | ||
La | string | Last. The price of the last transaction. | ||
SHE IS | string | Open. Price of the first transaction of the day | ||
V | string | Volume. Volume. | ||
AV | string | Average. Average price. | ||
D | string | Daily. Daily change amount. | ||
DS | string | Denominator Symbol. For example BTCTRY TRY. | ||
NS | string | Numerator Symbol. For example BTCTRY for BTC. | ||
PID | number | Pair Id value. | ||
NPr | number | Numerator precision value. For example BTC 8 | ||
Dpr | number | Denominator precision value. For example TRY 2 | ||
Ord | number | Pair's display sequence. | ||
B | string | Bidar. Best purchase order price. | ||
A | string | Love. Best selling order price. | ||
DP | string | Daily percent. 24-hour exchange rate. |
421 | TradeList | C | ||
A message sent from the server to the client. This is the list of all recent transactions of the specified Pair. | ||||
type | number | Model type | ||
channel | string | Message channel | ||
event | string | The name of the event to which the message was delivered. | ||
symbol | string | Pair symbol. For example; BTCTRY | ||
items | TradeSingle [] | An array in the list that contains a transaction log. The TradeSingle model is described below. The TradeSingle models in the TradeList model do not contain the PS and type variables. |
422 | TradeSingle | C | ||
A message sent from the server to the client. It is a single trade data of the specified Pair. This data is sent as it occurs. | ||||
type | number | Model type | ||
PS | number | Pair Symbol. For example; BTCTRY. | ||
A | string | Amount. The amount of the transaction. | ||
D | number | Date. Transaction date. UnixTime is the value in milliseconds. | ||
P | string | Price. The price at which the transaction was made. | ||
I | string | The unique number of the transaction. (Uniqueness is valid only in its own pairi) |
431 | OrderBookFull | C | ||
A message sent from the server to the client. It is the entire order book model of a particular Pair. | ||||
type | number | Model type | ||
CS | number | ChangeSet. Change number. It comes in the form of sequential values. There is no control at this time. | ||
PS | string | Pair Symbol value. For example; BTCTRY | ||
AO | Order [] | List of sales orders. The Order object contains two variables: A, amount, and transaction quantity. P is the price, the transaction price. | ||
BO | Order [] | List of purchase orders. |
432 | OrderBookDifference | C | ||
A message sent from the server to the client. Sends order book data of only a particular Pair's changes. The user must have previous order book data to use this model. This data is sent automatically from the server when the event is subscribed. | ||||
changingord is
| ||||
type | number | Model type | ||
CS | number | ChangeSet. Change number. It comes in the form of sequential values. There is no control at this time. | ||
PS | string | Pair Symbol value. For example; BTCTRY | ||
AO | ChangingOrder [] | List of sales orders. The Order object contains two variables: A, amount, and transaction quantity. P is the price, the transaction price. | ||
BO | ChangingOrder [] | List of purchase orders. |
441 | UserOrderMatch | U | |
It is the model that contains the details of this process, which is sent from the server to the user when an order of the connected user is executed. | |||
type | number | Model type | |
ID | number | Id value of the model being processed. | |
user | boolean | The id of the user being processed. | |
IsBid | string | True if the transaction is buying or false if the transaction is buying. | |
method | number | transaction method. 0: limit, 1: market, 2: stop limit | |
pair | number | pair id value of the transaction | |
symbol | string | The pair symbol value of the operation. For example; BTCTRY | |
numTotal | string | Total Numerator amount of the order | |
numleft | string | The quantity of the numerator remaining after the trade has been executed. | |
denomTotal | string | Total denominator amount of order | |
denomLeft | string | The denominator amount of the order remaining after the trade has taken place. | |
amount | string | The amount of the transaction. | |
price | string | The price at which the transaction occurred. |
451 | orderınsert | U | ||
A message sent from the server to the client. When a user's order is added to the system, it is the model sent to the user. Newly added orders will be sent with the model. When this model is received from the server, the user's orders can be updated from the endpoint. | ||||
type | number | Model type | ||
pairId | number | The pair id value of the order. | ||
symbol | string | The pair symbol value of the order. | ||
ID | number | Order Id value. | ||
method | number | Type of order (0: limit, 1: market, 2: stop limit) | ||
userId | number | The Id value of the user who issued the order. | ||
price | string | Price of the order | ||
amount | string | Amount of order |
452 | OrderDelete | U |
A message sent from the server to the client. When a user's order is deleted from the system, it is the model that is sent to the user. Deleted orders with model will be sent. When this model is received from the server, the user's orders can be updated from the endpoint. The model is the same as the OrderInsert model. |
453 | OrderUpdate | U |
A message sent from the server to the client. This is the model sent to the user when an order of the user is updated in the system. Orders updated with the model will be sent. When this model is received from the server, the user's orders can be updated from the endpoint. The model is the same as the OrderInsert model. |
Channel, Event and Model
For use on browsers or platforms where WebSocket is not supported, it is also possible to access data sent via WebSocket with specific endpoints.
Channel | Event | Model | Explanation |
ticker | all | 401 | Data is sent at specified intervals (not later than once per second). Contains all pair ticker data. |
ticker | [PAIR] | 402 | Data is sent at specified intervals (not later than once per second). |
trade | [PAIR] | 421 | One-time full trade model 421 is sent as subscribed . Only new incoming trade models 422 are then sent. |
orderbook | [PAIR] | 431 | All order book data is sent at certain intervals (at the latest every second). |
obdiff | [PAIR] | 431 | As ordered , a one-time full orderbook model 431 is sent. Only the exchange model 432 is then sent. |
Tradingview
radingView data is transmitted over the tradeview channel. PAIR_RESOLUTION events must be subscribed to on this channel . Supported resolution values for TradingView data are 1, 5, 15, 30, 60, 240 for minutes up to 4 hours . Daily, weekly and monthly ones are 1D, 1W, 1M . For example, a user who wants to view the trading hours BTCTRY follow the data tradeview the remaining BTCTRY_60 must subscribe to the event. With another example, if you want to follow the daily ETHTRY trading view data, you should subscribe to the ETHTRY_1D event of the tradeview channel . NOTE: Only the last column data is sent via WebSocket for TradingView. For example, when the time is 14:40:50, the minute data represents data between 14:40 and 14:41, and the hourly data represents data between 14:00 and 15:00. The data sent contains the UNIX timestamp value, which specifies the time zone for which the data belongs.
428 | TradingView | C | ||
A message sent from the server to the client. Contains the current candle data for the pair and resolution specified in the event. | ||||
type | number | Model type | ||
D | number | UNIX timestamp, in seconds. | ||
P | string | Pair. For example BTCTRY | ||
R | string | Resolution. For example 1W. | ||
O | Stringer | Open. The opening value of the data. | ||
H | Stringer | High. The highest value the data reaches. | ||
L | Stringer | Lower. The lowest value that the data reaches. | ||
C | Stringer | Close. The last value the data takes. (Ticker last) | ||
V | string | Volume. The total volume in the specified time. |
Communicating Directly with HTTP EndPoints
For use on browsers or platforms where WebSocket is not supported, it is also possible to access data sent via WebSocket with specific endpoints. Values returned to HTTP Requests sent to EndPoints are the last data fed by the BTC Trader socket server. For example, if the ticker data is updated on average every second, all requests sent within the same seconds will return the same result.
Order Book
There is one endpoint for each pair in the Order Book. The URL to which requests will be sent is as follows:
GET https://ws-feed-sandbox.btctrader.com/orderbook/{PAIR}
The format of the parameter Pair must be BTCTRY, ETHTRY, XRPUSDT. for example
https://ws-feed-sandbox.btctrader.com/orderbook/btctry
Sends the current BTC/TRY order book model.
The returned result is in JSON format of the model code OrderBookFull 431 specified in the above models.
Ticker
The ticker data consists of a single endpoint that returns ticker data for all pairs. Taken as follows. GET https://ws-feed-sandbox.btctrader.com/ticker/all The result returned is the Items variable of the code-named model TickerAll 401 in the above models. (Not the model itself) The following endpoint is available when you want to display a user-friendly HTML design version of the ticker data. GET https://ws-feed-sandbox.btctrader.com/ticker/html The following endpoint can only be used to receive ticker data for a particular pair. The following link is exemplified by BTCTRY. You can change the parameter here for other pair ticker data available in the system. GET https://ws-feed-sandbox.btctrader.com/ticker/pair/BTCTRY
Recent Actions
The last operations return the operations of a specified pair. The user can specify the last number of operations by parameter. The maximum number of records in the last transactions is 50. If a value greater than 50 is entered, the last 50 transactions will be sent again. The request for final transactions should be sent as follows.
GET https://ws-feed-sandbox.btctrader.com/trade/last/{PAIR{/{COUNT}
Pair should be entered as BTCTRY. Count value must be sent from 1 to 50 numerically. If Count is not sent, the default is 50. For example, requests are valid as follows. https://ws-feed-sandbox.btctrader.com/trade/last/btctry/10 https://ws-feed-sandbox.btctrader.com/trade/last/ethtry/76 https://ws-feed-sandbox.btctrader.com/trade/last/xrptry
Errors
Btcturk API uses the following error codes:
Error Code | Meaning |
---|---|
400 | Bad Request -- Your request is invalid. |
401 | Unauthorized -- Your Public/Private API key is wrong. |
429 | Too Many Requests -- You exceeded request rate limit. |
5xx | Internal Server Error -- We had a problem with our server. Try again later. |
503 | Service Unavailable -- We're temporarily offline for maintenance. Please try again later. |
Pairs Scale (Quantity/Price)
Pair | Quantity Scale | Price Scale |
---|---|---|
BTC/TRY | 8 | 0 |
EOS/TRY | 2 | 2 |
ETH/TRY | 8 | 0 |
LTC/TRY | 8 | 2 |
NEO/TRY | 4 | 2 |
USDT/TRY | 2 | 2 |
XLM/TRY | 4 | 4 |
XRP/TRY | 4 | 2 |
XTZ/TRY | 2 | 2 |
BTC/USDT | 8 | 0 |
EOS/USDT | 2 | 3 |
ETH/USDT | 8 | 1 |
LTC/USDT | 8 | 2 |
NEO/USDT | 4 | 2 |
XLM/USDT | 4 | 4 |
XRP/USDT | 4 | 4 |
EOS/BTC | 4 | 5 |
ETH/BTC | 8 | 8 |
LTC/BTC | 8 | 5 |
NEO/BTC | 8 | 5 |
XLM/BTC | 4 | 8 |
XRP/BTC | 4 | 8 |
- You can use https://api.btcturk.com/api/v2/server/exchangeinfo for all tradable pairs and their quantity or price scales and more.
FAQ
White label exchange API Frequently Asked Questions
The documentation for frequently asked questions of BTCTrader's white label exchange platform API.
Why do I receive 401 - Unauthorized error
You need to authorize before sending your request on all user related operations like buy/sell/cancel orders, user balances, open orders etc.
Please check and confirm that you've created the API key from PRO website. Also, check the API Key's permissions. If you don't have the necessary permissions, your requests will be unauthorized. Also if you had limited API with an IP address and your server has a different address, your API requests won't be authorized.
Why do I receive Invalid nonce error
Nonce is a regular integer number. It must be Unix Timestamp in milliseconds format. We do have a 5 seconds tolerance in timestamps within the requests but your server’s current time must be synced with the API server time which is in milliseconds format. Our servers are using UTC timezone.
You can check the server time from here
Why do I receive 502 - Not enough balance error
For TRY pairs, you need to calculate the commission and deduct from the total amount. For example, if you would like to order 1.00000000 BTC for 50,000TRY, your free balance must be at least 50,090TRY (Maker/Taker commissions are being calculated after your order executed. If your order matches immediately you'll be charged as Taker. Otherwise, you'll be charged as Maker and the commission difference will be added to your balance)
Why do I receive 429 - Too many requests
This means you exceeded the rate limit. Refer to Rate Limits section. Also please check the Retry-After response HTTP header. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After It indicates how long the user agent should wait before making a follow-up request.
What is the difference between API versions and which one is suitable for me
There are two versions v1 and v2.
V1 is used for all authentication required requests like checking balances, listing open orders, creating or canceling orders etc. with HMAC authentication.
V2 is used for all authentication required requests like checking balances, listing open orders, creating or canceling orders etc. with OAUTH2 authentication. V2 is also used for all public requests like ticker, OHLC (open, high, low, close) data, orderbook etc.
If you would like to request a data, related to your user account, you should use v1 with HMAC authentication or v2 with OAUTH2 authentication.
All public data is being served on v2.
401 Unauthorized - Invalid Signature
You might compute a wrong signature. You might not set the signature in the headers. You might use this signature before so the time is changed and therefore you cannot use it anymore. Please check your public/private keys are correct. You may need to encode the key as UTF-8 in some languages.
401 Unauthorized - Invalid Public/Private key
Your public or private keys are missing.
401 Unauthorized - Unauthorized - Headers are missing
Your request does not have requested headers.
401 Unauthorized - Invalid Request
Your current account could be unverified yet you should contact support. Your private key (API Secret) might be wrong. Please check your private key is correct. You may need to decode the key as base64 in some languages.
401 Unauthorized - Invalid Nonce
Nonce should not be different than the current timestamp we are giving a tolerance ±5 seconds.
Please check your server's timezone and timestamp output. It should be in milliseconds format and you need to declare your server's timezone to match UTC.
You can check the server time from here
Have more questions
If you have more questions please feel free to send your questions to issues section