{"id":189,"date":"2021-03-02T10:41:09","date_gmt":"2021-03-02T10:41:09","guid":{"rendered":"https:\/\/algomojo.com\/blog\/?p=189"},"modified":"2025-02-27T07:45:11","modified_gmt":"2025-02-27T07:45:11","slug":"how-to-use-amibroker-to-parsing-the-position-book-in-algomojo-trading-platform","status":"publish","type":"post","link":"https:\/\/algomojo.com\/blog\/how-to-use-amibroker-to-parsing-the-position-book-in-algomojo-trading-platform\/","title":{"rendered":"How to use Amibroker to Parsing the Position Book in Algomojo Trading Platform"},"content":{"rendered":"\n<p>This is a simple tutorial that explains how to access the position book using Amibroker and get various details about the position book details to use further in your trading system.<\/p>\n\n\n\n<p><strong>Supported Brokers<\/strong> : Aliceblue, Tradejini, Zebu<\/p>\n\n\n\n<p><strong>What are the parameters one can get from Position Book?<\/strong><\/p>\n\n\n\n<p>From the Position Book one can get various details about the open positions. However here are some of the most important and most common extracted information from the position book by automated traders.<\/p>\n\n\n\n<p>1.<strong>unrealisedprofitloss<\/strong><br>2.<strong>realisedprofitloss<\/strong><br>3.<strong>Exchange<\/strong><br>4.<strong>Netqty<\/strong><br>5.<strong>Buyavgprc<\/strong><br>6.<strong>Sellavgprc<\/strong><br>7.<strong>MtoM<\/strong><br>8.<strong><strong>Company Name<\/strong><\/strong><\/p>\n\n\n\n<p><strong>Sample PositionBook Response<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-json\">[\n    {\n        &quot;Fillsellqty&quot;: &quot;0&quot;,\n        &quot;realisedprofitloss&quot;: &quot;0.00&quot;,\n        &quot;NetSellavgprc&quot;: &quot;0.00&quot;,\n        &quot;Opttype&quot;: &quot;XX&quot;,\n        &quot;Exchangeseg&quot;: &quot;nse_cm&quot;,\n        &quot;Netqty&quot;: &quot;3&quot;,\n        &quot;CFBuyavgprc&quot;: &quot;0.00&quot;,\n        &quot;sSqrflg&quot;: &quot;Y&quot;,\n        &quot;netbuyamt&quot;: &quot;824.55&quot;,\n        &quot;Tsym&quot;: &quot;EIHAHOTELS-EQ&quot;,\n        &quot;Netamt&quot;: &quot;-824.55&quot;,\n        &quot;netsellqty&quot;: &quot;0&quot;,\n        &quot;Sqty&quot;: &quot;0&quot;,\n        &quot;FillsellamtCF&quot;: &quot;0.00&quot;,\n        &quot;NetBuyavgprc&quot;: &quot;274.85&quot;,\n        &quot;MtoM&quot;: &quot;16.20&quot;,\n        &quot;Symbol&quot;: &quot;EIHAHOTELS&quot;,\n        &quot;posflag&quot;: &quot;true&quot;,\n        &quot;Series&quot;: &quot;EQ&quot;,\n        &quot;netSellamt&quot;: &quot;0.00&quot;,\n        &quot;Fillbuyamt&quot;: &quot;824.55&quot;,\n        &quot;unrealisedprofitloss&quot;: &quot;16.20&quot;,\n        &quot;PriceNumerator&quot;: &quot;1&quot;,\n        &quot;Type&quot;: &quot;DAY1&quot;,\n        &quot;netbuyqty&quot;: &quot;3&quot;,\n        &quot;BLQty&quot;: 1,\n        &quot;Fillbuyqty&quot;: &quot;3&quot;,\n        &quot;CFsellqty&quot;: &quot;0&quot;,\n        &quot;s_NetQtyPosConv&quot;: &quot;N&quot;,\n        &quot;CFbuyqty&quot;: &quot;0&quot;,\n        &quot;Sellavgprc&quot;: &quot;0.00&quot;,\n        &quot;Bqty&quot;: &quot;3&quot;,\n        &quot;Exchange&quot;: &quot;NSE&quot;,\n        &quot;CFSellavgprc&quot;: &quot;0.00&quot;,\n        &quot;Fillsellamt&quot;: &quot;0.00&quot;,\n        &quot;actid&quot;: &quot;TS2499&quot;,\n        &quot;GeneralDenomenator&quot;: &quot;1&quot;,\n        &quot;Instname&quot;: &quot;NA&quot;,\n        &quot;discQty&quot;: &quot;10&quot;,\n        &quot;Expdate&quot;: &quot;NA&quot;,\n        &quot;LTP&quot;: &quot;280.25&quot;,\n        &quot;Buyavgprc&quot;: &quot;274.85&quot;,\n        &quot;Token&quot;: &quot;15399&quot;,\n        &quot;GeneralNumerator&quot;: &quot;1&quot;,\n        &quot;companyname&quot;: &quot;EIH ASSOCIATED HOTELS LTD&quot;,\n        &quot;stat&quot;: &quot;Ok&quot;,\n        &quot;PriceDenomenator&quot;: &quot;1&quot;,\n        &quot;FillbuyamtCF&quot;: &quot;0.00&quot;,\n        &quot;Stikeprc&quot;: &quot;0&quot;,\n        &quot;BEP&quot;: &quot;274.85&quot;,\n        &quot;Pcode&quot;: &quot;MIS&quot;\n    },\n    {\n        &quot;Fillsellqty&quot;: &quot;1&quot;,\n        &quot;realisedprofitloss&quot;: &quot;0.00&quot;,\n        &quot;NetSellavgprc&quot;: &quot;106.60&quot;,\n        &quot;Opttype&quot;: &quot;XX&quot;,\n        &quot;Exchangeseg&quot;: &quot;nse_cm&quot;,\n        &quot;Netqty&quot;: &quot;-1&quot;,\n        &quot;CFBuyavgprc&quot;: &quot;0.00&quot;,\n        &quot;sSqrflg&quot;: &quot;Y&quot;,\n        &quot;netbuyamt&quot;: &quot;0.00&quot;,\n        &quot;Tsym&quot;: &quot;L&amp;TFH-EQ&quot;,\n        &quot;Netamt&quot;: &quot;106.60&quot;,\n        &quot;netsellqty&quot;: &quot;1&quot;,\n        &quot;Sqty&quot;: &quot;1&quot;,\n        &quot;FillsellamtCF&quot;: &quot;0.00&quot;,\n        &quot;NetBuyavgprc&quot;: &quot;0.00&quot;,\n        &quot;MtoM&quot;: &quot;-0.30&quot;,\n        &quot;Symbol&quot;: &quot;L&amp;TFH&quot;,\n        &quot;posflag&quot;: &quot;true&quot;,\n        &quot;Series&quot;: &quot;EQ&quot;,\n        &quot;netSellamt&quot;: &quot;106.60&quot;,\n        &quot;Fillbuyamt&quot;: &quot;0.00&quot;,\n        &quot;unrealisedprofitloss&quot;: &quot;-0.30&quot;,\n        &quot;PriceNumerator&quot;: &quot;1&quot;,\n        &quot;Type&quot;: &quot;DAY1&quot;,\n        &quot;netbuyqty&quot;: &quot;0&quot;,\n        &quot;BLQty&quot;: 1,\n        &quot;Fillbuyqty&quot;: &quot;0&quot;,\n        &quot;CFsellqty&quot;: &quot;0&quot;,\n        &quot;s_NetQtyPosConv&quot;: &quot;N&quot;,\n        &quot;CFbuyqty&quot;: &quot;0&quot;,\n        &quot;Sellavgprc&quot;: &quot;106.60&quot;,\n        &quot;Bqty&quot;: &quot;0&quot;,\n        &quot;Exchange&quot;: &quot;NSE&quot;,\n        &quot;CFSellavgprc&quot;: &quot;0.00&quot;,\n        &quot;Fillsellamt&quot;: &quot;106.60&quot;,\n        &quot;actid&quot;: &quot;TS2499&quot;,\n        &quot;GeneralDenomenator&quot;: &quot;1&quot;,\n        &quot;Instname&quot;: &quot;NA&quot;,\n        &quot;discQty&quot;: &quot;10&quot;,\n        &quot;Expdate&quot;: &quot;NA&quot;,\n        &quot;LTP&quot;: &quot;106.90&quot;,\n        &quot;Buyavgprc&quot;: &quot;0.00&quot;,\n        &quot;Token&quot;: &quot;24948&quot;,\n        &quot;GeneralNumerator&quot;: &quot;1&quot;,\n        &quot;companyname&quot;: &quot;L&amp;T FINANCE HOLDINGS LTD&quot;,\n        &quot;stat&quot;: &quot;Ok&quot;,\n        &quot;PriceDenomenator&quot;: &quot;1&quot;,\n        &quot;FillbuyamtCF&quot;: &quot;0.00&quot;,\n        &quot;Stikeprc&quot;: &quot;0&quot;,\n        &quot;BEP&quot;: &quot;106.60&quot;,\n        &quot;Pcode&quot;: &quot;MIS&quot;\n    }]<\/code><\/pre>\n\n\n\n<p>One can get the detailed positionbook API response from\u00a0<a href=\"https:\/\/docs.algomojo.com\/docs\/api\/v1\">Algomojo Documentation<\/a><\/p>\n\n\n\n<p><strong>To Build this module we need 2 components<\/strong><\/p>\n\n\n\n<p>1)Header PositionBook Module that needs to be placed inside the&nbsp;<strong>Amibroker\\Formulas\\Include<\/strong>&nbsp;folder<br>2)Main Module which send the data to PositionBook Module for Parsing<\/p>\n\n\n\n<p><strong>Header Module<\/strong><\/p>\n\n\n\n<p>Copy the Header Execution Module to Amibroker\\Formulas\\include folder. Save the AFL under the name&nbsp;<strong>positionbook.afl<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\">\/\/store the file under the name - PositionBook.afl under the Amibroker\\Formulas\\Include folder\n\nuid = ParamStr(&quot;Client ID&quot;,&quot;TS2499&quot;);\nuser_apikey = ParamStr(&quot;user_apikey&quot;,&quot;86cbef19e7e61ccee91e497690d5814e&quot;); \/\/Enter your API key here\napi_secret = ParamStr(&quot;api_secret&quot;,&quot;8e8b207de43446c65f379bf2145b62fc&quot;); \/\/Enter your API secret key here\ns_prdt_ali = &quot;BO:BO||CNC:CNC||CO:CO||MIS:MIS||NRML:NRML&quot;;\nbroker = ParamStr(&quot;Broker&quot;,&quot;tj&quot;); \/\/Broker Short Code - ab - aliceblue, tj - tradejini, zb - zebu, en - enrich\nver = ParamStr(&quot;API Version&quot;,&quot;1.0&quot;);\n\nRequestTimedRefresh(1,False);\n\nfunction GetPositionsBook()\n{\n\nalgomojo=CreateObject(&quot;AMAMIBRIDGE.Main&quot;);\napi_data =&quot;{\\&quot;uid\\&quot;:\\&quot;&quot;+uid+&quot;\\&quot;,\\&quot;actid\\&quot;:\\&quot;&quot;+uid+&quot;\\&quot;,\\&quot;type\\&quot;:\\&quot;&quot;+&quot;NET&quot;+&quot;\\&quot;,\\&quot;s_prdt_ali\\&quot;:\\&quot;&quot;+s_prdt_ali+&quot;\\&quot;}&quot;;\nresp=algomojo.AMDispatcher(user_apikey, api_secret,&quot;PositionBook&quot;,api_data,broker,ver);\n_TRACE(&quot; Position Book  : &quot; +resp);\nreturn resp;\n}\n\nfunction JsonParse(resp,Tsym,Pcode,stringinfo)\n{\n\n\/\/Initialization\nflag = 0;\npossym = &quot;&quot;;\nposNetqty =0;\n\n\nfor( item = 0; ( sym = StrExtract( resp, item,&#039;{&#039; )) != &quot;&quot;; item++ )\n{\n\nsym = StrTrim(sym,&quot; &quot;);\nTsym = StrTrim(Tsym,&quot; &quot;);\n\nif(StrFind(sym,Tsym) AND StrFind(sym,Pcode)) \/\/Matches the symbol and \/\/Matches the Order Type\n{\n\nflag = 1; \/\/turn on the flag\n\ndata = sym;\n\n\n\nfor( jitem = 0; ( posdetails = StrExtract( data, jitem,&#039;,&#039; )) != &quot;&quot;; jitem++ )\n{\n  \n  if(StrFind(posdetails,&quot;\\&quot;&quot;+stringinfo+&quot;\\&quot;&quot;))\n  {\n   posdetails = StrExtract(posdetails,1,&#039;:&#039;);\n   _TRACE(&quot;\\n&quot;+stringinfo+&quot; : &quot;+StrTrim(posdetails,&quot;\\&quot;&quot;));\n  }\n  \n\n} \/\/end of for loop\n}\n\n}\/\/end of for loop\n\n}<\/code><\/pre>\n\n\n\n<p><strong>Main Module<\/strong><\/p>\n\n\n\n<p>Copy the Main Execution Module to Amibroker\\Formulas\\Algomojo Platform. Save the AFL under the name&nbsp;<strong>PositonBook Json Parsing.afl<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\">#include &lt; positionbook.afl &gt;\n\n\nSymbol = ParamStr(&quot;Symbol&quot;,&quot;EIHAHOTELS-EQ&quot;);\nPcode = ParamList(&quot;Pcode&quot;,&quot;NRML|CO|MIS&quot;,2);\ntrigger = ParamTrigger(&quot;Trigger Button&quot;,&quot;Get PositionBook&quot;);\n\nif(trigger)\n{\nresp = GetPositionsBook();\nJsonParse(resp,Symbol,Pcode,&quot;unrealisedprofitloss&quot;); \/\/output in string format\nJsonParse(resp,Symbol,Pcode,&quot;realisedprofitloss&quot;); \/\/output in string format\nJsonParse(resp,Symbol,Pcode,&quot;Exchange&quot;); \/\/output in string format\nJsonParse(resp,Symbol,Pcode,&quot;Netqty&quot;); \/\/output in string format\nJsonParse(resp,Symbol,Pcode,&quot;Buyavgprc&quot;); \/\/output in string format\nJsonParse(resp,Symbol,Pcode,&quot;Sellavgprc&quot;); \/\/output in string format\nJsonParse(resp,Symbol,Pcode,&quot;companyname&quot;); \/\/output in string format\nJsonParse(resp,Symbol,Pcode,&quot;MtoM&quot;); \/\/output in string format\n\n}<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/docs.algomojo.com\/docs\/api\/v1\">Enable the Logging Feature in Amibroker<\/a>\u00a0to check the output in the Amibroker Log window<\/p>\n\n\n\n<p><strong>Sample Output<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/www.marketcalls.in\/wp-content\/uploads\/2021\/03\/image-1024x332.png\" alt=\"This image has an empty alt attribute; its file name is image-1024x332.png\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>This is a simple tutorial that explains how to access the position book using Amibroker and get various details about the position book details to use further in your trading system.<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[6],"tags":[13,7,102,101],"_links":{"self":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/189"}],"collection":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/comments?post=189"}],"version-history":[{"count":4,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/189\/revisions"}],"predecessor-version":[{"id":1591,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/189\/revisions\/1591"}],"wp:attachment":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/media?parent=189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/categories?post=189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/tags?post=189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}