WebSocket API
Overview
In general, there are 2 ways of delivering the data to the user within B2TRADER Platform:
REST API (for synchronous data transferring)
WebSocket API (for real-time data transferring)
A WebSocket message is a payload sent from Backend to the Frontend in order to deliver real-time updates. WebSocket messages are sent by AspNetCore SignalR.
SignalR library
SignalR is a tool used for organizing and transmitting WebSocket messages. It provides a clear, uniform structure for these messages, and the data transfer is divided into two parts:
Connection establishment
Data streaming
SignalR utilizes type
as indication of an operation:
type: 4 — subscribe to streaming
type: 5 — unsubscribe from streaming
type: 3 — confirmation of unsubscribing
type: 2 — streaming in progress
Stream types
Trading:
Get Open Orders
Get Open Positions
Get Closed Positions
Market Data:
Get Order Book
Get Trading Data
Get Top of the Book
Get Trading Chart
Get Market Summary
Account info:
Full Balance
Margin Data
Get Open Orders
Connection
/frontoffice/ws/v4/account?access_token={traderToken}
{
"arguments": [
"67d0456f8c7b1108e4cf5d46"
],
"invocationId": "0",
"target": "OpenOrders",
"type": 4
}
arguments
string
Connection parameters.
The first element is always accountId
invocationId
string
Invocation ID
target
string
Stream type
type
int
Set to 4
to indicate the StreamInvocation
Message
{
"type": 2,
"invocationId": "0",
"item": [
{
"marketId": "cfd.eur_chf",
"marketType": "Cfd",
"marketDisplayName": "EUR/CHF",
"marketFullName": "",
"orderId": "01JVQBFSTVC40VK03A0AY7K016",
"timeInForce": "Gtc",
"status": "Pending",
"source": "Manual",
"reason": "Trader",
"side": "Buy",
"orderType": "Limit",
"requestedAmount": "10000",
"remainingAmount": "10000",
"requestedPrice": "0.9",
"executionPrice": "0",
"createdAt": "2025-05-20T17:22:31.899Z",
"updatedAt": "2025-05-20T17:22:31.9001213Z",
"cancellationDate": null,
"commissionAssetId": "eur",
"commissionAmount": "0",
"leverage": 1,
"fillFactor": "0",
"takeProfit": null,
"stopLoss": null
}
]
}
type
int
Type
invocationId
string
Invocation ID
item
array
Item array
marketId
string
Market ID
marketType
string
Market Type
marketDisplayName
string
Market Display Name
marketFullName
string
Market Full Name
orderId
string
Order ID
timeInForce
string
Time-In-Force
status
string
Order Status
source
string
Source
reason
string
Reason
side
string
Order Side
orderType
string
Order Type
requestedAmount
decimal string
Requested Amount
remainingAmount
decimal string
Remaining Amount
requestedPrice
decimal string
Requested Price
executionPrice
decimal string
Execution Price
createdAt
dateTime
Created At
updatedAt
dateTime
Updated At
cancellationDate
dateTime
Cancellation Date
commissionAssetId
string
Commission Asset Id
commissionAmount
decimal string
Commission Amount
leverage
int
Order Leverage
fillFactor
decimal string
Fill Factor
takeProfit
decimal string
Take Profit Price
stopLoss
decimal string
Stop Loss Price
Get Open Positions
Connection
/frontoffice/ws/v4/account?access_token={traderToken}
{
"arguments": [
"67d0456f8c7b1108e4cf5d46"
],
"invocationId": "0",
"target": "OpenPositions",
"type": 4
}
arguments
string
Connection parameters.
The first element is always accountId
invocationId
string
Invocation ID
target
string
Stream type
type
int
Set to 4
to indicate the StreamInvocation
Message
{
"type": 2,
"invocationId": "0",
"item": {
"item": [
{
"positionId": "01JP4H3AMS7Q1H6Y6H3XJ52JTA",
"marketId": "cfd.eur_chf",
"marketType": "Cfd",
"marketDisplayName": "EUR/CHF",
"marketFullName": "",
"createdAt": "2025-03-12T06:36:31.257Z",
"updatedAt": "2025-03-12T06:36:31.257Z",
"side": "Buy",
"status": "Open",
"leverage": 1,
"positionLotAmount": "0.01",
"positionPriceInRAT": "1000.46",
"rateToRAT": "1.07",
"usedMarginInRAT": "1000.53",
"openPrice": "0.96304",
"currentMarketPrice": "0.93501",
"unrealizedPnlDayInRAT": "1.86",
"unrealizedPnlDayPercent": "0.0018",
"unrealizedPnlTotalInRAT": "-29.93",
"unrealizedPnlTotalPercent": "-0.0291",
"takeProfit": null,
"stopLoss": null,
"positionModifier": "Trader"
},
{
"positionId": "01JVQB9ZWJ6G4QV0P98X0QWNA7",
"marketId": "cfd.eur_chf",
"marketType": "Cfd",
"marketDisplayName": "EUR/CHF",
"marketFullName": "",
"createdAt": "2025-05-20T17:19:21.49Z",
"updatedAt": "2025-05-20T17:19:21.491321Z",
"side": "Buy",
"status": "Open",
"leverage": 100,
"positionLotAmount": "0.1",
"positionPriceInRAT": "10004.6",
"rateToRAT": "1.07",
"usedMarginInRAT": "100.06",
"openPrice": "0.93666",
"currentMarketPrice": "0.93501",
"unrealizedPnlDayInRAT": "18.61",
"unrealizedPnlDayPercent": "0.0018",
"unrealizedPnlTotalInRAT": "-17.02",
"unrealizedPnlTotalPercent": "-0.0017",
"takeProfit": null,
"stopLoss": null,
"positionModifier": "Trader"
}
],
"snapshot": false
}
}
type
int
Type
invocationId
string
Invocation ID
item
array
Item array
positionId
string
Position Id
marketId
string
Market ID
marketType
string
Market Type
marketDisplayName
string
Market Display Name
marketFullName
string
Market Full Name
createdAt
dateTime
Created At
updatedAt
dateTime
Updated At
side
string
Order Side
status
string
Order Status
leverage
int
Order Leverage
positionLotAmount
decimal string
Position Amount, Lots
positionPriceInRAT
decimal string
RAT Notional
rateToRAT
decimal string
Rate To RAT
usedMarginInRAT
decimal string
Used Margin, RAT
openPrice
decimal string
Position Open Price
currentMarketPrice
decimal string
Current Market Price
unrealizedPnlDayInRAT
decimal string
Unrealized Pnl Day, RAT
unrealizedPnlDayPercent
decimal string
Unrealized Pnl Day, %
unrealizedPnlTotalInRAT
decimal string
Unrealized Pnl Total, RAT
unrealizedPnlTotalPercent
decimal string
Unrealized Pnl Total, %
takeProfit
decimal string
Take Profit Price
stopLoss
decimal string
Stop Loss Price
positionModifier
string
Position Modifier
snapshot
boolean
Data snapshot.
If snapshot: true
, it indicates the message contains the full dataset. Subsequent messages with snapshot: false
only include updates or changes since the initial snapshot.
Get Closed Positions
Connection
/frontoffice/ws/v4/account?access_token={traderToken}
{
"arguments": [
"67d0456f8c7b1108e4cf5d46"
],
"invocationId": "0",
"target": "ClosePositionsOrders",
"type": 4
}
arguments
string
Connection parameters.
The first element is always accountId
invocationId
string
Invocation ID
target
string
Stream type
type
int
Set to 4
to indicate the StreamInvocation
Message
{
"type": 2,
"invocationId": "0",
"item": [
{
"marketId": "cfd.eur_chf",
"marketFullName": "",
"marketDisplayName": "EUR/CHF",
"marketType": "Cfd",
"orderId": "01JVSQ8WFA3QZ6AQTKYPXVXDWA",
"orderType": "Market",
"timeInForce": "Ioc",
"side": "Sell",
"positionCloseLotAmount": "0.01",
"reason": "Trader",
"realizedPnlInRAT": "-29.25",
"closedAt": "2025-05-21T15:26:57.0027785Z",
"positionId": "01JP4H3AMS7Q1H6Y6H3XJ52JTA",
"openPrice": "0.96304",
"closePrice": "0.93571",
"positionPriceInRAT": "1001.2",
"rateToRAT": "1.07",
"openedAt": "2025-03-12T06:36:31.257Z"
}
]
}
type
int
Type
invocationId
string
Invocation ID
item
array
Item array
marketId
string
Market ID
marketFullName
string
Market Full Name
marketDisplayName
string
Market Display Name
marketType
string
Market Type
orderId
string
Order ID
orderType
string
Order Type
timeInForce
string
Time-In-Force
side
string
Order Side
positionCloseLotAmount
string
Position Close Amount, Lots
reason
string
Reason
realizedPnlInRAT
string
Realized PnL, RAT
closedAt
dateTime
Closed At
positionId
string
Position Id
openPrice
string
Position Open Price
closePrice
string
Position Close Price
positionPriceInRAT
string
RAT Notional
rateToRAT
string
Rate To RAT
openedAt
dateTime
Opened At
Get Order Book
Connection
/marketdata/v5/info?access_token={traderToken}
{
"arguments": [
"67d0456f8c7b1108e4cf5d46",
"cfd.eur_chf"
],
"invocationId": "0",
"target": "Book",
"type": 4
}
arguments
string
Connection parameters.
The first element is always accountId
.
The second element is marketId
.
invocationId
string
Invocation ID
target
string
Stream type
type
int
Set to 4
to indicate the StreamInvocation
Message
{
"type": 2,
"invocationId": "0",
"item": {
"instrument": "cfd.eur_chf",
"askTotalAmount": "18700000",
"bidTotalAmount": "19100000",
"asks": [
{
"price": "0.93677",
"amount": "5000000",
"total": "4683850"
},
{
"price": "0.93676",
"amount": "0",
"total": "0"
},
{
"price": "0.93676",
"amount": "0",
"total": "0"
}
],
"bids": [
{
"price": "0.93654",
"amount": "0",
"total": "0"
},
{
"price": "0.93654",
"amount": "0",
"total": "0"
},
{
"price": "0.93655",
"amount": "5000000",
"total": "4682750"
}
],
"version": "12498",
"snapshot": false
}
}
type
int
Type
invocationId
string
Invocation ID
item
object
Item object
instrument
string
Market ID
askTotalAmount
string
Asks total amount
bidTotalAmount
string
Bids total amount
asks
array
Asks array
bids
array
Bids array
price
string
Price of relevant item
amount
string
Amount of relevant item
total
string
Total of relevant item
version
string
Version
snapshot
boolean
Data snapshot.
If snapshot: true
, it indicates the message contains the full dataset. Subsequent messages with snapshot: false
only include updates or changes since the initial snapshot.
Get Trading Data
Widget Market Summary
Connection
/marketdata/v5/info?access_token={traderToken}
{
"arguments": [
"67d0456f8c7b1108e4cf5d46",
[
"spot.bnb_btc"
]
],
"invocationId": "0",
"target": "TradingData",
"type": 4
}
arguments
string
Connection parameters.
The first element is always accountId
.
The second element is an array of marketIds
.
invocationId
string
Invocation ID
target
string
Stream type
type
int
Set to 4
to indicate the StreamInvocation
Message
{
"type": 2,
"invocationId": "0",
"item": {
"markets": [
{
"marketId": "cfd.eur_chf",
"type": "Cfd",
"displayName": "cfd.eur_chf",
"fullName": "",
"price": "0.93586",
"priceInRAT": "1",
"priceChange24hr": "-0.0006",
"priceChangeAbs24hr": "-0.00049",
"highPrice24hr": "0.93695",
"lowPrice24hr": "0.93134",
"markPrice": null,
"fundingRate": null
}
],
"snapshot": false
}
}
type
int
Type
invocationId
string
Invocation ID
item
object
Item object
marketId
string
Market ID
type
string
Market type
displayName
string
Market Display Name
fullName
string
Market Full Name
price
decimal string
Price
priceInRAT
decimal string
Price, RAT
priceChange24hr
decimal string
Price change per last 24 hours
priceChangeAbs24hr
decimal string
Price change per last 24 hours, asset amount
highPrice24hr
decimal string
Highest price per last 24 hours
lowPrice24hr
decimal string
Lowest price per last 24 hours
markPrice
decimal string
Mark Price
fundingRate
decimal string
Funding Rate
Get Top of the Book
Connection
/marketdata/v5/info?access_token={traderToken}
{
"arguments": [
"67d0456f8c7b1108e4cf5d46",
[
"spot.eth_usdt"
]
],
"invocationId": "0",
"target": "Tob",
"type": 4
}
arguments
string
Connection parameters.
The first element is always accountId
.
The second element is an array of marketIds
.
invocationId
string
Invocation ID
target
string
Stream type
type
int
Set to 4
to indicate the StreamInvocation
Message
{
"type": 2,
"invocationId": "0",
"item": {
"markets": [
{
"marketId": "spot.eth_usdt",
"ask": "2483.82",
"bid": "2483.81"
}
],
"snapshot": false
}
}
type
int
Type
invocationId
string
Invocation ID
item
object
Item object
markets
array
Markets
marketId
string
Market ID
ask
decimal string
Ask Price
bid
decimal string
Bid Price
Get Trading Chart
Connection
/marketdata/v5/info?access_token={traderToken}
{
"arguments": [
"67d0456f8c7b1108e4cf5d46",
"cfd.eth_eur@15m"
],
"invocationId": "0",
"target": "Chart",
"type": 4
}
arguments
string
Connection parameters.
The first element is always accountId
.
The second element is marketId
and timescale
.
invocationId
string
Invocation ID
target
string
Stream type
type
int
Set to 4
to indicate the StreamInvocation
Message
{
"type": 2,
"invocationId": "0",
"item": {
"instrument": "cfd.eth_eur",
"low": "2240.88",
"high": "2270.29",
"open": "2265.63",
"close": "2255.99",
"start": "2025-05-21T15:30:00Z",
"end": "2025-05-21T15:45:00Z"
}
}
type
int
Type
invocationId
string
Invocation ID
item
object
Item object
instrument
string
Market ID
low
decimal string
Lowest Price
high
decimal string
Highest Price
open
decimal string
Open Price
close
decimal string
Close Price
start
dateTime
Start timestamp
end
dateTime
End timestamp
Get Summary
Widget Watchlist
Connection
/marketdata/v5/info?access_token={traderToken}
{
"arguments": [
"67d0456f8c7b1108e4cf5d46",
[
"cfd.eur_chf"
]
],
"invocationId": "0",
"target": "Summary",
"type": 4
}
arguments
string
Connection parameters.
The first element is always accountId
.
The second element is an array of marketIds
.
invocationId
string
Invocation ID
target
string
Stream type
type
int
Set to 4
to indicate the StreamInvocation
Message
{
"type": 2,
"invocationId": "0",
"item": {
"items": [
{
"marketId": "cfd.eur_chf",
"last": "0.93597",
"high24hr": "0.93695",
"low24hr": "0.93134",
"percentChange": "-0.02"
}
],
"snapshot": false
}
}
type
int
Type
invocationId
string
Invocation ID
item
object
Item object
marketId
string
Market ID
last
decimal string
Last Market Price
high24hr
decimal string
Highest Market Price per last 24 hours
low24hr
decimal string
Lowest Market Price per last 24 hours
percentChange
decimal string
Percent Change
snapshot
boolean
Data snapshot.
If snapshot: true
, it indicates the message contains the full dataset. Subsequent messages with snapshot: false
only include updates or changes since the initial snapshot.
Full Balance
Connection
/frontoffice/ws/v3/account?access_token={traderToken}
{
"arguments": [
"67d0456f8c7b1108e4cf5d46"
],
"invocationId": "0",
"target": "FullBalance",
"type": 4
}
arguments
string
Connection parameters.
The first element is always accountId
.
invocationId
string
Invocation ID
target
string
Stream type
type
int
Set to 4
to indicate the StreamInvocation
Message
{
"type": 2,
"invocationId": "0",
"item": [
{
"assetId": "eur",
"available": "497838.8",
"total": "497838.8",
"locked": "0"
}
]
}
type
int
Type
invocationId
string
Invocation ID
item
array
Item array
assetId
string
Balance Asset Id
available
decimal string
Available Asset Balance
total
decimal string
Total Asset Balance
locked
decimal string
Locked Asset Balance
Margin Data
Connection
/frontoffice/ws/v3/account?access_token={traderToken}
{
"arguments": [
"67d0456f8c7b1108e4cf5d46"
],
"invocationId": "0",
"target": "MarginData",
"type": 4
}
arguments
string
Connection parameters.
The first element is always accountId
.
invocationId
string
Invocation ID
target
string
Stream type
type
int
Set to 4
to indicate the StreamInvocation
Message
{
"type": 2,
"invocationId": "0",
"item": {
"marginBalanceInRAT": "497838.8",
"unrealizedPnlInRAT": "-5.25",
"equityInRAT": "497833.55",
"usedMarginInRAT": "100.18",
"freeMarginInRAT": "497733.37",
"marginLevel": "4969.3905"
}
}
type
int
Type
invocationId
string
Invocation ID
item
object
Item object
marginBalanceInRAT
decimal string
Margin Balance, RAT
unrealizedPnlInRAT
decimal string
Unrealized PnL, RAT
equityInRAT
decimal string
Equity, RAT
usedMarginInRAT
decimal string
Used Margin, RAT
freeMarginInRAT
decimal string
Free Margin, RAT
marginLevel
decimal string
Margin Level
Last updated
Was this helpful?