Samples :: FIXML Converter

Fixml Converter Sample

Description

This sample demonstrates how to convert FIX message to FIXML message and vice versa.

Directory Structure

Item Description
conf/sample sample data
conf/sample/schema FIXML schema documents
conf/logback.xml logger configuration

Usage

  • Run the sample:
    • win: FixmlConverterSample.bat
    • linux: FixmlConverterSample.sh
  • Clean everything:
    • win: clean.bat
    • linux: clean.sh

Source Code

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import biz.onixs.fix.dictionary.Version;
import biz.onixs.fix.engine.Engine;
import biz.onixs.fix.fixml.FixmlConverter;
import biz.onixs.fix.parser.Message;
import biz.onixs.fix.fixml.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
  
public class FixmlConverterSample {
    private static final Logger LOG = LoggerFactory.getLogger(FixmlConverterSample.class);
  
    public static void main(final String[] args) throws Exception {
        final Engine engine = Engine.init(-1);
        final FixmlConverter converter = new FixmlConverter(Version.FIX44);
        //
        final String inFixFile = "sample/Order.txt";
        LOG.info("Loading FIX message from file: {}", inFixFile);
        final Message inFixMessage = Utils.readFixMessage(inFixFile);
        LOG.info("Input FIX message: {}", inFixMessage);
        final String fixmlMessage = converter.fix2fixml(inFixMessage);
        LOG.info("Output converted FIXML message: {}", fixmlMessage);
        //
        final String inFixmlFile = "sample/ExecRpt.xml";
        LOG.info("Loading FIXML message from file: {}", inFixmlFile);
        final String inFixmlMessage = Utils.readFixmlMessage(inFixmlFile);
        LOG.info("Input FIXML message: {}", inFixmlMessage);
        final Message outFixMessage = converter.fixml2fix(fixmlMessage);
        LOG.info("Output converted FIX message: {}", outFixMessage);
        //
        engine.shutdown();
    }
}

Custom Repeating Group Sample

Description

This sample demonstrates how to convert FIX message to FIXML message. Customized FIXML schema is used.

Directory Structure

Item Description
conf/sample sample data
conf/sample/schema2 FIXML schema documents
conf/logback.xml logger configuration

Usage

  • Run the sample:
    • win: CustomRepeatingGroupSample.bat
    • linux: CustomRepeatingGroupSample.sh
  • Clean everything:
    • win: clean.bat
    • linux: clean.sh

Source Code

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import biz.onixs.fix.dictionary.Version;
import biz.onixs.fix.engine.Engine;
import biz.onixs.fix.engine.EngineSettings;
import biz.onixs.fix.fixml.FixmlConverter;
import biz.onixs.fix.fixml.Utils;
import biz.onixs.fix.parser.Group;
import biz.onixs.fix.parser.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
  
import java.io.File;
  
/**
 * Custom repeating group sample.
 *
 * Changes in the FIXML schemas are made in the following files:
 * conf/schema2/fixml-components-base-4-4.xsd
 * conf/schema2/fixml-fields-base-4-4.xsd
 *
 * Changes are surrounded with the "Sample changes" comment.
 */
public class CustomRepeatingGroupSample {
    private static final Logger LOG = LoggerFactory.getLogger(CustomRepeatingGroupSample.class);
  
    public static void main(final String[] args) throws Exception {
        final EngineSettings engineSettings = new EngineSettings()
                .setListenPorts("-1")
                .setDialects("sample/dialect.xml");
        Engine.init(engineSettings);
        //
        final File file = new File("conf/sample/schema2/fixml-main-4-4.xsd");
        final FixmlConverter converter = new FixmlConverter(file.toURI().toString(), Version.FIX44);
        // Adding custom repeating group
        converter.addCustomRepeatingGroup(10000, "CustomIdGrp_Block_t");
        //
        final String fixFile = "sample/Quot.txt";
        LOG.info("Loading FIX message from file: " + fixFile);
        final Message fixMessage = Utils.readFixMessage(fixFile);
        LOG.info("FIX message: {}", fixMessage);
        printRepeatingGroup711(fixMessage);
        final String fixmlMessage = converter.fix2fixml(fixMessage);
        LOG.info("Converted FIXML message: {}", fixmlMessage);
        //
        Engine.getInstance().shutdown();
    }
  
    private static void printRepeatingGroup711(final Message message) {
        final Group group711 = message.getGroup(711);
        if (null != group711) {
            LOG.info("Repeating group 711 instance number: {}", group711.getNumberOfInstances());
            for (int i = 0; i < group711.getNumberOfInstances(); i++) {
                LOG.info("  Repeating group 711, instance #{}", i);
                final Group group10000 = group711.getGroup(10000, i);
                if (null != group10000) {
                    for (int j = 0; j < group10000.getNumberOfInstances(); j++) {
                        LOG.info("    Repeating group 10000, instance #{}", j);
                        LOG.info("      Field 10001 value: {}", group10000.get(10001, j));
                    }
                } else {
                    LOG.info("  No repeating group 10000 defined");
                }
            }
        } else {
            LOG.info("No repeating group 711 defined");
        }
    }
}

Fixml Converter Benchmark Sample

Description

This sample benchmark conversion from FIX message to FIXML message.

Directory Structure

Item Description
conf/sample/FixmlMessageBenchmark.properties configuration file
conf/sample sample data
conf/sample/schema FIXML schema documents
conf/logback.xml logger configuration

Usage

  • Run the sample:
    • win: FixmlConverterBenchmarkSample.bat
    • linux: FixmlConverterBenchmarkSample.sh
  • Clean everything:
    • win: clean.bat
    • linux: clean.sh

Source Code

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import biz.onixs.fix.engine.Engine;
import biz.onixs.fix.parser.Message;
import biz.onixs.util.PrecisionTimer;
import biz.onixs.util.settings.PropertyBasedSettings;
import biz.onixs.util.url.ResourceLoader;
import biz.onixs.util.url.ResourceLoaderUtil;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
  
import java.io.InputStream;
import java.nio.charset.Charset;
  
public class FixmlBenchmark {
    private static final Logger LOG = LoggerFactory.getLogger(FixmlBenchmark.class);
    private static final ResourceLoader resourceLoader = ResourceLoaderUtil.DEFAULT_LOADER;
    private final PropertyBasedSettings settings = new PropertyBasedSettings("sample/FixmlMessageBenchmark.properties");
  
    private void run() {
        try {
            Engine.init(settings);
            final long messageNum = settings.getLong("MessageNum");
            final String messageFile = settings.getString("MessageFile");
            final InputStream inputStream = resourceLoader.getResource(messageFile);
            final String rawMsg = IOUtils.toString(inputStream, Charset.defaultCharset()).trim();
            final Message fixMsg = new Message(rawMsg);
            LOG.info("Raw message size: {} bytes", rawMsg.length());
            doBenchmark(fixMsg, messageNum);
        } catch (final Exception e) {
            LOG.error(e.getMessage(), e);
        } finally {
            if (Engine.isInited()) {
                LOG.info("Engine shutdown...");
                Engine.getInstance().shutdown();
            }
        }
    }
  
    private static void doBenchmark(final Message message, final long messageNum) {
        final Benchmark benchmark = new Benchmark(message);
        benchmark.setMessageNum(messageNum);
        LOG.info(Benchmark.getName());
        benchmark.warmUp();
        final PrecisionTimer timer = new PrecisionTimer();
        benchmark.run();
        timer.stop();
        LOG.info("Performance: {} msgs/sec", timer.getItemsPerSecond(benchmark.getMessageNum()));
    }
  
    public static void main(final String[] args) {
        LOG.info("Fixml message Benchmark");
        LOG.info("The application is starting...");
        final FixmlBenchmark messageBenchmark = new FixmlBenchmark();
        messageBenchmark.run();
    }
}

The following class is used in the sample:

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import biz.onixs.fix.dictionary.Version;
import biz.onixs.fix.fixml.FixmlConverter;
import biz.onixs.fix.parser.Message;
import biz.onixs.fix.fixml.FixmlConverterException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
  
public class Benchmark {
    private static final Logger LOG = LoggerFactory.getLogger(Benchmark.class);
    private final Message message;
    private FixmlConverter converter = null;
    private long messageNum = 0L;
  
    Benchmark(final Message message) {
        this.message = message;
        try {
            converter = new FixmlConverter(Version.FIX44);
        } catch (final Exception e) {
            LOG.error("Can't initialize Fixml Converter");
        }
    }
  
    public long getMessageNum() {
        return messageNum;
    }
  
    public void setMessageNum(final long messageNum) {
        this.messageNum = messageNum;
    }
  
    public static String getName() {
        return "Message converted from FIX to FIXML";
    }
  
    void warmUp() {
        LOG.info("Running warm-up...");
        cycle(messageNum / 10L);
    }
  
    void run() {
        LOG.info("Running benchmark...");
        cycle(messageNum);
    }
  
    private void cycle(final long messageNum) {
        LOG.info("Message number: {}", messageNum);
        try {
            for (long l = 0L; l < messageNum; l++) {
                doAction();
            }
        } catch (final FixmlConverterException e) {
            LOG.error("Can't convert FIX to FIXML");
        }
    }
  
    private void doAction() throws FixmlConverterException {
        converter.fix2fixml(message);
    }
}