API Support Forum
OEC API > Market Data > Marginrequest does not always respond
Author Topic: Marginrequest does not always respond
(8 messages, Page 1 of 1)
Moderators: VPfau
JKovalcin926
Posts: 9
Joined: Jan 24, 2022


Posted: Sep 20, 2022 @ 02:57 PM             Msg. 1 of 8
It turns out that the GF API does not respond to a percentage of the MarginRequests that we make. We have taken special care to validate the request, implement waiting times, verify that the contract is valid, among others.
But we don't get the event for everyone.

For example, "ESZ22" or "MEZ22" we have tried to apply it since Sept/12/2022 2 times per day but the event has not been triggered yet. But it does work for others like 6JX22, BTCX22, GFV22, M6AZ22, NKDZ22 and others.

The rest works fine with all symbols except the MarginRequest

Could you help us?


Thank you very much in advanced
VPfau
Moderator
Posts: 164
Joined:


Posted: Sep 21, 2022 @ 07:44 AM             Msg. 2 of 8
Hello,

Please provide account name, environment name, GFAPI version and example of request you are sending.

Thank you
Vitaliy Pfau
JKovalcin926
Posts: 9
Joined: Jan 24, 2022


Posted: Sep 21, 2022 @ 10:22 AM             Msg. 3 of 8
Hi VPfau, of course

The account name is JKovalcin926, GFAPI version 4.0.3.44
The code is i use is the following:

GF.Api.Accounts.AccountID accountID = client.Accounts.Get().First().ID;
HypoPosition position = new HypoPosition(e.Contracts.First().ID, 1, 1);
HypoOrder order = new HypoOrder(e.Contracts.First().ID, GF.Api.Values.Orders.OrderSide.Buy, 1);

List listPosition = new List();
listPosition.Add(position);
List listOrder = new List();
listOrder.Add(order);

IReadOnlyList datapositions = listPosition;
IReadOnlyList dataorders = listOrder;

MarginCalculationRequest marginRequest = new MarginCalculationRequest(accountID, datapositions, dataorders);

string validation = client.Margin.ValidateMarginCalculationRequest(marginRequest);
if (string.IsNullOrEmpty(validation))
{
int response = client.Margin.RequestMarginCalculation(marginRequest);
symbolData.requestID = response;
}

Thanks for advanced
VPfau
Moderator
Posts: 164
Joined:


Posted: Sep 22, 2022 @ 03:01 PM             Msg. 4 of 8
Hello,

I checked all contracts you specified and all of them are working but MEZ22. We do not have MEZ22 on API environment.
I suppose the issue is that you don't see errors we send back if something goes wrong. Make sure you subscribe to `client.Traders.TraderError` event.
Most often issue with margin requests is that you cannot send multiple requests in parallel. You need to wait `client.Margin.MarginCalculationCompleted` before send a new request.

Please see example here: https://bitbucket.org/GainFuturesDev/workspace/snippets/Eg6jXk

To See simultaneous error send two requests in line 44 like:
client.Margin.RequestMarginCalculation(request);
client.Margin.RequestMarginCalculation(request);

and you should get something similar at console:

Connecting...
Press any key to exit
Login Completed
TraderApi error occurred: Only one simultaneous margin calculation request per account is allowed
Margin request completed
Initial: 15400
Maintenance: 14000
Vitaliy Pfau
JKovalcin926
Posts: 9
Joined: Jan 24, 2022


Posted: Sep 23, 2022 @ 10:42 AM             Msg. 5 of 8
Thank you very much for your answer, I have a few points to share:
* MEZ22 is not found because I wrote it wrong in this forum, sorry. It is the MESZ22. So with that part there is no problem.
* I wasn't using that event, thanks. Continuing with the thread of not receiving ESZ22, the new event returned the following message:

"[Traders_TraderError event] Contract is not subscribed or not found for Margin Calculator request".

I was going through the bitbucket example and this is how I am using it.
Edited by JKovalcin926 on Sep 23, 2022 10:43 AM
VPfau
Moderator
Posts: 164
Joined:


Posted: Sep 23, 2022 @ 11:58 AM             Msg. 6 of 8
It is very possible that you use a contractID in your requests without obtaining a contract first.
To be able to send margin requests you have to have a contract on a client side doing lookup or other loading methods.
Vitaliy Pfau
JKovalcin926
Posts: 9
Joined: Jan 24, 2022


Posted: Sep 23, 2022 @ 12:20 PM             Msg. 7 of 8
I understand, but we are requesting the contractID before MarginRequest. here is a sample of code vs console

------> GFClient_OnSymbolLookupReceived( IGFClient client, SymbolLookupEventArgs e ) <--------------
Console.WriteLine($"Contract: {e.Contracts.First().Symbol} - {e.Contracts.First().BaseSymbol} - ID: {e.Contracts.First().ID.Value} - is pit {e.Contracts.First().ID.IsPit}");
...
GF.Api.Accounts.AccountID accountID = client.Accounts.Get().First().ID;
HypoPosition position = new HypoPosition(e.Contracts.First().ID, 1, 1);
HypoOrder order = new HypoOrder(e.Contracts.First().ID, GF.Api.Values.Orders.OrderSide.Buy, 1);
...

17:12:36:724 Contract: ESZ22 - ES - ID: 280192539 - is pit False
17:12:36:806 Added Symbol:ESZ22 to Request Margin Event -- validaMarginCalculationRequest Sucessful
[Traders_TraderError event] Contract is not subscribed or not found for Margin Calculator request
Edited by JKovalcin926 on Sep 23, 2022 12:23 PM
Edited by JKovalcin926 on Sep 23, 2022 12:26 PM
VPfau
Moderator
Posts: 164
Joined:


Posted: Sep 26, 2022 @ 07:57 AM             Msg. 8 of 8
Sorry, it is hard to understand what is going on based on lines above.
Can you provide a full example project that replicate the issue?
Vitaliy Pfau