How do we calculate the number of active positions and the number of trades in a day

If i want to put a filter for number of trades per day and number of active trades per day, which API should i use?
Or basically I am interested in knowing all the positions for the current day both active and closed.

I think active trades are positions?
Order api TradeHistory will it show all the closed position for the current day ?

I am confused ? Both these filters are important to avoid big losses.

Also how to get all GttOrders currently placed, I see that we can fetch the Gtt order details via orderId, but i want to check all the GttOrders currently placed. how to get it?

Hi, you can try using Get Trades | Upstox Developer API

2 Likes

Don’t pass order ID and it will return all gtt orders.

And order API will give you all orders placed during current day. You need to match buy and sell orders to get closed positions and unmatched orders will be your open positions.

1 Like

@Jagdish_j_ptl
I am using java SDK, there is no method corresponding to getting all GttOrders

So Position for active trades ?
and GetTrades for closed trades ?

Pass null to get GTT order details method. if it is available. as Gtt order id field is optional.

Try using

apiInstance.getGttOrderDetails("");

apiInstance.getGttOrderDetails();

Yes I think you are right, It is optional

In python it is returning all GTT orders if you don’t pass order id

Yes correct it will do the same in java.
so position is active trades ?
and Trades is closed trades ?

Positions API will give you all the positions. If qty is 0 then it is closed else it is open positive for buy order and negative for sell order.

But if you want to calculate Total number of orders placed during day then you need to use orders API which will give you buy and sell orders. Then you need to manually match each order with buy sell pair.

basically my use case is to limit total active trades and total trades in a day, please suggest correct apis to use for this use case.

I am using Get Order Book | Upstox Developer API to fetch all orders and then filtering all the completed or partially filled ( order where filled_quantity > 0 and status is cancelled) and then matching buy sell order to calculate total orders.

Well i think position api is more suitable
as you mentioned it can retrieve all positions
qty >0 active trades
qty==0 closed trades.
So this logic is fine right assuming all positions are retrieved past and current.

Thanks

For buying qty>0 is active position

for selling qty < 0 is active position

and qty=0 for closed position.

Here you can’t calculate total orders as for multiple orders you will see only one position with total qty.

oh ok Thanks makes sense

Since I will be placing only GTT orders, so wondering how it could be determined using get GTT,

  1. if the target and stoploss are scheduled and entry is complete it means the trade is active
  2. if the target or stoploss is complete and entry is complete it means the trade was closed
  3. if all 3 are in scheduled, it means upcoming order
  4. other combinations are irrelevant

Do you think the above makes sense.

One more condition will be added if entry is completed and stoploss and target is cancelled then also trade is active.

Hmm agree, there are chances of that.