Read Margins
Read live account margins for any supported broker account, in a broker independent format.
https://apix.stocksdeveloper.in/trading/readPlatformMargins Read Margins returns the live margin details for the trading account mapped to a pseudo account. The same call works across every client language and supported broker. Margins are grouped into equity, commodity and all, each with values such as funds, utilized, available, net, span, exposure and MTM. Cache the result and reuse it to stay within the rate limits.
This call reads margins from your trading platform. It returns data for the trading account linked to the pseudo account you pass in.
Margins are grouped into three categories: equity, commodity and all (the entire account). The same call is available across all supported brokers, so your code stays broker independent. See API functions for the full list.
Code samples
HTTP
Example
curl https://apix.stocksdeveloper.in/trading/readPlatformMargins \
-H "api-key: <your-api-key>" \
-d "pseudoAccount=ACC_NAME"The response is JSON, in the format shown under Response. Each margin carries the Margin fields listed below.
Python
Signature
def read_platform_margins(self, pseudo_account):Example
response = autotrader.read_platform_margins('XX1234')
if response.success():
# response.result is a list of PlatformMargin objects
for m in response.result:
print(m.category, m.funds, m.available)
else:
print("Message: {0}".format(response.message))response.result is a list of margin objects. Read each field with object.property notation. Each object exposes the Margin fields below.
Java
Signature
/**
* Read margins from the trading account mapped to the given pseudo account.
*
* @param pseudoAccount pseudo account id
* @return trading platform margins
*/
IOperationResponse<Set<PlatformMargin>>
readPlatformMargins(final String pseudoAccount);Example
IOperationResponse<Set<PlatformMargin>> response =
this.autotrader.readPlatformMargins("ACC_NAME");
Set<PlatformMargin> margins = null;
if (response.success()) {
margins = response.getResult();
}Use getResult() to get the set of margins. Each object exposes the Margin fields below through getters such as getAvailable().
C#
Signature
/// <summary>
/// Read margins from the trading account mapped to the given pseudo account.
/// </summary>
/// <param name="pseudoAccount"> pseudo account id </param>
/// <returns> trading platform margins </returns>
IOperationResponse<ISet<PlatformMargin>> ReadPlatformMargins(
string pseudoAccount);Example
IOperationResponse<ISet<PlatformMargin>> response =
autoTrader.ReadPlatformMargins("XX1234");
foreach (PlatformMargin p in response.Result)
Console.WriteLine("{0}", p);Use the Result property to get the set of margins. Each object exposes the Margin fields below as properties such as Available.
Excel
Signature
Excel exposes one function per field and category. They all take the same arguments:
Public Function GetMarginAvailable(pseudoAccount As String, _
category As String) As DoubleEvery field in Margin fields has a matching GetMargin<Field> function (for example GetMarginFundsEquity, GetMarginAvailableAll).
AmiBroker
Signature
AmiBroker exposes one function per field and category. They all take the same arguments:
function getMarginAvailableEquity(pseudoAccount)Example
fundsEquity = getMarginFundsEquity(AT_ACCOUNT);
availableAll = getMarginAvailableAll(AT_ACCOUNT);Every field in Margin fields has a matching getMargin<Field> function.
MetaTrader
Signature
MetaTrader exposes one function per field and category. They all take the same arguments:
double getMarginAvailableEquity(string pseudoAccount)Example
double fundsEquity = getMarginFundsEquity(AT_ACCOUNT);
double availableAll = getMarginAvailableAll(AT_ACCOUNT);Every field in Margin fields has a matching getMargin<Field> function.
Postman
Postman is a widely used tool for API testing. We provide a collection of all our APIs in Postman collection format. See the Postman collection guide to learn how to use it.
Response
The call returns an array of margins in JSON, one record per category, sourced from your trading platform.
{
"result":[
{
"category":"ALL",
"funds":944.16,
"utilized":0.05,
"available":944.11,
"day":[2020,7,2],
"pseudoAccount":"XX9999",
"tradingAccount":"XX9999",
"stockBroker":"YOUR_BROKER"
},
{
"category":"EQUITY",
"funds":944.16,
"utilized":0.05,
"available":944.11,
"day":[2020,7,2],
"pseudoAccount":"XX9999",
"tradingAccount":"XX9999",
"stockBroker":"YOUR_BROKER"
}
],
"message":null,
"status":true,
"commandId":"e7f67fa1-d696-4aed-bd3c-dd6f44e526ef"
}
status is true on success. On error it is false, and message holds the error text.
Margin fields
Each margin carries the fields below. They are the same across every language: object properties (Python/Java/C#) or a getMargin<Field> function (Excel/AmiBroker/MetaTrader), and JSON keys over HTTP.
| Field | Type | Description |
|---|---|---|
pseudoAccount | string | The pseudo account the margin belongs to. |
tradingAccount | string | The mapped trading account id. |
stockBroker | string | The stock broker for this account. |
category | enum | Margin category (EQUITY, COMMODITY, ALL). |
funds | float | Total funds. |
utilized | float | Utilized margin. |
available | float | Available margin. |
total | float | Total margin. |
net | float | Net margin. |
span | float | Span margin. |
exposure | float | Exposure margin. |
collateral | float | Collateral margin. |
payin | float | Payin amount. |
payout | float | Payout amount. |
adhoc | float | Adhoc margin. |
realisedMtm | float | Realised mark to market. |
unrealisedMtm | float | Unrealised mark to market. |
day | date | Margin date. |
Notes
It is recommended to download and cache margins periodically, then look up the cached set, to avoid hitting the API rate limits.
Not every field is available from every broker (see limitations). In those cases the value may be empty or zero. If you notice any issue, please let us know.
Thanks for the feedback. Still stuck? Contact support.
Last updated 20 June 2026