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.
C#
Python
GoLang
Node.js
static async Task Main(string[] args)
{
await WebsocketConnection();
}
private static string message = "[151,{\"type\":151,\"channel\":\"CHANNEL_NAME_HERE\",event:\"EVENT_NAME_HERE\",\"join\":true}]";
private static async Task WebsocketConnection()
{
ClientWebSocket client = new ClientWebSocket();
Uri _uri = new Uri("wss://ws-feed-sandbox.btctrader.com");
await client.ConnectAsync(_uri, CancellationToken.None);
await SendSocketMessage(client, _orderBookFull);
}
private static async Task SendSocketMessage(ClientWebSocket client, string msg)
{
await client.SendAsync(buffer: new ArraySegment<byte>(array: Encoding.UTF8.GetBytes(msg),
offset: 0,
count: msg.Length),
messageType: WebSocketMessageType.Text,
endOfMessage: true,
cancellationToken: CancellationToken.None);
var buffer = new byte[1024 * 20];
while (true)
{
WebSocketReceiveResult result = await client.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
string resultMessage = Encoding.UTF8.GetString(buffer, 0, result.Count);
Console.WriteLine(resultMessage);
}
}
import json
import pprint
import time
import websocket
try:
import thread
except ImportError:
import _thread as thread
def on_message(ws, message):
data = json.loads(message)
pprint.pprint(data)
def on_error(ws, error):
print(error)
def on_close(ws):
print("### closed ###")
def on_open(ws):
def run(*args):
time.sleep(1)
message = [
151,
{
"type": 151,
"channel": 'CHANNEL_NAME_HERE',
"event": 'EVENT_NAME_HERE',
"join": True
}
]
ws.send(json.dumps(message))
thread.start_new_thread(run, ())
if __name__ == "__main__":
websocket.enableTrace(True)
ws = websocket.WebSocketApp(
"wss://ws-feed-pro.btcturk.com/",
on_message=on_message,
on_error=on_error,
on_close=on_close)
ws.on_open = on_open
ws.run_forever()
package main
import (
"flag"
"github.com/gorilla/websocket"
"log"
"net/url"
)
var addr = flag.String("addr", "ws-feed-pro.btcturk.com", "BtcTurk Websocket Feed")
func main() {
u := url.URL{Scheme: "wss", Host: *addr, Path: "/"}
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
if err != nil {
log.Fatal("Dial Error:", err)
}
message := []byte(`[151, {
"type":151,
"channel":"CHANNEL_NAME_HERE",
"event": "EVENT_NAME_HERE",
"join":true}]`)
err = c.WriteMessage(websocket.TextMessage, message)
if err != nil {
log.Println("ERROR:", err)
return
}
for {
messageType, p, err := c.ReadMessage()
if err != nil {
log.Println(err)
return
}
log.Println(string(p))
if err = c.WriteMessage(messageType, p); err != nil {
log.Println(err)
return
}
}
}
const WebSocket = require('ws')
const url = 'wss://ws-feed-pro.btcturk.com/'
const connection = new WebSocket(url)
const message = `[151,{"type":151,"channel":"CHANNEL_NAME_HERE","event":"EVENT_NAME_HERE","join":true}]`
connection.onopen = () => {
connection.send(message)
}
connection.onerror = (error) => {
console.log(`WebSocket error: ${error}`)
}
connection.onmessage = (e) => {
console.log(e.data)
}
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.
100 | Result | P |
---|---|---|
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. |
Extra requests sent to the server. For example, the Request model is sent when the last operations list is requested again.
101 | Request | P |
---|---|---|
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. |
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.
[151,{"type":151,"channel":"CHANNEL_NAME","event":"PAIRSYMBOL","join":true}]
151 | Subscription | P |
type | number | Model type |
channel | string | The name of the channel. For example; trade, orderbook, ticker etc. |
event | string | Event names are often used as “all” or upper-case as pair name (eg BTCTRY, ETHTRY). |
join | boolean |
|
A message sent from the server to the client. It is the model of all ticker data belonging to all Pairs.
[151,{"type":151,"channel":"ticker","event":"all","join":true}]
401 | TickerAll | C |
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. |
A message sent from the server to the client. It is only a model of all ticker data for a particular Pair.
[151,{"type":151,"channel":"ticker","event":"BTCTRY","join":true}]
402 | TickerPair | P |
type | number | Model type |
PS | string | Pair Symbol. For example; BTCTRY |
H | string | Highest price in the last 24 hours(high). |
L | string | The lowest price in the last 24 hours(low). |
La | string | The price of the last transaction(last). |
V | string | Volume. |
AV | string | Average price. |
D | string | 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. |
O | number | Open. Price of the first transaction of the day. |
B | string | Bid. Best buy order price. |
A | string | Ask. Best selling order price. |
BA | string | BidAmount. Best bid order amount. |
AA | string | AskAmount. Best ask order amount. |
DP | string | Daily percent. 24-hour change rate. |
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.
[151,{"type":151,"channel":"trade","event":"BTCTRY","join":true}]
422 | TradeSingle | P |
type | number | Model type |
PS | number | Pair Symbol. For example; BTCTRY. |
A | string | The amount of the transaction (Amount). |
S | number | Trade Side. Shows the side of the order.
|
D | number | Transaction date (Date). UnixTime is the value in milliseconds. |
P | string | The price at which the transaction was made (Price). |
I | string | The unique number of the transaction. (Uniqueness is valid only in its own pair) |
A message sent from the server to the client. It is the entire order book model of a particular Pair.
[151,{"type":151,"channel":"orderbook","event":"BTCTRY","join":true}]
431 | OrderBookFull | P |
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. |
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.
Changing process is:
- CP: Orders are transaction type.
- 0: Updated
- 1: New added
- 3: Deleted
- P: Order price value.
- A: Orders is the quantity.
[151,{"type":151,"channel":"obdiff","event":"BTCTRY","join":true}]
432 | OrderBookDifference | P |
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 |
CP | number | Changing Process of pair |
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. |
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.When a request is made with a HMAC Authentication, user login response is received from channel 114.
114 | UserLoginResult | P |
A message sent from the server to the client. Socket message of
user/transactions/trade
endpoint. When user's order match, message is sent to the client.423 | UserTrade | U |
---|---|---|
type | number | Model Type |
id | number | Id of the trade. |
orderId | number | Order id of the trade. |
timestamp | number | Server time of the order |
numeratorSymbol | string | Numerator Symbol. For example for BTCTRY, it is BTC |
denominatorSymbol | string | Denominator Symbol. For example for BTCTRY, it is TRY |
amount | string | Amount of the trade. |
fee | string | Fee amount of the trade. |
tax | string | Tax amount of the trade. |
price | string | Price of the trade. |
orderType | string | This field indicates if it is a buy order or a sell order. |
orderClientId | string | Client Id of the order |
preciseAmount | number | Precise amount of the trade. |
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.
441 | UserOrderMatch | U |
type | number | Model type |
id | number | Id value of the model being processed. |
user | number | The id of the user being processed. |
isBid | boolean | True if the transaction is buying or false if the transaction is selling. |
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 |
amount | string | The amount of the transaction. |
price | string | The price at which the transaction occurred. |
clientId | string | ClientId of the order |
timestamp | date | Server time of the order |
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.
451 | orderınsert | U |
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 |
numLeft | number | total crypto amount |
denomLeft | number | total order amount (TRY, USDT, BTC) |
newOrderClientId | string | ClientId of the order |
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.
452 | OrderDelete | 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.
453 | OrderUpdate | U |
Last modified 9mo ago