{"id":186,"date":"2021-03-02T03:45:58","date_gmt":"2021-03-02T03:45:58","guid":{"rendered":"https:\/\/algomojo.com\/blog\/?p=186"},"modified":"2025-02-27T07:46:08","modified_gmt":"2025-02-27T07:46:08","slug":"how-to-retrieve-opening-balance-total-turnover-realized-and-unrealized-mtm-using-python","status":"publish","type":"post","link":"https:\/\/algomojo.com\/blog\/how-to-retrieve-opening-balance-total-turnover-realized-and-unrealized-mtm-using-python\/","title":{"rendered":"How to Retrieve Opening Balance, Total Turnover, Realized and Unrealized MTM using Python?"},"content":{"rendered":"\n<p>This tutorial explores how to access the limits API functionality in Algomojo using python to retrieve the Account Balance, Total Turnover, Realized, UnRealized PNL, Realized Intraday MTM, UnRealized Intraday MTM.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1280\" height=\"720\" src=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2021\/03\/Fund-Details.png\" alt=\"\" class=\"wp-image-187\"\/><\/figure>\n\n\n\n<p><strong>Supported Brokers<\/strong> : Aliceblue, Tradejini, Zebu<\/p>\n\n\n\n<p><strong>How to Install Algomojo Python Library?<\/strong><\/p>\n\n\n\n<p>Install from PyPI using the simple PIP command<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-bash\">pip install algomojo<\/code><\/pre>\n\n\n\n<p>It is highly recommended to use Python 3.x versions<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/i0.wp.com\/www.marketcalls.in\/wp-content\/uploads\/2020\/11\/image-16.png?resize=993%2C519&amp;ssl=1\" alt=\"This image has an empty alt attribute; its file name is image-16.png\"\/><\/figure>\n\n\n\n<p id=\"block-35a1c7d3-4050-4fb4-9d13-f59db28d62e7\">Algomojo provides in-depth functionality to explore various possibilities of implementing your own trading rules. For more detailed documentation visit <a href=\"https:\/\/docs.algomojo.com\/docs\/api\/v1\">algomojo documentation<\/a><\/p>\n\n\n\n<p id=\"block-4e3ab033-7220-4dd0-b0cb-02deb29d1a16\"><strong>Sample Limits API Response<\/strong><\/p>\n\n\n\n<p id=\"block-d187303b-d5c7-4b03-ad5f-5d91446d931f\">Limits API in Algomojo provides details funds information of the client and helps users to<br>1)Positionsize based on the available funds detail.<br>2)Implementing risk management based on the available funds<br>3)Implementing Portfolio Stoploss based on realized or unrealized profit and loss figures.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-json\">{&#039;OpeningBalance&#039;: &#039;88834.73&#039;,\n &#039;Netcashavailable&#039;: &#039;88835.73&#039;,\n &#039;grossexposurevalue&#039;: &#039;0.00&#039;,\n &#039;segment&#039;: &#039;ALL&#039;,\n &#039;cncrealizedmtomprsnt&#039;: &#039;-0.0&#039;,\n &#039;valueindelivery&#039;: &#039;0.00&#039;,\n &#039;cncsellcreditpresent&#039;: &#039;0.00&#039;,\n &#039;cncunrealizedmtomprsnt&#039;: &#039;-0.0&#039;,\n &#039;deliverymarginprsnt&#039;: &#039;0&#039;,\n &#039;grossCollateral&#039;: &#039;0&#039;,\n &#039;BuyPower&#039;: &#039;88835.73&#039;,\n &#039;PayoutAmt&#039;: &#039;-0.00&#039;,\n &#039;cncbrokerageprsnt&#039;: &#039;0&#039;,\n &#039;turnover&#039;: &#039;240243&#039;,\n &#039;unrealisedmtom&#039;: &#039;-0.00&#039;,\n &#039;adhocscripmargin&#039;: &#039;0.00&#039;,\n &#039;specialmarginprsnt&#039;: &#039;0&#039;,\n &#039;BOmarginRequired&#039;: &#039;0.00&#039;,\n &#039;losslimit&#039;: &#039;0&#039;,\n &#039;IPOAmount&#039;: &#039;-0.00&#039;,\n &#039;elm&#039;: &#039;0.00&#039;,\n &#039;cdsspreadbenefit&#039;: &#039;0.00&#039;,\n &#039;realisedmtom&#039;: &#039;1264.00&#039;,\n &#039;category&#039;: &#039;ONLINE&#039;,\n &#039;nfospreadbenefit&#039;: &#039;0.00&#039;,\n &#039;Utilizedamount&#039;: &#039;0.00&#039;,\n &#039;exposuremargin&#039;: &#039;0.00&#039;,\n &#039;Adhoc&#039;: &#039;1.00&#039;,\n &#039;t1grossCollateral&#039;: &#039;0&#039;,\n &#039;directcollateralvalue&#039;: &#039;0.000000&#039;,\n &#039;StockValuation&#039;: &#039;0.00&#039;,\n &#039;credits&#039;: &#039;88835.73&#039;,\n &#039;branchadhoc&#039;: &#039;0.000000&#039;,\n &#039;adhocmargin&#039;: &#039;1.000000&#039;,\n &#039;additionalmarginprsnt&#039;: &#039;0&#039;,\n &#039;spanmargin&#039;: &#039;0.00&#039;,\n &#039;premiumpresent&#039;: &#039;0.00&#039;,\n &#039;BookedPNL&#039;: &#039;1264.00&#039;,\n &#039;varmargin&#039;: &#039;0.00&#039;,\n &#039;marginScripBasketCustomPresent&#039;: &#039;0&#039;,\n &#039;tendermarginprsnt&#039;: &#039;0&#039;,\n &#039;cncmarginused&#039;: &#039;0&#039;,\n &#039;brokerageprsnt&#039;: &#039;0&#039;,\n &#039;UnbookedPNL&#039;: &#039;-0.00&#039;,\n &#039;debits&#039;: &#039;0.00&#039;,\n &#039;COMarginRequired&#039;: &#039;0.00&#039;,\n &#039;multiplier&#039;: &#039;1.00&#039;,\n &#039;stat&#039;: &#039;Ok&#039;,\n &#039;mfamount&#039;: &#039;0.00&#039;,\n &#039;scripbasketmargin&#039;: &#039;0.00&#039;,\n &#039;buyExposurePrsnt&#039;: &#039;0&#039;,\n &#039;notionalcash&#039;: &#039;0&#039;,\n &#039;additionalpreexpirymarginprsnt&#039;: &#039;0&#039;,\n &#039;cncMarginElmPrsnt&#039;: &#039;0&#039;,\n &#039;PayinAmt&#039;: &#039;0.00&#039;,\n &#039;cncMarginVarPrsnt&#039;: &#039;0&#039;,\n &#039;mfssamountused&#039;: &#039;0.00&#039;,\n &#039;sellExposurePrsnt&#039;: &#039;0&#039;}<\/code><\/pre>\n\n\n\n<p id=\"block-60340d81-4fe6-43a4-9f17-6cbb02013b10\">Here is the python code which demonstrates how to fetch the funds details using the limits API.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">#!\/usr\/bin\/env python\n# coding: utf-8\n\n# Import Python Libraries\n\n\n#Import Algomojo Library\nfrom algomojo import *\nimport json\n\n\n#set the API Key and API secret key, Broker Code and the Version\n#Broker Code &quot;ab&quot; = aliceblue, &quot;tj&quot; = tradejini, &quot;zb&quot; = zebu, &quot;en&quot; = enrich for the list of short codes supported kindly check with algomojo team\n#default version used Ver = 1.0\n\ntj = api(&quot;86cbef19e7e61ccee91e497690d5814e&quot;,&quot;8e8b207de43446c65f379bf2145b62fc&quot;,broker=&quot;tj&quot;,version=1.0)\n\n\n# Fetch the Limits containing the JSON Data\n\n\nlimits = tj.limits(&#039;TS2499&#039;,exchange=&quot;&quot;)\nlimits\n\n\n# Parse the JSON \n\n\ndata = json.dumps(limits)\nfunds = json.loads(data)\nbalance = funds[&quot;Netcashavailable&quot;]\nturnover = funds[&quot;turnover&quot;]\nrealizedPNL = funds[&quot;BookedPNL&quot;]\nunrealizedPNL = funds[&quot;UnbookedPNL&quot;]\nrealizedMTM = funds[&quot;realisedmtom&quot;]\nunrealizedMTM = funds[&quot;unrealisedmtom&quot;]\n\n#Print the Funds Details\n\nprint(&quot;Account balance :&quot;+balance)\nprint(&quot;Total Turnover :&quot;+turnover)\nprint(&quot;Account PNL :&quot;+realizedPNL)\nprint(&quot;Account unrealized PNL :&quot;+unrealizedPNL)\nprint(&quot;Intraday Realized MTM :&quot;+realizedMTM)\nprint(&quot;Intraday Unrealized MTM :&quot;+unrealizedMTM)\n<\/code><\/pre>\n\n\n\n<p id=\"block-f78b36b0-70fe-485f-930f-df02bd3349ce\"><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-batch\">Account balance :88835.73\nTotal Turnover :240243\nAccount PNL :1264.00 \nAccount unrealized PNL :-0.00 \nIntraday Realized MTM :1264.00 \nIntraday Unrealized MTM :-0.00<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial explores how to access the limits API functionality in Algomojo using python to retrieve the Account Balance, Total Turnover, Realized, UnRealized PNL, Realized Intraday MTM, UnRealized Intraday MTM.<\/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":[95],"tags":[97,4,96,31,99,98,100],"_links":{"self":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/186"}],"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=186"}],"version-history":[{"count":3,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/186\/revisions"}],"predecessor-version":[{"id":1592,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/186\/revisions\/1592"}],"wp:attachment":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/media?parent=186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/categories?post=186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/tags?post=186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}