API Support Forum
OEC API > API Support > GFAPI COM Help with Closed Positions
Author Topic: GFAPI COM Help with Closed Positions
(18 messages, Page 1 of 1)
Moderators: VPfau
RWare2020
Posts: 205
Joined: Feb 11, 2020


Posted: Jun 09, 2022 @ 04:13 PM             Msg. 1 of 18
I am having 2 issues:

1. When opening/closing a position with a symbol that currently does not have an open order closed position, the DetailedPositionDictionaryPtr does not increment in size and therefore the position is not there. If I re-initialize everything (logout and log back in) they will appear.

We use this to get our closed positions:

IDetailedPositionDictionaryPtr poses;
if(pAcct)
poses = pAcct->DetailedPositions;
for(int i = 0; i Count; i++)
{
IPositionListPtr pos = poses->ValueByIndex(i);
for(int j = 0; j Count; j++)
{
IPositionPtr p = pos->GetAt(j);
if(p->Net->Volume == 0) //closed position
{
//build closed position
}
}
}


2. In the OECAPI, we use the SourceFill ID to display the open/closed position id, however, the sourcefill id always changes. What is an accurate way to get the open/close order id for the closed position in the GF API?
JSmith5611
Posts: 187
Joined:


Posted: Jun 13, 2022 @ 09:23 AM             Msg. 2 of 18
I'm looking into these this morning. If you have any more details, please let me know.
Jason Smith
JSmith5611
Posts: 187
Joined:


Posted: Jun 13, 2022 @ 10:43 AM             Msg. 3 of 18
1) I've been testing this situation this morning, but the new positions always are in the detailedpositions.. can you give me a detailed step-by-step you do to reproduce? Aslo, i do notice that your for loops in this example do not show what is the source of the Count calls.

2) Yes, every time you get an IFill.ID (of type IFillID) it will be a different object, the IFillID's Value member will always be the same value for a given fill.
Jason Smith
RWare2020
Posts: 205
Joined: Feb 11, 2020


Posted: Jun 13, 2022 @ 12:20 PM             Msg. 4 of 18
1) Sorry something must have happened when I copied and pasted. The for loops should show:
IDetailedPositionDictionaryPtr poses = pAcct->DetailedPositions
for(int i = 0; i < poses -> Count; i++)
{
IPositionListPtr pos = poses->ValueByIndex(i);
for(int j = 0; j < pos -> Count; j++)
{
}
}

1 cont...) Inside of our callback for OnOrderFilled we update our closed positions. If I open a position and close a position and put a breakpoint on a variable that stores the count of our detailed positions, it shows 0. On first run of the software for the day, this is true no matter how many times I open and close any position:

IDetailedPositionDictionaryPtr poses = pAcct->DetailedPositions
int count = poses->Count; //this is 0

If I restart my application, the detailed positions count is then correct until I open and close a position with a different symbol (It's not just base symbol, doing it on the same base symbol with different expiration does not show up).

Step by step:
Open Software
Buy MNQU22
Sell MNQU22
Detailed Position size is 0
Sell MNQU22
Buy MNQU22
Detailed Position size is 0
Restart application
Detailed Position size is 1
Buy MESU22
Sell MESU22
Detailed Position size is 1
Sell MESU22
Buy MESU22
Detailed Position size is 1
Restart application
Detailed Position size is 2

Whenever the detailed position size is correct, I can close positions of the same symbol that is in the detailed positions map and it will then correctly show up. It's like the detailed positions list doesn't update for new symbols or something.

2) Oh perfect, thank you for that.
Edited by RWare2020 on Jun 13, 2022 12:21 PM
Edited by RWare2020 on Jun 13, 2022 12:31 PM
Edited by RWare2020 on Jun 13, 2022 12:48 PM
RWare2020
Posts: 205
Joined: Feb 11, 2020


Posted: Jun 13, 2022 @ 12:23 PM             Msg. 5 of 18
I have tested this in the latest GAIN GFAPI COM 4.7.603.176 as well as GAIN GFAPI COM 4.5.311.173
JSmith5611
Posts: 187
Joined:


Posted: Jun 13, 2022 @ 03:00 PM             Msg. 6 of 18
Do you keep a copy of IDetailedPositionDictionaryPtr or IAccount, or get a new object from the api each time?
Jason Smith
RWare2020
Posts: 205
Joined: Feb 11, 2020


Posted: Jun 13, 2022 @ 03:24 PM             Msg. 7 of 18
We get a new object from the api each time. This is our GetAccountPtr function:

if(GF_Api_COM::IAccountListPtr accts = GFApi()->Accounts->Get()) {
std::string currentIdString = std::to_string(accts->GetAt(m_curAccountIndex)->id->Value);
if(strAcct.compare(currentIdString) == 0) {
pAcct = accts->GetAt(m_curAccountIndex);
found = true;
}
else {
for(int i = 0; i Count && !found; i++) {
std::string str = std::to_string(accts->GetAt(i)->id->Value);
if(str.compare(strAcct) == 0) {
pAcct = accts->GetAt(i);
found = true;
}
}
}
}
JSmith5611
Posts: 187
Joined:


Posted: Jun 14, 2022 @ 09:17 AM             Msg. 8 of 18
Ok. after much digging, I do see that there is a problem here. I'll let you know when i have a fix.
Jason Smith
RWare2020
Posts: 205
Joined: Feb 11, 2020


Posted: Jun 14, 2022 @ 10:55 AM             Msg. 9 of 18
Thank you very much!
RWare2020
Posts: 205
Joined: Feb 11, 2020


Posted: Jun 24, 2022 @ 10:25 AM             Msg. 10 of 18
It appears that the fix is in the api environment. Thanks for getting this taken care of. Do you have an ETA as to when this will be in PROD/SIM?

Thanks again.
RWare2020
Posts: 205
Joined: Feb 11, 2020


Posted: Jul 08, 2022 @ 04:00 PM             Msg. 11 of 18
Any ETA on when this fix will be in Sim/Prod?
VPfau
Moderator
Posts: 154
Joined:


Posted: Jul 11, 2022 @ 08:30 AM             Msg. 12 of 18
Hello

this item was released
to SIM at June 26 2022
to PROD at July 9 2022
Vitaliy Pfau
RWare2020
Posts: 205
Joined: Feb 11, 2020


Posted: Jul 11, 2022 @ 10:44 AM             Msg. 13 of 18
Well then it appears that we are still experiencing the issue.

I have updated to version GAIN GFAPI COM 4.7.624.179 and having the same issue. I am having an issue login to the api side to test api again to make sure it is still working over there. I will update the thread if I have issues logging into API

Thanks.
Edited by RWare2020 on Jul 11, 2022 12:04 PM
RWare2020
Posts: 205
Joined: Feb 11, 2020


Posted: Jul 12, 2022 @ 02:47 PM             Msg. 14 of 18
I am unable to login to the api side. Can I please get some help with that as well?

Thanks
JSmith5611
Posts: 187
Joined:


Posted: Jul 13, 2022 @ 07:55 AM             Msg. 15 of 18
This fix was released in 4.7.709.181
Jason Smith
RWare2020
Posts: 205
Joined: Feb 11, 2020


Posted: Jul 13, 2022 @ 11:07 AM             Msg. 16 of 18
The latest version available from https://gainfutures.com/gainfuturesapi/documentation/ Download GF API COM (32 - Bit) button is GAIN GFAPI COM 4.7.624.179
JSmith5611
Posts: 187
Joined:


Posted: Jul 15, 2022 @ 08:19 AM             Msg. 17 of 18
I just used those links and got the version i mentioned.4.7.709.181
Jason Smith
RWare2020
Posts: 205
Joined: Feb 11, 2020


Posted: Jul 15, 2022 @ 12:19 PM             Msg. 18 of 18
I was able to download it today.

I cleared my cache, not sure if that helped. I should have tried before clearing my cache today.

I tested this new version and things are working correctly, thanks for getting this fixed.