Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

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 Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

Voice Commands to Trade on OpenAlgo Platform Using Google…

Trading platforms are always getting better by using the newest technologies to make things easier and more efficient for users. A great example of...
Rajandran R
5 min read

[Live Coding Webinar] Build Your First Trading Bridge for…

In this course, you will be learning to build your own trading bridge using Python. This 60-minute session is perfect for traders, Python enthusiasts,...
Rajandran R
1 min read

How to Place Orders Concurrently using ThreadPoolExecutor – Python…

Creating concurrent orders is essential for active traders, especially those handling large funds, as it allows for executing multiple trade orders simultaneously, thereby maximizing...
Rajandran R
2 min read

Leave a Reply

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