Fed*_*ede 4 field exception quickfix fix-protocol quickfixn
我正在编写一个基于Quickfix/N的 FIX 引擎,它监听交易执行(ExecutionReport)并将其保存到数据库中。
如果接收到的消息中不存在该值,则从 API 请求字段值会引发 FieldNotFoundException。例如,如果帐户不存在,则调用executionReport.Account 将引发异常。
由于某些字段是可选的,因此我必须在获取字段值之前明确检查该字段值是否存在。我对此有两种可能性:
可能性一:
executionReport.IsSetAccount() ? executionReport.Account : null;
可能性2:
try
{
return executionReport.Account.getValue();
}
catch (Exception e)
{
return null;
}
Run Code Online (Sandbox Code Playgroud)
第一个选项很干净,但我发现它真的很重,第二个选项可以概括为辅助函数,但它违背了 API 哲学,我感觉我做错了什么。
那么我的问题是:
或者我对协议/API的理解完全错误?我感觉我没有以正确的方式解决这个问题。
多谢
您还没有真正说明为什么您认为这些不干净,所以我不确定您到底在寻找什么。
我能想到的唯一选择是:
// Both these lines are functionally identical.
executionReport.IsSetField(1)
executionReport.IsSetField(QuickFix.Fields.Tags.Account)
// 1 is the tag for Account.
// The second line just uses the tag enum to get 1
// instead of hardcoding the int.
Run Code Online (Sandbox Code Playgroud)
那个更好吗?
| 归档时间: |
|
| 查看次数: |
3639 次 |
| 最近记录: |