2

After opening an order with our brokerage firm, we desire to obtain the fill price from the ExecutionReport messages. Below you will find the callback code used.

The MarketDataSnapshotFullRefresh messages are received properly, but the second if block is never triggered. Strangely, the corresponding messages.log file does contain multiple 35=8 messages.

We use QuickFIX/J as FIX engine.

@Override
public void fromApp(Message message, SessionID sessionID) throws FieldNotFound, IncorrectDataFormat, IncorrectTagValue, UnsupportedMessageType {
    if (message instanceof MarketDataSnapshotFullRefresh) {
        // do stuff with MarketDataSnapshotFullRefresh
    }

    if(message instanceof ExecutionReport) {
        // do stuff with ExecutionReport
    }
4

2 回答 2

3

消息处理理想地由 a 完成quickfix.MessageCracker,尽管有时处理它们fromApp是要走的路。

您可以在此处阅读有关消息破解的更多信息:QuickFIX/J 用户手册 - 接收消息

我将概述两种方式:


  1. fromApp

    传入的消息fromApp不是 QuickFIX/J 库中定义的特定消息类型,而是quickfix.Message. 如果您想以现在的方式(从fromApp)处理它们,则必须MsgType手动检查:

    MsgType msgType = (MsgType) message.getHeader( ).getField( new MsgType( ) );
    

    根据检索到的类型,您将调用特定消息类型的处理程序方法:

    if( msgType.valueEquals( MsgType.MARKET_DATA_SNAPSHOT_FULL_REFRESH ) )
        handleMarketDataSnapshotFullRefresh( message, sessionID );
    else if ...
    
    ...
    
    private void handleMarketDataSnapshotFullRefresh( quickfix.Message msg, SessionID sessionID ) {
        // handler implementation
    }
    

  1. 使用MessageCracker

    如前所述,处理传入消息的另一种方法是通过 MessageCracker. 例如,您可以扩展使用 实现的quickfix.Applicationquickfix.MessageCracker

    添加一个onMessage带有两个参数的方法,第一个是消息类型,第二个是 SessionID。crackfromApp将路由到适当处理程序的方法调用。

    import quickfix.*;
    
    public class MyApplication extends MessageCracker implements Application
    {
        public void fromApp(Message message, SessionID sessionID)
              throws FieldNotFound, UnsupportedMessageType, IncorrectTagValue {
              crack(message, sessionID);
        }
    
        @Handler
        public void onMessage(quickfix.fix44.MarketDataSnapshotFullRefresh mdsfr, SessionID sessionID) {
             // handler implementation
        }
    }
    
于 2016-03-04T20:34:32.733 回答
2

你为什么在错误的地方进行消息处理?如果您查看 Quickfix 推荐的内容,您会看到他们建议在onMessage其中进行消息处理(您可能尚未实现)。并且 fromApp 方法中应该只存在一个消息破解程序。

否则,您的 fromApp 方法将成为一大堆代码,而下一个处理您的代码的人将不会是一个快乐的人。

于 2016-03-04T17:57:50.033 回答