Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Actually startup

  • Loading branch information...
commit 6e139066f6195e9d1d8f35e1c7d286e4c30cb25c 1 parent 6f4ced0
@kittylyst authored
View
3  .gitignore
@@ -1,4 +1,7 @@
*.class
+build/
+ide-bin/
+fix8on/
# Package Files #
*.war
View
5 README.md
@@ -29,3 +29,8 @@ So this style of application is well suited to a pipeline design utilising the b
of java.util.functions
Individual clients are configured up by using a JSON format to describe them.
+
+Start with:
+
+java -cp lib/mina-core-1.1.7.jar:lib/jackson-all-1.9.8.jar:lib/quickfixj-all-1.5.2.jar:lib/logback-core-1.0.6.jar:lib/slf4j-api-1.6.6.jar:build/jar/fix8on.jar fix8on.Main src/fix8on/config
+
View
2  build.xml
@@ -14,7 +14,7 @@
<javac srcdir="src" destdir="build/classes" classpathref="project.class.path"/>
</target>
- <target name="jar">
+ <target name="jar" depends="compile">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/fix8on.jar" basedir="build/classes">
<manifest>
View
BIN  lib/logback-core-1.0.6.jar
Binary file not shown
View
BIN  lib/mina-core-1.1.7.jar
Binary file not shown
View
BIN  lib/slf4j-api-1.6.6.jar
Binary file not shown
View
4 src/fix8on/DMAManager.java → src/fix8on/ClientsideManager.java
@@ -22,11 +22,11 @@
* @author boxcat
*
*/
-public class DMAManager implements Application {
+public class ClientsideManager implements Application {
private DefaultMessageFactory messageFactory = new DefaultMessageFactory();
- public DMAManager(SessionSettings settings, List<JsonNode> clientCfgs) {
+ public ClientsideManager(SessionSettings settings, List<JsonNode> clientCfgs) {
// TODO Auto-generated constructor stub
}
View
110 src/fix8on/Main.java
@@ -2,6 +2,14 @@
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.DirectoryStream;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;
@@ -21,48 +29,99 @@
import quickfix.ScreenLogFactory;
import quickfix.SessionSettings;
import quickfix.SocketAcceptor;
+import quickfix.SocketInitiator;
public class Main {
- private SocketAcceptor acceptor;
- private Application app;
+ private SocketAcceptor acceptor; // connections from clients
+ private SocketInitiator initiator; // sending stuff down to market
+ private Application clientsideMgr;
+ private Application marketsideMgr;
- private void init(String dirStr) throws ConfigError {
- // Convert to a Path
+ /**
+ * Helper class which finds the main config file and any client configuration files
+ *
+ * @author boxcat
+ *
+ */
+ private static class FindJsonVisitor extends SimpleFileVisitor<Path> {
+ private final List<Path> files = new ArrayList<>();
+ private String clientCfg;
+ private String mktCfg;
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
+ Path fileName = file.getFileName();
+ if (fileName.endsWith("client.cfg")) {
+ clientCfg = file.toAbsolutePath().toString();
+ } else if (fileName.endsWith("market.cfg")) {
+ mktCfg = file.toAbsolutePath().toString();
+ } else if (fileName.endsWith(".json")) {
+ files.add(file);
+ }
+ return FileVisitResult.CONTINUE;
+ }
+
+ public List<Path> getFiles() {
+ return files;
+ }
+
+ public String getClientsideCfg() {
+ return clientCfg;
+ }
+
+ public String getMarketsideCfg() {
+ return mktCfg;
+ }
+ }
+
+ private void init(String dirStr) throws ConfigError {
// Find all JSON objects
- List<File> clientFiles = new ArrayList<>();
-
- // Find main config
- JsonNode primaryCfg = createJsonObject(null);
+ FindJsonVisitor visitor = new FindJsonVisitor();
+ try {
+ Files.walkFileTree(Paths.get(dirStr), visitor);
+ } catch (IOException iox) {
+ throw new ConfigError(iox);
+ }
// Handle client configs
- List<JsonNode> clientCfgs = clientFiles.map(f -> createJsonObject(f)).into(new ArrayList<JsonNode>());
-
- // Configure up the acceptor
- SessionSettings settings = createSessionSettings(primaryCfg);
- app = new DMAManager(settings, clientCfgs);
- MessageStoreFactory msgStoreFactory = new FileStoreFactory(settings);
+ List<JsonNode> clientCfgs = visitor.getFiles().map(f -> createJsonObject(f)).into(new ArrayList<JsonNode>());
+ if (clientCfgs.contains(null)) throw new ConfigError("Malformed JSON file in config dir");
+
+ // Handle main config
+// System.out.println("Clientside: "+ visitor.getClientsideCfg());
+// System.out.println("Marketside: "+ visitor.getMarketsideCfg());
+ SessionSettings clientsideSettings = new SessionSettings(visitor.getClientsideCfg());
+ SessionSettings mktsideSettings = new SessionSettings(visitor.getMarketsideCfg());
+
+ // Configure up the acceptor - which will handle the transforms of incoming messages from clients
+ clientsideMgr = new ClientsideManager(clientsideSettings, clientCfgs);
+ MessageStoreFactory msgStoreFactory = new FileStoreFactory(clientsideSettings);
LogFactory logFactory = new ScreenLogFactory(true, true, true);
- DefaultMessageFactory msgFactory = new DefaultMessageFactory();
- acceptor = new SocketAcceptor(app, msgStoreFactory, settings,
- logFactory, msgFactory);
+ acceptor = new SocketAcceptor(clientsideMgr, msgStoreFactory, clientsideSettings,
+ logFactory, new DefaultMessageFactory());
+
+ //
+ marketsideMgr = new MarketsideManager(mktsideSettings, clientCfgs);
+ msgStoreFactory = new FileStoreFactory(mktsideSettings);
+// LogFactory logFactory = new ScreenLogFactory(true, true, true);
+
+ initiator = new SocketInitiator(marketsideMgr, msgStoreFactory, mktsideSettings,
+ logFactory, new DefaultMessageFactory());
}
- private static JsonNode createJsonObject(File f) throws ConfigError {
- String mainCfgStr = "";
-
- JsonNode primaryCfg;
+ private static JsonNode createJsonObject(Path p) {
+ JsonNode cfg;
try {
ObjectMapper mapper = new ObjectMapper();
- primaryCfg = mapper.readTree(mainCfgStr);
+ cfg = mapper.readTree(p.toFile());
} catch (IOException iox) {
- throw new ConfigError(iox);
+ // FIXME Log a config error here...
+ return null;
}
- return primaryCfg;
+ return cfg;
}
private SessionSettings createSessionSettings(JsonNode primaryCfg) {
@@ -94,6 +153,7 @@ public static void main(String[] args) throws RuntimeError, ConfigError {
* @throws ConfigError
*/
private void start() throws RuntimeError, ConfigError {
+ initiator.start();
acceptor.start();
}
@@ -102,6 +162,6 @@ private void start() throws RuntimeError, ConfigError {
*/
private void stop() {
acceptor.stop();
+ initiator.stop();
}
-
}
View
77 src/fix8on/MarketsideManager.java
@@ -0,0 +1,77 @@
+package fix8on;
+
+import java.util.List;
+
+import org.codehaus.jackson.JsonNode;
+
+import quickfix.Application;
+import quickfix.DefaultMessageFactory;
+import quickfix.DoNotSend;
+import quickfix.FieldNotFound;
+import quickfix.IncorrectDataFormat;
+import quickfix.IncorrectTagValue;
+import quickfix.Message;
+import quickfix.RejectLogon;
+import quickfix.SessionID;
+import quickfix.SessionSettings;
+import quickfix.UnsupportedMessageType;
+
+/**
+ * This appliaction only deals with a single version of FIX - FIX 4.4 for simplicity.
+ *
+ * @author boxcat
+ *
+ */
+public class MarketsideManager implements Application {
+
+ private DefaultMessageFactory messageFactory = new DefaultMessageFactory();
+
+ public MarketsideManager(SessionSettings settings, List<JsonNode> clientCfgs) {
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public void fromAdmin(Message arg0, SessionID arg1) throws FieldNotFound,
+ IncorrectDataFormat, IncorrectTagValue, RejectLogon {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void fromApp(Message arg0, SessionID arg1) throws FieldNotFound,
+ IncorrectDataFormat, IncorrectTagValue, UnsupportedMessageType {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onCreate(SessionID arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onLogon(SessionID arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onLogout(SessionID arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void toAdmin(Message arg0, SessionID arg1) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void toApp(Message arg0, SessionID arg1) throws DoNotSend {
+ // TODO Auto-generated method stub
+
+ }
+
+}
View
17 src/fix8on/config/client.cfg
@@ -0,0 +1,17 @@
+[default]
+FileStorePath=fix8on/data/client
+ConnectionType=acceptor
+StartTime=00:00:00
+EndTime=00:00:00
+HeartBtInt=30
+ValidOrderTypes=1,2,F
+SenderCompID=EXEC
+TargetCompID=FIX8ON
+UseDataDictionary=Y
+DefaultMarketPrice=12.30
+
+[session]
+BeginString=FIX.4.4
+SocketAcceptPort=9880
+
+
View
18 src/fix8on/config/market.cfg
@@ -0,0 +1,18 @@
+[default]
+FileStorePath=fix8on/data/market
+ConnectionType=initiator
+SenderCompID=FIX8ON
+TargetCompID=EXEC
+SocketConnectHost=elsewhere
+StartTime=00:00:00
+EndTime=00:00:00
+HeartBtInt=30
+ReconnectInterval=5
+
+[session]
+BeginString=FIX.4.4
+SocketConnectPort=9900
+
+
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.