Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

How to Fetch Trading Account Balance using Amibroker

2 min read

Amibroker recently launched their Amibroker 6.4 version which comes with new Javascript engines with JSON native object support which is very much required to parse any JSON Strings. Most of the Trading API response is in JSON format this 6.4 upgrade will definitely bring more innovative features and code simplification in building intelligent execution strategies in the future.

Amibroker JSON Parsing – Tutorial using Algomojo API

Requirements

Amibroker 6.4 or higher version, Access to Algomojo API

Supported Brokers

Aliceblue, Tradejini, Zebu

Sample JSON Response for Limits API to fetch trading fund details

{
    "OpeningBalance": "30.52",
    "Netcashavailable": "31.52",
    "grossexposurevalue": "0.00",
    "segment": "ALL",
    "cncrealizedmtomprsnt": "-0.0",
    "valueindelivery": "0.00",
    "cncsellcreditpresent": "0.00",
    "cncunrealizedmtomprsnt": "-0.0",
    "deliverymarginprsnt": "0",
    "grossCollateral": "0",
    "BuyPower": "31.52",
    "PayoutAmt": "-0.00",
    "cncbrokerageprsnt": "0",
    "turnover": "0",
    "unrealisedmtom": "-0.00",
    "adhocscripmargin": "0.00",
    "specialmarginprsnt": "0",
    "BOmarginRequired": "0.00",
    "losslimit": "0",
    "IPOAmount": "-0.00",
    "elm": "0.00",
    "cdsspreadbenefit": "0.00",
    "realisedmtom": "-0.00",
    "category": "ONLINE",
    "nfospreadbenefit": "0.00",
    "Utilizedamount": "0.00",
    "exposuremargin": "0.00",
    "Adhoc": "1.00",
    "t1grossCollateral": "0",
    "directcollateralvalue": "0.000000",
    "StockValuation": "0.00",
    "credits": "31.52",
    "branchadhoc": "0.000000",
    "adhocmargin": "1.000000",
    "additionalmarginprsnt": "0",
    "spanmargin": "0.00",
    "premiumpresent": "0.00",
    "BookedPNL": "-0.00",
    "varmargin": "0.00",
    "marginScripBasketCustomPresent": "0",
    "tendermarginprsnt": "0",
    "cncmarginused": "0",
    "brokerageprsnt": "0",
    "UnbookedPNL": "-0.00",
    "debits": "0.00",
    "COMarginRequired": "0.00",
    "multiplier": "1.00",
    "stat": "Ok",
    "mfamount": "0.00",
    "scripbasketmargin": "0.00",
    "buyExposurePrsnt": "0",
    "notionalcash": "0",
    "additionalpreexpirymarginprsnt": "0",
    "cncMarginElmPrsnt": "0",
    "PayinAmt": "0.00",
    "cncMarginVarPrsnt": "0",
    "mfssamountused": "0.00",
    "sellExposurePrsnt": "0"
}

Amibroker AFL Codes for JSON Parsing Example to fetch Trading Account Balance.

//Parsing the Fund Balance using Algomojo API
_SECTION_BEGIN("JSON Parsing Example");

uid = ParamStr("Client ID","TS2499");
user_apikey = ParamStr("user_apikey","86cbef19e7e61ccee91e497690d5814e"); //Enter your API key here
api_secret = ParamStr("api_secret","eb4a0e79ff9e1bc8a05940cad8d2e94e"); //Enter your API secret key here
broker = ParamList("Broker","ab|tj|zb"); //Broker Short Code - ab - aliceblue, tj - tradejini, zb - zebu, en - enrich
ver = ParamStr("API Version","1.0");
trigger = ParamTrigger("Funds","Fetch Funds");

RequestTimedRefresh(1,False);

EnableScript("jscript");
<%
  function _Parse( json_string )
  {
	return JSON.parse( json_string );
  }
%>

function ParseJSON( json_string )
{
   script = GetScriptObject();
   return script._Parse( json_string );
}


function GetFunds()
{

algomojo=CreateObject("AMAMIBRIDGE.Main");
api_data ="{\"uid\":\""+uid+"\",\"actid\":\""+uid+"\",\"segment\":\""+"ALL"+"\",\"Exchange\":\""+""+"\",\"product\":\""+""+"\"}";
resp=algomojo.AMDispatcher(user_apikey, api_secret,"Limits",api_data,broker,ver);
_TRACE(" Account Balance Response  : " +resp);
return resp;
}



if(Now(4)%30==0)  //access funds every 30 seconds
{
obj = ParseJson(GetFunds());
StaticVarSetText("Balance",obj.OpeningBalance);
StaticVarSetText("Cash",obj.Netcashavailable);
StaticVarSetText("Turnover",obj.turnover);
_TRACE("Account Balance :"+StaticVarGetText("Balance"));
_TRACE("Cash Available :"+StaticVarGetText("Cash"));
_TRACE("Turnover :"+StaticVarGetText("Turnover"));
}

_SECTION_END();

Amibroker Log Output

Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

Virtual Trade Simulator Module Version 1.0 – Amibroker AFL…

Thought of launching a simple and user-friendly Virtual Trade Simulator to study/test your inner intuition before practicing in the live markets. Virtual Trade Simulator...
Rajandran R
3 min read

Clarification on Business Standard Article and False Allegations made…

This article clarifies the false allegations made on Marketcalls and Algomojo.
Rajandran R
1 min read

How to Fetch Trading Account Balance using Amibroker

Amibroker recently launched their Amibroker 6.4 version which comes with new Javascript engines with JSON native object support which is very much required to...
Rajandran R
2 min read

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More