Skip to content

Commit 8d6fd64

Browse files
authored
Add more helpful information to README (#203)
1 parent 21bec09 commit 8d6fd64

File tree

1 file changed

+198
-2
lines changed

1 file changed

+198
-2
lines changed

README.md

Lines changed: 198 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,210 @@ QuickFIX/J
66

77
This is the official QuickFIX/J project repository.
88

9+
## intro
10+
QuickFIX/J is a full featured messaging engine for the FIX protocol.
11+
It is a 100% Java open source implementation of the popular C++ QuickFIX engine.
12+
913
The Financial Information eXchange (FIX) protocol is a messaging standard developed
1014
specifically for the real-time electronic exchange of securities transactions.
1115
FIX is a public-domain specification owned and maintained by FIX Protocol, Ltd (FPL).
12-
QuickFIX/J is a full featured messaging engine for the FIX protocol.
13-
It is a 100% Java open source implementation of the popular C++ QuickFIX engine.
1416

1517
For more information see the project website at http://www.quickfixj.org.
1618

19+
## questions
1720
For asking questions please use the mailing list: https://lists.sourceforge.net/lists/listinfo/quickfixj-users
1821

22+
## issues
1923
Please report issues at http://www.quickfixj.org/jira.
24+
25+
## contributions
26+
27+
Pull requests are always welcome! Best is if you added a unit test to show that a certain bug has been fixed or a new feature works as expected.
28+
29+
## build instructions
30+
31+
Fastest: clone the repo and issue the following command.
32+
```
33+
$ mvn clean package -Dmaven.javadoc.skip=true -DskipTests
34+
```
35+
36+
Slower: if you only want to skip the acceptance test suite:
37+
```
38+
$ mvn clean package -Dmaven.javadoc.skip=true -DskipAT=true
39+
```
40+
41+
Slow: if you want to run all tests:
42+
```
43+
$ mvn clean package -Dmaven.javadoc.skip=true
44+
```
45+
46+
## basics
47+
48+
### Creating a QuickFIX/J application
49+
50+
Implement the `quickfix.Application` interface.
51+
52+
By implementing these interface methods in your derived class, you are requesting to be notified of events that occur on the FIX engine. The function that you should be most aware of is `fromApp`.
53+
54+
Here are explanations of what these functions provide for you.
55+
56+
`onCreate` is called when QFJ creates a new session. A session comes into and remains in existence for the life of the application. Sessions exist whether or not a counter party is connected to it. As soon as a session is created, you can begin sending messages to it. If no one is logged on, the messages will be sent at the time a connection is established with the counterparty.
57+
58+
`onLogon` notifies you when a valid logon has been established with a counter party. This is called when a connection has been established and the FIX logon process has completed with both parties exchanging valid logon messages.
59+
60+
`onLogout` notifies you when an FIX session is no longer online. This could happen during a normal logout exchange or because of a forced termination or a loss of network connection.
61+
62+
`toAdmin` provides you with a peek at the administrative messages that are being sent from your FIX engine to the counter party. This is normally not useful for an application however it is provided for any logging you may wish to do. Notice that the `quickfix.Message` is mutable. This allows you to add fields before an adminstrative message before it is sent out.
63+
64+
`toApp` is a callback for application messages that are being sent to a counterparty. If you throw a `DoNotSend` exception in this method, the application will not send the message. This is mostly useful if the application has been asked to resend a message such as an order that is no longer relevant for the current market. Messages that are being resent are marked with the `PossDupFlag` in the header set to true; If a `DoNotSend` exception is thrown and the flag is set to true, a sequence reset will be sent in place of the message. If it is set to false, the message will simply not be sent. Notice that the `quickfix.Message` is mutable. This allows you to add fields to an application message before it is sent out.
65+
66+
`fromAdmin` notifies you when an administrative message is sent from a counterparty to your FIX engine. This can be useful for doing extra validation on `Logon` messages such as for checking passwords. Throwing a `RejectLogon` exception will disconnect the counterparty.
67+
68+
`fromApp` is one of the core entry points for your FIX application. Every application level request will come through here. If, for example, your application is a sell-side OMS, this is where you will get your new order requests. If you were a buy side, you would get your execution reports here. If a `FieldNotFound` exception is thrown, the counterparty will receive a reject indicating a conditionally required field is missing. The `Message` class will throw this exception when trying to retrieve a missing field, so you will rarely need the throw this explicitly. You can also throw an `UnsupportedMessageType` exception. This will result in the counterparty getting a reject informing them your application cannot process those types of messages. An `IncorrectTagValue` can also be thrown if a field contains a value that is out of range or you do not support.
69+
70+
71+
The sample code below shows how you might start up a FIX acceptor which listens on a socket. If you wanted an initiator, you would simply replace the acceptor in this code fragment with a `SocketInitiator`. `ThreadedSocketInitiator` and `ThreadedSocketAcceptor` classes are also available. These will supply a thread to each session that is created. If you use these you must make sure your application is thread safe.
72+
73+
```
74+
import quickfix.*;
75+
import java.io.FileInputStream;
76+
77+
public class MyClass {
78+
79+
public static void main(String args[]) throws Exception {
80+
if (args.length != 1) return;
81+
String fileName = args[0];
82+
83+
// FooApplication is your class that implements the Application interface
84+
Application application = new FooApplication();
85+
86+
SessionSettings settings = new SessionSettings(new FileInputStream(fileName));
87+
MessageStoreFactory storeFactory = new FileStoreFactory(settings);
88+
LogFactory logFactory = new FileLogFactory(settings);
89+
MessageFactory messageFactory = new DefaultMessageFactory();
90+
Acceptor acceptor = new SocketAcceptor
91+
(application, storeFactory, settings, logFactory, messageFactory);
92+
acceptor.start();
93+
// while(condition == true) { do something; }
94+
acceptor.stop();
95+
}
96+
}
97+
```
98+
99+
### Receiving messages
100+
101+
Most of the messages you will be interested in looking at will be arriving in your overloaded `fromApp` method of your application. You can get fields out of messages with different degrees of type safety. The type in question here is the FIX message type.
102+
103+
When the application passes you a `Message` class, the Java type checker has no idea what specific FIX message it is, you must determine that dynamically. There is, however, a way we can make Java aware of this type information.
104+
105+
Keep in mind that all messages have a header and a trailer. If you want to see fields in them, you must first call `getHeader()` or `getTrailer()` to get access to them. Otherwise you access them just like in the message body.
106+
107+
QuickFIX/J has message classes that correlate to all the messages defined in the spec. They are, just like the field classes, generated directly off of the FIX specifications. To take advantage of this, you must break the messages out with the supplied `MessageCracker`.
108+
109+
```
110+
import quickfix.*;
111+
import quickfix.field.*;
112+
113+
public void fromApp(Message message, SessionID sessionID)
114+
throws FieldNotFound, UnsupportedMessageType, IncorrectTagValue {
115+
116+
crack(message, sessionID);
117+
}
118+
119+
public void onMessage(quickfix.fix42.NewOrderSingle message, SessionID sessionID)
120+
throws FieldNotFound, UnsupportedMessageType, IncorrectTagValue {
121+
122+
ClOrdID clOrdID = new ClOrdID();
123+
message.get(clOrdID);
124+
125+
ClearingAccount clearingAccount = new ClearingAccount();
126+
message.get(clearingAccount);
127+
}
128+
129+
public void onMessage(quickfix.fix42.OrderCancelRequest message, SessionID sessionID)
130+
throws FieldNotFound, UnsupportedMessageType, IncorrectTagValue {
131+
132+
ClOrdID clOrdID = new ClOrdID();
133+
message.get(clOrdID);
134+
135+
// compile time error!! field not defined for OrderCancelRequest
136+
ClearingAccount clearingAccount = new ClearingAccount();
137+
message.get(clearingAccount);
138+
}
139+
```
140+
141+
In order to use this you must use the `MessageCracker` as a mixin to your application. This will provide you with the `crack` method and allow you to overload specific message functions.
142+
143+
Any function you do not overload will by default throw an `UnsupportedMessageType` exception
144+
145+
146+
Define your application like this:
147+
148+
```
149+
import quickfix.Application;
150+
import quickfix.MessageCracker;
151+
152+
public class MyApplication extends MessageCracker implements quickfix.Application {
153+
public void fromApp(Message message, SessionID sessionID)
154+
throws FieldNotFound, UnsupportedMessageType, IncorrectTagValue {
155+
crack(message, sessionID);
156+
}
157+
158+
// Using annotation
159+
@Handler
160+
public void myEmailHandler(quickfix.fix50.Email email, SessionID sessionID) {
161+
// handler implementation
162+
}
163+
164+
// By convention (notice different version of FIX. It's an error to have two handlers for the same message)
165+
// Convention is "onMessage" method with message object as first argument and SessionID as second argument
166+
public void onMessage(quickfix.fix44.Email email, SessionID sessionID) {
167+
// handler implementation
168+
}
169+
}
170+
```
171+
172+
If you'd rather use composition rather than inheritance of the `MessageCracker` you can construct a message cracker with a delegate object. The delegate message handler methods will be automatically discovered.
173+
174+
Message crackers for each FIX version are still generated for backward compatibility but it's more efficient to define the specific handlers you need.
175+
176+
The generated classes define handlers for all messages defined by that version of FIX. This requires the JVM to load those classes when the cracker is loaded. Most applications only need to handle a small subset of the messages defined by a FIX version so loading all the messages classes is excessive overhead in those cases.
177+
178+
179+
### Sending messages
180+
181+
Messages can be sent to a counter party with one of the static `Session.sendToTarget` methods. This method has several signatures. They are:
182+
183+
```
184+
package quickfix;
185+
186+
public static boolean sendToTarget(Message message)
187+
throws SessionNotFound
188+
189+
public static boolean sendToTarget(Message message, SessionID sessionID)
190+
throws SessionNotFound
191+
192+
public static boolean sendToTarget
193+
(Message message, String senderCompID, String targetCompID)
194+
throws SessionNotFound
195+
```
196+
197+
The highly recommended method is to use the type safe message classes. This should typically be the only way you should ever have to create messages.
198+
199+
Here the constructor takes in all the required fields and adds the correct `MsgType` and `BeginString` for you. What's more, by using the `set` method instead of `setField`, the compiler will not let you add a field that is not a part of a `OrderCancelRequest` based on the FIX4.1 specs. Keep in mind that you can still use `setField` if you want to force any field you want into the message.
200+
201+
```
202+
import quickfix.*;
203+
204+
void sendOrderCancelRequest() throws SessionNotFound {
205+
quickfix.fix41.OrderCancelRequest message = new quickfix.fix41.OrderCancelRequest(
206+
new OrigClOrdID("123"),
207+
new ClOrdID("321"),
208+
new Symbol("LNUX"),
209+
new Side(Side.BUY));
210+
211+
message.set(new Text("Cancel My Order!"));
212+
213+
Session.sendToTarget(message, "TW", "TARGET");
214+
}
215+
```

0 commit comments

Comments
 (0)