Hey Guys, I working on a scenario where i am infinitely looping through few Scripts in worker thread, and once the XYZ condition met, i will pass the specific script further to place an Cover Order, but before placing the order i need to check if there is any order is currently open,
So i have called getPositions() method which returns HashMap . then i will iterate through HashMap to check if Trading Symbol already present in Positions arrayslist, if Yes then check for netqty==0 then i am good place the order.
Since i am testing this now, and i know i have placed two cover orders for CIPLA, when i am iterating through Hashmap i am getting below exception.
You can check out the raw response here. The response will always have two maps one is for net positions and another for day positions. Having two maps doesn't mean it contains elements always. Array will have positions if there are some active positions(closed or open) in your account.
Ok checked size for "net" and "day" both are 1 and 1 hence Map size is 2 So in order to make this work, can i safely iterate through size of "net" in my for loop ? I just need to check if Position is open (netqty==0), Assuming net will always contain open position right ?
for (int i=0 ;i<position.get("net").size() ;i++) {.....TODO......}
Another basic question - What is the difference between net and day elements ?
Yes, you can add a size check before doing any operations. Net will have all the positions including day and overnight positions whereas day will have only today's positions.
The response will always have two maps one is for net positions and another for day positions. Having two maps doesn't mean it contains elements always. Array will have positions if there are some active positions(closed or open) in your account.
Ok checked size for "net" and "day" both are 1 and 1 hence Map size is 2
So in order to make this work, can i safely iterate through size of "net" in my for loop ? I just need to check if
Position is open (netqty==0), Assuming net will always contain open position right ?
for (int i=0 ;i<position.get("net").size() ;i++)
{.....TODO......}
Another basic question - What is the difference between net and day elements ?
Thanks,
Abhijeet
Net will have all the positions including day and overnight positions whereas day will have only today's positions.
As per my current logic, All orders will be intraday so i am not worried about overnight positions.
Thanks for your support, We are good to close this thread.
Regards,
Abhijeet