Quickfix/j (2): Receiving and sending messages

Source: Internet
Author: User
quickfix/j Session

All messages sent and received by QJ are based on sessions. In the configuration file we see two tags: sendercompid/targetcompid, just like the message that is passed literally, it represents the target party and initiator of the receiving session.

"Clinet"
Connectiontype=initiator
Sendercompid=flyzhang
Targetcompid=fixserver
beginstring=fix4.4 (the version number of the fix protocol based on the session)
"Server"
Connectiontype=acceptor
Sendercompid=fixserver
targetcompid=*
beginstring=fix4.4 (Session based on the Fix Protocol version number) quickfix/j initiating/Feedback request Information

When creating a message, it needs to be constructed strictly according to the field description (whether required, type, etc.) in the message label in Fix44.xml;
Otherwise, it will be denied service by the server side. New Order Request

Quickfix.fix44.NewOrderSingle newordersinglerequest = new Quickfix.fix44.NewOrderSingle ();
        Newordersinglerequest.set (New Clordid ("QSD"));
        Newordersinglerequest.set (New OrderQty (1));
        Newordersinglerequest.set (New Ordtype (' 2 '));
        Newordersinglerequest.set (new price);
        Newordersinglerequest.set (New Side (' 1 '));
        Newordersinglerequest.set (New Symbol ("LTC/CNY"));
        Newordersinglerequest.set (New Transacttime ());
        Session.send (newordersinglerequest);
Fix return information label Description

Fix Standard protocol number

http://www.onixs.biz/fix-dictionary/4.4/fields_by_tag.html messagecracker function

The landlord recently in writing fix procedure, always do not understand what to do with it; the recent free look at the source found that its main role is to the message for streaming. It can be understood that a simple factory pattern calls different handle methods for different meeage.

@Handler
protected void Marketdatarequesthandle (Quickfix.fix44.MarketDataRequest message, SessionID SessionID);
@Handler
protected void Newordersinglehandle (Quickfix.fix44.NewOrderSingle message  , SessionID SessionID);
......

Calling this method public
void Fromapp (Quickfix) When a business message is received. Message message, SessionID SessionID) {
        crack (message, SessionID);
    }

 public void crack (Quickfix. Message message, SessionID SessionID) {
        //source code we will find that in the initialization messagecaker called the Initialize method loaded Invokers set
        invoker Invoker = Invokers.get (Message.getclass ()); Gets if there is no corresponding handle 
        if (invoker!= null) {
            invoker. Invoke (message, SessionID); 
        } else {
            onMessage (message, SessionID);//If the underlying method is not invoked
        }
applaction Full Demo
Import Quickfix. Application;
Import Quickfix. Messagecracker;
public class MyApplication extends Messagecracker implements Quickfix. Application
{public
    void Fromapp (Message message, SessionID SessionID)
          throws Fieldnotfound, Unsupportedmessagetype, Incorrecttagvalue {
      crack (message, SessionID);
    }
    Use annotation annotations to handle email_message
    @Handler public
    void Myemailhandler (Quickfix.fix50.Email Email, SessionID SessionID) {
         //handler implementation
    }
    //default public
    void OnMessage (Quickfix.fix44.Email Email, SessionID SessionID) {
        //handler implementation
    }
}
Message Sending There are two ways to send messages
The first way
session.sendtotarget (message, "Sendercompid", "targetcompid");

The second way sessions session
= Session.lookupsession (SessionID);
Session.send (message);
use fix Group to send information

In the actual business, we often encounter to send "collection" information, such as multiple order information, bulk query.
FIX provides us with a group label that can be used for related operations.

Marketdatasnapshotfullrefresh marketdata = new Marketdatasnapshotfullrefresh (); 
    Marketdata.set (new symbol ("symbol"));
    Marketdata.set (New Mdreqid ("Mdreqid"));
    for (Trade trade:trades) {////group collection of transactions in the landlord's business
        , in the next article, explain how to customize your group label
            Marketdatasnapshotfullrefresh.nomdentries trade = new Marketdatasnapshotfullrefresh.nomdentries ();
             Trade. Set (New Mdentrytype (' 2 '));
             Trade. Set (new MDENTRYPX (1));
             Trade. Set (new Mdentrysize (1));
             Trade. Set (New OrderID ("5569998"));
             Add the data to the quotes data
         marketdata. AddGroup (trade);
           

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.