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

How I Built a Telegram AI Stock Assistant Using…

In this post, I'll walk you through the process of creating an intelligent Telegram AI assistant, StockBot, using the Llama 3 Groq tool use...
Rajandran R
1 min read

[Course] Building Stock Market Based Telegram Bots using Python

Learn how to build powerful Telegram bots for the stock market using Python. This hands-on course guides you through creating bots that fetch real-time...
Rajandran R
1 min read

Understanding Object-Oriented Programming (OOP) Concepts in Python for Traders…

For traders and investors, having well-structured code can greatly improve the efficiency and manageability of trading applications. Object-Oriented Programming (OOP) in Python offers a...
Rajandran R
3 min read

Leave a Reply

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