Skip to main content

WEBSOCKET API Account Info - Get margin data

WEBSOCKET API Account Info - Get margin data

Written by Albert
Updated over a week ago

Connection

URL:

/frontoffice/ws/v3/account?access_token={YOUR_ACCESS_TOKEN}

arguments array

The connection parameters.

In the first element, provide the accountId as a string.

invocationId string

The invocation identifier.

Must be unique and increase by 1 for each sent message.

target string

The stream name.

Specify "MarginData".

type int

The operation type.

Set to 4 to indicate a subscription to the stream.

Example:

{
"arguments": [
"67d0456f8c7b1108e4cf5d46"
],
"invocationId": "0",
"target": "MarginData",
"type": 4
}

Message

type string

The operation type.

2 indicates the streaming is in progress.

invocationId string

The invocation identifier. Same as in the request.

item object

The dataset object.

item.marginBalanceInRAT decimal string

The total amount of funds that can be used as a collateral for trading, in RAT.

This value is calculated as SUM (TotalAmountX × MarginRatioX × Rate X/RAT)

Where:

  • TotalAmountX is the the total amount of the asset X, including both available and locked funds.

  • MarginRatioX is the Margin ratio set for the asset X.

  • Rate X/RAT is the constantly updated rate of the asset X to the BP root asset.

item.unrealizedPnlInRAT decimal string

The total potential profit or loss earned from all open positions.

This value is calculated as Σ(Unrealized PnL for Long positions + Unrealized PnL for Short positions), where:

  • Unrealized PnL for Long positions = Position size × (Current priceOpen price)

  • Unrealized PnL for Short positions = Position size × (Open priceCurrent price)

item.equityInRAT decimal string

The potential balance if all open positions were closed right now.

This value is calculated as Margin balance + Unrealized PnL.

item.usedMarginInRAT decimal string

The amount of funds that is used for maintaining all open positions. Is opposed to the Free margin.

The Used margin for positions on a specific market is calculated using the maximum value between the total margin of long positions and the total margin of short positions: MAX(MarketPositionLong, MarketPositionShort).

item.freeMarginInRAT decimal string

The amount of funds that can be used for opening new positions.

item.marginLevel decimal string

The ratio of funds to a used collateral, in percents.

This value is calculated as Equity / Used margin × 100%.

Example:

{
"type": 2,
"invocationId": "0",
"item": {
"marginBalanceInRAT": "497838.8",
"unrealizedPnlInRAT": "-5.25",
"equityInRAT": "497833.55",
"usedMarginInRAT": "100.18",
"freeMarginInRAT": "497733.37",
"marginLevel": "4969.3905"
}
}

Did this answer your question?