API Market Depth and Open position py code Doc

i want to Market depth, Open position and P&L is use in my algo code , i search but not found code doc

please help

@KBS You can find the code here - Installing the Upstox SDK and Dependencies | Upstox Developer API . Each “github” folder has “examples” and “docs“ folder.

2 Likes

SDK already installed , i use this code below

def get_broker_pnl():
    try:
        response = portfolio_api.get_positions(api_version="2.0")
        if response and response.data:
            total_pnl = 0.0
            for pos in response.data:
                realized = float(pos.realised_pnl) if pos.realised_pnl else 0.0
                unrealized = float(pos.unrealised_pnl) if pos.unrealised_pnl else 0.0
                total_pnl += (realized + unrealized)
            return total_pnl
    except Exception as e:
        print(f"⚠️ Error fetching Broker PnL: {e}")
    return 0.0

but not get pnl value , today out put

Trades: 4
Wins: 2 | Losses: 2
Win Rate: 50.00%
Net PnL: ₹45.68​:bank: Broker PnL: ₹+0.00
:waving_hand: Session Ended. Exiting script.
PS D:\upstox>

pl help

@KBS That is why “Vibe coding” is harmful, you are not even reading the standard documents.

Very clear example and explanation of each “response“ parameters is mentioned here. Get Positions | Upstox Developer API
Also clearly mentioned in the github code. upstox-python/upstox_client/models/position_data.py at master · upstox/upstox-python · GitHub and upstox-python/docs/PositionData.md at master · upstox/upstox-python · GitHub

You are fetching incorrect parameters from “pos” List item.

1 Like