API Support Forum
OEC API > API Support > GF API COM OnMarginCalculationCompleted to Being Hit After doing Margin Request
Author Topic: GF API COM OnMarginCalculationCompleted to Being Hit After doing Margin Request
(5 messages, Page 1 of 1)
Moderators: VPfau
RWare2020
Posts: 205
Joined: Feb 11, 2020


Posted: Feb 09, 2023 @ 07:03 PM             Msg. 1 of 5
OnMarginCalculationCompleted is not being called after doing a margin request.
It was working before and is no longer working.
This is my code for the margin request:
I have tried updating the latest version of the API but did not help

IMarginCalculationRequestBuilderPtr marginCalc;
marginCalc.CreateInstance(__uuidof(MarginCalculationRequestBuilder));

IAccountPtr pAcct = GetCurrentAccountPtr(GFApi());

marginCalc->WithAccountID(pAcct->id);
IContractPtr contract = GFApi()->Contracts->Get_2((LPCTSTR)leg->
marginCalc->WithOrder(GFApi()->Margin->CreateHypoOrder(contract->id, side, qty));
IMarginCalculationRequestPtr marginRequest = marginCalc->Build();
_bstr_t valid = GFApi()->Margin->ValidateMarginCalculationRequest(marginRequest);
//valid is NULL which means it is valid
GFApi()->Margin->RequestMarginCalculation(marginRequest);

Please implement what is involved in this thread (https://apisupport.gainfutures.com/Topic/Index/1483) , it's in the API, but not in the GF COM API Wrapper as well

Thanks
RWare2020
Posts: 205
Joined: Feb 11, 2020


Posted: Feb 09, 2023 @ 07:04 PM             Msg. 2 of 5
Logging is showing that the margin calculation is going out:

Timestamp: 2/9/2023 6:03:30 PM - Category: 2 - Message: OrderConnection Outgoing:
Timestamp: 2/9/2023 6:03:32 PM - Category: 2 - Message: OrderConnection Outgoing:
Timestamp: 2/9/2023 6:03:34 PM - Category: 2 - Message: OrderConnection Outgoing:
RWare2020
Posts: 205
Joined: Feb 11, 2020


Posted: Feb 14, 2023 @ 11:41 AM             Msg. 3 of 5
Something seems weird.

With option symbol:
OQNEG23 C12500 - marginCalc->WithOrder(GFApi()->Margin->CreateHypoOrder(contract->id, OrderSide_Buy, 1));
OQNEG23 P12500 - marginCalc->WithOrder(GFApi()->Margin->CreateHypoOrder(contract->id, OrderSide_Sell, 1));
OQNEG23 C12250 - marginCalc->WithOrder(GFApi()->Margin->CreateHypoOrder(contract->id, OrderSide_Buy, 1));

OnMarginCalculated does not get called

With Option Symbol:
OQNEG23 C12300 - marginCalc->WithOrder(GFApi()->Margin->CreateHypoOrder(contract->id, OrderSide_Buy, 1));
OQNEG23 P12300 - marginCalc->WithOrder(GFApi()->Margin->CreateHypoOrder(contract->id, OrderSide_Sell, 1));
OQNEG23 C12550 - marginCalc->WithOrder(GFApi()->Margin->CreateHypoOrder(contract->id, OrderSide_Buy, 1));

OnMarginCalculated does get called

They are both compound orders with 2 buy calls and 1 sell put.
The legs that do get calculated, they are a current position of mine. Why is it working when I have a position and not work when I don't have a position with those legs?
RWare2020
Posts: 205
Joined: Feb 11, 2020


Posted: Feb 14, 2023 @ 11:46 AM             Msg. 4 of 5
Furthermore, if I place the order that is not being calculated, then attempt to do another margin check on the position I just placed it works.

So it appears that the margin calculation only works on positions in the account.
JSmith5611
Posts: 187
Joined:


Posted: Feb 16, 2023 @ 11:48 AM             Msg. 5 of 5
Placing a margin calc request with multiple orders, and no position is working just fine for me.
Jason Smith