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 Retrieve Opening Balance, Total Turnover, Realized and Unrealized MTM using Python?

1 min read

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.

Supported Brokers : Aliceblue, Tradejini, Zebu

How to Install Algomojo Python Library?

Install from PyPI using the simple PIP command

pip install algomojo

It is highly recommended to use Python 3.x versions

Algomojo provides in-depth functionality to explore various possibilities of implementing your own trading rules. For more detailed documentation visit algomojo documentation

Sample Limits API Response

Limits API in Algomojo provides details funds information of the client and helps users to
1)Positionsize based on the available funds detail.
2)Implementing risk management based on the available funds
3)Implementing Portfolio Stoploss based on realized or unrealized profit and loss figures.

{'OpeningBalance': '88834.73',
 'Netcashavailable': '88835.73',
 'grossexposurevalue': '0.00',
 'segment': 'ALL',
 'cncrealizedmtomprsnt': '-0.0',
 'valueindelivery': '0.00',
 'cncsellcreditpresent': '0.00',
 'cncunrealizedmtomprsnt': '-0.0',
 'deliverymarginprsnt': '0',
 'grossCollateral': '0',
 'BuyPower': '88835.73',
 'PayoutAmt': '-0.00',
 'cncbrokerageprsnt': '0',
 'turnover': '240243',
 'unrealisedmtom': '-0.00',
 'adhocscripmargin': '0.00',
 'specialmarginprsnt': '0',
 'BOmarginRequired': '0.00',
 'losslimit': '0',
 'IPOAmount': '-0.00',
 'elm': '0.00',
 'cdsspreadbenefit': '0.00',
 'realisedmtom': '1264.00',
 'category': 'ONLINE',
 'nfospreadbenefit': '0.00',
 'Utilizedamount': '0.00',
 'exposuremargin': '0.00',
 'Adhoc': '1.00',
 't1grossCollateral': '0',
 'directcollateralvalue': '0.000000',
 'StockValuation': '0.00',
 'credits': '88835.73',
 'branchadhoc': '0.000000',
 'adhocmargin': '1.000000',
 'additionalmarginprsnt': '0',
 'spanmargin': '0.00',
 'premiumpresent': '0.00',
 'BookedPNL': '1264.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'}

Here is the python code which demonstrates how to fetch the funds details using the limits API.

#!/usr/bin/env python
# coding: utf-8

# Import Python Libraries


#Import Algomojo Library
from algomojo import *
import json


#set the API Key and API secret key, Broker Code and the Version
#Broker Code "ab" = aliceblue, "tj" = tradejini, "zb" = zebu, "en" = enrich for the list of short codes supported kindly check with algomojo team
#default version used Ver = 1.0

tj = api("86cbef19e7e61ccee91e497690d5814e","8e8b207de43446c65f379bf2145b62fc",broker="tj",version=1.0)


# Fetch the Limits containing the JSON Data


limits = tj.limits('TS2499',exchange="")
limits


# Parse the JSON 


data = json.dumps(limits)
funds = json.loads(data)
balance = funds["Netcashavailable"]
turnover = funds["turnover"]
realizedPNL = funds["BookedPNL"]
unrealizedPNL = funds["UnbookedPNL"]
realizedMTM = funds["realisedmtom"]
unrealizedMTM = funds["unrealisedmtom"]

#Print the Funds Details

print("Account balance :"+balance)
print("Total Turnover :"+turnover)
print("Account PNL :"+realizedPNL)
print("Account unrealized PNL :"+unrealizedPNL)
print("Intraday Realized MTM :"+realizedMTM)
print("Intraday Unrealized MTM :"+unrealizedMTM)

Output

Account balance :88835.73
Total Turnover :240243
Account PNL :1264.00 
Account unrealized PNL :-0.00 
Intraday Realized MTM :1264.00 
Intraday Unrealized MTM :-0.00
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.

AllinOneAlerts – Amibroker Alerts Module for Algomojo Users

AllinOneAlerts is one of the most important and most requested modules is to bring all sorts of alerts with few lines of coding efforts....
Rajandran R
58 sec read

Algomojo Platform Now Open to Angel Broking Users

We are proud to provide our Algomojo access to Angel Broking users. Now users of Angel Broking can enjoy Free API-based algotrading access. Free...
Rajandran R
4 min read

Algomojo Trading Platform Fee Reduced for Existing Brokers Clients

Algomojo strives to bring low-cost Algo trading services with a better user experience. We are always looking for new ways to improve our services and...
Rajandran R
50 sec read

Leave a Reply

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