API Support Forum
OEC API > API Support > Order Breaks Limits - Details
Author Topic: Order Breaks Limits - Details
(7 messages, Page 1 of 1)
Moderators: VPfau
RAhlander
Posts: 13
Joined: Jul 13, 2023


Posted: May 14, 2024 @ 12:49 PM             Msg. 1 of 7
Hello,

Using the C# API. When I submit an order, I get an "Order Breaks Limits" comment. How can I get the actual reason so I understand how to fix the order?

Thanks
CMicciche902
Posts: 367
Joined:


Posted: May 14, 2024 @ 12:59 PM             Msg. 2 of 7
Per https://gainfutures.com/GFAPI/?topic=html/9900566b-260a-4247-8326-9698b013e7b8.htm#SecOrders

Risk Violations
If your order is rejected, you can find the reason in ResultComments.

To get more details about a risk violation rejection, you can capture messages in the OnError event:

OnError
Copy
private static void Main(GF.Api.IGFClient client)
{
client.Logging.ErrorOccurred += GFClient_OnErrorOccurred;
}

private static void GFClient_OnErrorOccurred(GF.Api.IGFClient client, GF.Api.Utils.ErrorEventArgs e)
{
Console.WriteLine($"OnError: {e.Exception.Message}");
}
Risk violation text will look like this:

Risk violation: 1540:API001540 Max credit = 0.0000000000 USD,Order requires [3600.00000 USD] and needs additional credit of 130.00000 USD (cash leveraged) Cash and credit balance 125.00000 USD ...
where 1540 is AccountID and API001540 is Spec.
Chris M
RAhlander
Posts: 13
Joined: Jul 13, 2023


Posted: May 14, 2024 @ 01:23 PM             Msg. 3 of 7
Thanks for the reply.

I'm already doing this as instructed in the documentation, however, I am not getting any Logging events. I'm getting Connection.Aggregate events, Client.Orders Events, etc. However, these Logging events are never fired. Are these error details not stored anywhere on the order object? Can you think of a reason my Logging events are not fired?

Here is my setup:

private readonly ILogger _logger;
private readonly GF.Api.IGFClient _gfClient = GF.Api.Impl.GFApi.CreateClient();

private readonly GFClientRunner _runner;

public GainSystemService(ILogger logger)
{
_logger = logger;
_logger.LogDebug("Creating GainSystem Object");
_runner = new GFClientRunner(_gfClient);
_gfClient.Connection.Aggregate.LoginCompleted += (client, e) => _logger.LogInformation("Connection complete");
_gfClient.Connection.Aggregate.LoginFailed += (client, e) => _logger.LogInformation($"Connection failed: {e.FailReason}");
_gfClient.Connection.Aggregate.Disconnected += (client, e) => _logger.LogInformation($"Disconnected: {e.Message}");
_gfClient.Logging.ErrorOccurred += (client, e) => _logger.LogInformation($"Error Occurred: {e.Exception.Message}");
_gfClient.Logging.NewMessageLogged += (client, e) => _logger.LogInformation($"Message Logged: {e.Message}");
}

Can you see any issues with this setup? Again, I'm getting logs from Connection.Aggregate events but not Logging events.
RAhlander
Posts: 13
Joined: Jul 13, 2023


Posted: May 14, 2024 @ 01:49 PM             Msg. 4 of 7
Update.

When I add:

_gfClient.Logging.SetCategories(GF.Api.Logging.LogCategory.All);

I start getting events from NewMessageLogged, but never ErrorOccurred even though I got rejected order with "Order breaks limits." I can't even get an order placed using Gain Trader, same error. I have zero positions.
CMicciche902
Posts: 367
Joined:


Posted: May 15, 2024 @ 08:49 AM             Msg. 5 of 7
Our developers are looking into the matter.
Chris M
RAhlander
Posts: 13
Joined: Jul 13, 2023


Posted: May 16, 2024 @ 10:26 AM             Msg. 6 of 7
Update.

I am getting system messages from the Logging.NewMessageLogged when I get a "Order Breaks Limits" error. I have yet to the Logging.ErrorOccurred event to fire.
DRylskiy1654
Posts: 1
Joined:


Posted: May 20, 2024 @ 08:56 AM             Msg. 7 of 7
You can catch errors using this mechanism:


private void RegisterHandlers()
{
Client.Traders.TraderError += TraderError;
}

private void TraderError(IGFClient client, TraderErrorEventArgs e)
{
Console.WriteLine(e.Message);
}


If you installed GFAPI v4.12.305.1903, you need to use this mechanism:


private void RegisterHandlers()
{
Client.ServerErrors.Error += ServerError;
}

private void ServerError(IGFClient client, ServerErrorEventArgs e)
{
Console.WriteLine(e.Message);
}