如何解决 quickfixj 的市场数据请求

how to solve market data request for quickfixj

我是修复传输的新手,我尝试使用 java 与我的代理建立连接。我的 运行ning 我的 java 市场数据请求应用程序有问题。

这里是我的主要classjava

public class FastmatchMDRequest {
 public static void main(String[] args) {
        SocketInitiator socketInitiator = null;
        try {
             InputStream inputStream = null;
             if (args.length == 0) {
                 inputStream = FastmatchMDRequest.class.getResourceAsStream("initiator.cfg");
             } else if (args.length == 1) {
                 inputStream = new FileInputStream(args[0]);
             }
             if (inputStream == null) {
                 System.out.println("usage: " + FastmatchMDRequest.class.getName() + " [configFile].");
                 return;
             }
             SessionSettings settings = new SessionSettings(inputStream);
             inputStream.close();
            Application application = new TestMarketdataRequest();
            FileStoreFactory fileStoreFactory = new FileStoreFactory(settings);
            FileLogFactory logFactory = new FileLogFactory(settings);
            MessageFactory messageFactory = new DefaultMessageFactory();
            socketInitiator = new SocketInitiator(application,
                    fileStoreFactory, settings, logFactory,
                    messageFactory);
            socketInitiator.start();
            SessionID sessionId = socketInitiator.getSessions().get(0);
            sendMarkeDataRequest(sessionId);
            int i = 0;
            do {
                try {
                    Thread.sleep(1000);
                    System.out.println(socketInitiator.isLoggedOn());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                i++;
            } while ((!socketInitiator.isLoggedOn()) && (i < 30));
        } catch (ConfigError e) {
            e.printStackTrace();
        } catch (SessionNotFound e) {
            e.printStackTrace();
        } catch (Exception exp) {
            exp.printStackTrace();
        } finally {
            if (socketInitiator != null) {
                socketInitiator.stop(true);
            }
        }
    }
    private static void sendMarkeDataRequest(SessionID sessionId)
            throws SessionNotFound {
        UUID uuid = UUID.randomUUID();
        String randomUUIDString = uuid.toString();
        Message message = new Message();
        quickfix.fix42.MarketDataRequest.NoMDEntryTypes group =
                  new quickfix.fix42.MarketDataRequest.NoMDEntryTypes();
        quickfix.fix42.MarketDataRequest.NoRelatedSym group1 =
                  new quickfix.fix42.MarketDataRequest.NoRelatedSym();
        MarketDataRequest marketdatarequest = new MarketDataRequest();
        Header header = marketdatarequest.getHeader();
        header.setField(new BeginString("FIX.4.2"));
          header.setField(new SenderCompID("Mycomp"));
          header.setField(new TargetCompID("mybroker"));
          header.setField(new MsgType("V"));
          message.setField(new MDReqID(randomUUIDString));
          message.setField(new SubscriptionRequestType((char) 1));
          message.setField(new MarketDepth(1));
          message.setField(new NoMDEntryTypes(1));
          group.setField(new MDEntryType((char) 1));
          message.addGroup(group);
          group1.setField(new Symbol("ALL"));
          message.addGroup(group1);
          try
          {
          Session.sendToTarget(message);
          System.out.println("message" + message);
          }catch (Exception ex)
          {
              System.out.println("error" + ex);
              }
    }}

申请class

public class TestMarketdataRequest implements Application {

public void fromAdmin(quickfix.Message arg0, SessionID arg1)
        throws FieldNotFound, IncorrectDataFormat, IncorrectTagValue, RejectLogon {
    // TODO Auto-generated method stub
    System.out.println("Successfully called fromAdmin for sessionId : "
            + arg0);
}

public void fromApp(quickfix.Message arg0, SessionID arg1)
        throws FieldNotFound, IncorrectDataFormat, IncorrectTagValue, UnsupportedMessageType {
    // TODO Auto-generated method stub
    System.out.println("Successfully called fromApp for sessionId : "
            + arg0);
}
public void onCreate(SessionID sessionID) {
    // TODO Auto-generated method stub
    System.out.println("Successfully called onCreate for sessionId : "
            + sessionID);
}

public void onLogon(SessionID sessionID) {
    // TODO Auto-generated method stub
    System.out.println("Successfully logged on for sessionId : " + sessionID);
}

public void onLogout(SessionID sessionID) {
    // TODO Auto-generated method stub
    System.out.println("Successfully logged out for sessionId : " + sessionID);
}

public void toAdmin(quickfix.Message message, SessionID sessionID) {
    // TODO Auto-generated method stub
     System.out.println("Inside toAdmin");
}

public void toApp(quickfix.Message message, SessionID sessionID) throws DoNotSend {
    // TODO Auto-generated method stub
    System.out.println("Message : " + message + " for sessionid : " + sessionID);
}

public void onMessage(MarketDataIncrementalRefresh message, SessionID sessionID)
        throws FieldNotFound, UnsupportedMessageType, IncorrectTagValue {
    System.out.println("Inside onMessage for New Order Single" + message + sessionID);
}
public void MarketDataIncrementalRefresh (Message message, SessionID sessionID) throws FieldNotFound{
     try
       {
           MDReqID mdreqid = new MDReqID();
           SendingTime sendingtime = new SendingTime();
           NoMDEntries nomdentries = new NoMDEntries();
           quickfix.fix42.MarketDataIncrementalRefresh.NoMDEntries group
               = new quickfix.fix42.MarketDataIncrementalRefresh.NoMDEntries();
           MDUpdateAction mdupdateaction = new MDUpdateAction();
           DeleteReason deletereason = new DeleteReason();
           MDEntryType mdentrytype = new MDEntryType();
           MDEntryID mdentryid = new MDEntryID();
           Symbol symbol = new Symbol();
           MDEntryOriginator mdentryoriginator = new MDEntryOriginator();
           MDEntryPx mdentrypx = new MDEntryPx();
           Currency currency = new Currency();
           MDEntrySize mdentrysize = new MDEntrySize();
           ExpireDate expiredate = new ExpireDate();
           ExpireTime expiretime = new ExpireTime();
           NumberOfOrders numberoforders = new NumberOfOrders();
           MDEntryPositionNo mdentrypositionno = new MDEntryPositionNo();

           message.getField(nomdentries);
           message.getField(sendingtime);

           message.getGroup(1, group);

           int list = nomdentries.getValue();
           for (int i = 0; i < list; i++)
           {
               message.getGroup(i + 1, group);
               group.get(mdupdateaction);
               if (mdupdateaction.getValue() == '2')
                System.out.println("Enter");
               group.get(deletereason);
               group.get(mdentrytype);
               group.get(mdentryid);
               group.get(symbol);
               group.get(mdentryoriginator);
               if (mdupdateaction.getValue() == '0')
                   group.get(mdentrypx);
               group.get(currency);
               if (mdupdateaction.getValue() == '0')
                   group.get(mdentrysize);
           }

           System.out.printf("Got Symbol {0} Price {1}", 
       symbol.getValue(), mdentrypx.getValue());

}catch (Exception ex)
       {
    System.out.println("error" + ex);
  }
  }
   public void MarketDataSnapshotFullRefresh (Message message,    SessionID sessionID) throws FieldNotFound{

    String Symbol = message.getField(new Symbol()).getValue();

    NoMDEntries noMDEntries = new NoMDEntries();
    message.getField(noMDEntries);
    quickfix.fix42.MarketDataSnapshotFullRefresh.NoMDEntries group =
      new quickfix.fix42.MarketDataSnapshotFullRefresh.NoMDEntries();
    MDEntryType MDEntryType = new MDEntryType();
    MDEntryPx MDEntryPx = new MDEntryPx();
    MDEntrySize MDEntrySize = new MDEntrySize();
    SendingTime sendingTime = new SendingTime();

    message.getField(sendingTime);

    message.getGroup(1, group);
    group.get(MDEntryType);
    group.get(MDEntryPx);
    group.get(MDEntrySize);

    message.getGroup(2, group);
    group.get(MDEntryType);
    group.get(MDEntryPx);
    group.get(MDEntrySize);

    System.out.printf("Symbol {0} Price {1}", Symbol, MDEntryPx);
        }

我在我的 pom.xml 中为 quickfixj 等添加了工件,但是当我构建为 jar 和 运行 jar 应用程序时,我收到了类似

的错误
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: quickfix/SessionNotFound
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: quickfix.SessionNotFound
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
... 7 more

如何解决我的构建市场数据请求问题? 最好的问候,

福阿德

尝试通过在 pom.xml

中添加以下插件来创建具有依赖项的 executable/fat jar
<build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>fully.qualified.MainClass</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
    </plugin>
  </plugins>
</build>