Quantcast
Channel: Market Calls
Viewing all articles
Browse latest Browse all 2070

How to Fetch Trading Account Balance using Amibroker

$
0
0

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

The post How to Fetch Trading Account Balance using Amibroker appeared first on Marketcalls.


Viewing all articles
Browse latest Browse all 2070

Trending Articles