2017-03-12 58 views
0
# Here is my settings.cfg file: 
# Thank you.Here is what i tried.My settings.cfg file 

[DEFAULT] 
# Settings which apply to all the Sessions. 
ConnectionType=initiator 
LogonTimeout=30 
ReconnectInterval=20 
ResetOnLogon=Y 
FileLogPath=C:\Work\QuickFIXJ\logs 
FileStorePath=C:\Work\QuickFIXJ\logs 

[SESSION] 
# Settings specifically for one session 
BeginString=FIX.4.4 
SenderCompID=XYZ 
TargetCompID=TYZ 
TimeZone=Asia/Tokyo 
StartTime=16:00:00 
EndTime=13:30:00 
HeartBtInt=60 
SocketConnectPort=7200 
SocketConnectHost=123.123.123.123 
UseDataDictionary=Y 
DataDictionary=C:\Work\QuickFIXJ\datadictionary\FIX44.xml 

[GATEWAY] 
Port=4444 

[TRANSPORT] 
Port=4444 

然後FIX:如何發送,使用FIX消息,quickfixj

//initiator code: 

public class TestQuickFixJConnectivity { 
    public static void main(String[] args) { 
     SocketInitiator socketInitiator = null; 
     try { 
      SessionSettings sessionSettings = new SessionSettings("C:\\Work\\QuickFixJ\\sessionSettings.txt"); 
      Application application = new TestApplicationImpl(); 
      FileStoreFactory fileStoreFactory = new FileStoreFactory(sessionSettings); 
      FileLogFactory logFactory = new FileLogFactory(sessionSettings); 
      MessageFactory messageFactory = new DefaultMessageFactory(); 
      socketInitiator = new SocketInitiator(application, 
        fileStoreFactory, sessionSettings, logFactory, 
        messageFactory); 
      socketInitiator.start(); 
      SessionID sessionId = socketInitiator.getSessions().get(0); 
      sendLogonRequest(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 sendLogonRequest(SessionID sessionId) throws SessionNotFound { 
     Logon logon = new Logon(); 
     Message msg=new Message(); 
     Header header = msg.getHeader(); 
     logon.set(new HeartBtInt(60)); 
     logon.set(new ResetSeqNumFlag(true)); 
     header.setField(new BeginString("FIX.4.4")); 
     header.setField(new MsgType("AP")); 
     header.setField(new SenderCompId("XYZ")); 
     header.setField(new TagetCompId("TYZ")); 
     header.setField(new ResetSeqNumFlag(true)); 
     //here i m setting all the fields in the csv report . 
     msg.setField(705,new SortQty("")); 
     // .... 
     //below statement returning false 
     boolean sent = Session.sendToTarget(msg, sessionId); 
     System.out.println("Logon Message Sent : " + sent); 
    } 
} 

請在下面找到我的意見:

在事件日誌中我看到了作爲創建的會話:和消息我正在嘗試發送。另外我可以看到發件人序列號在日誌中增加。

Messages.log和header.logs是空白的,body.log中有我正在發送的消息。

當我嘗試運行代碼時,onCreate和ToApp也被調用。

我想知道我是否已成功發送消息?

boolean sent = Session.sendToTarget(msg, sessionId); is returning false

我看不到在我的代碼中執行ToAdmin和FromAdmin。另外我是否也需要編寫接受者代碼,或者只是發起者代碼就可以。我正在使用的DataDictionary有所有的字段集,但我不確定當我嘗試執行代碼時它是否被QuickFixJ使用。

請告知這是怎麼回事?

回答

1

OK設置文件看起來不錯,你是說它的工作原理,但我不認爲你需要網關和運輸標題

至於你的代碼,你需要做的,開始與機的安裝默認的QuickFIX應用程序,FileStoreFactory,LogFactory,MessageFactory和Initiator。

默認的QuickFIX自動登錄到您的設置文件中的目標,並且如果登錄被接受,則它開始心跳。從你的評論看來,這聽起來像是在發生。

那麼怎麼回事你的sendLogonRequest是沒有必要的。另外,如果您確實發送了「額外」登錄,那麼目標FIX引擎可能會拒絕或忽略它們。拒絕消息將在日誌或文件存儲中顯示。

那麼你有QuickFIX的API,你可以簡單地輸出消息到你自己的日誌。

像這樣的事情

public void fromApp(Message msg, SessionID s) throws UnsupportedMessageType, FieldNotFound, IncorrectTagValue 
{ 
    log.debug(String.valueOf(LocalTime.now()) + " INITIATOR: FromApp " + msg.toString()); 
} 
public void toApp(Message msg, SessionID s) 
{ 
    log.info(String.valueOf(LocalTime.now()) + " INITIATOR: ToApp " + msg.toString()); 
} 
public void fromAdmin(Message msg, SessionID s) throws FieldNotFound, IncorrectTagValue 
{ 
    Log.trace("INITIATOR: FromAdmin " + msg.getClass() + " " + msg.toString());  
} 
public void onCreate(SessionID s) 
{ 
    log.info("INITIATOR: OnCreate " + s.toString()); 
}  
public void onLogout(SessionID s) 
{ 
    log.error("INITIATOR: OnLogout " + s.toString()); 
} 
public void onLogon(SessionID s) 
{ 
    log.info("INITIATOR: OnLogon " + s.toString()); 
}  
public void toAdmin(Message msg, SessionID s) 
{ 
    log.trace("INITIATOR: ToAdmin " + msg.getClass() + " " + msg.toString()); 
} 

然後,當你想發送的消息,嘗試這樣的事情:

QuoteReqID id = new QuoteReqID("1234"); 

    // Create Quote Request message 
    QuoteRequest qr = new QuoteRequest(id); 

    // Setup outgoing group and specify an index for each group tag 
    NoRelatedSym g = new NoRelatedSym(); 

    String instrument = m.getString("EUR/USD"); 
    Symbol symbol = new Symbol(instrument);  
    g.setField(1, symbol); 

    QuoteRequestType qt = new QuoteRequestType(102); 
    g.setField(2, qt); 

    OrderQty qty = new OrderQty("1000000"); 
    g.setField(3, qty); 

    SettlType sType = new SettlType("B"); 
    g.setField(4, sType); 

    SettlDate sDate = new SettlDate("20170315"); 
    g.setField(5, sDate); 

    Account account = new Account("357647"); 
    g.setField(6, account); 

    // add group to request 
    qr.addGroup(g); 

    Session s = Session.lookupSession(i.getSessions().get(0)); 
    s.send(qr); 
+0

謝謝:)我在我的代碼所做的更改,試圖發送消息。 。我的代碼不會調用toadmin和從管理員,它只是調用toapp ...是有必要在發送應用程序消息(這裏我試圖發送msgtype = AP)之前發送登錄msgtype = A。我怎樣才能知道我的郵件是否成功發送。 – Kini

+0

「如果登錄成功,它會開始心跳」我怎麼知道這一點?通過日誌文件中的標籤號? – Kini

+0

是的那些聲音我喜歡心跳......你需要做的是從你的對手方得到訂婚的FIX規則,並開始向他們請求不同類型的消息...... – rupweb