I'm writting a FIX Engine based on Quickfix/N that listen for trade Executions (ExecutionReport) and save them into a database.
Requesting a field value from the API throws a FieldNotFoundException if the value is not present in the received message. By example calling executionReport.Account will throw the exception if the account is not present.
As some fields are optional, I have to explicitely check for the existence of the field value before getting it. I have two possibilities for that:
Possibility 1:
executionReport.IsSetAccount() ? executionReport.Account : null;
Possibility 2:
try
{
return executionReport.Account.getValue();
}
catch (Exception e)
{
return null;
}
The first option is clean but I find it really heavy, the second can be generalized into an helper function but It goes against the API philosophy and I have the feeling I do something wrong.
Then my question is:
- Is there another clean/correct way to do the job?
Or is my comprehension of the Protocol/API totally wrong ? I have the feeling I don't get the problem in the right way.
Thanks a lot