Fetching Open positions

is this the correct way to retrieve open positions?
It returns there are open positions even when there are no open positions.
Am i making a mistake in the code.

Hello @Dev

Looks like you are just printing whether there are open positions or not instead of looking for what the open positions are.

You can also use print (open_pos) to actually print the position details along.

Hi @Hardik ,

I am trying to retrieve if there are open positions or not.
I think the command dhan.get_positions() is to fetch all positions of the day not just open ones.
The wording in the API document confused me.

Can you let me know if there are commands to:

  1. check if there are any open positions
    or
  2. close all open positions at one go

Thanks,

Hello @Dev

Yes, you got it right!

  1. No, you can simply filter out from the JSON based on positionType.
  2. This you will have to do at your end only, there is no Exit All API available as of now.

Thanks Hardik

1 Like