Samples :: Simple FAST

Simple Decode Sample

Description

This sample demonstrates how to decode a FIX message. The CME FAST template is used.

Usage

  • Run the sample:

    • win: SimpleDecodeSample.bat
    • linux: SimpleDecodeSample.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
import biz.onixs.fix.dictionary.Version;
import biz.onixs.fix.engine.Engine;
import biz.onixs.fix.engine.EngineSettings;
import biz.onixs.fix.fast.Decoder;
import biz.onixs.fix.fast.FastVersion;
import biz.onixs.fix.parser.Message;
import biz.onixs.util.url.ResourceLoader;
import biz.onixs.util.url.ResourceLoaderUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
  
import java.io.InputStream;
  
/**
 * Simple FAST decode sample.
 */
public class SimpleDecodeSample {
    private static final Logger LOG = LoggerFactory.getLogger(SimpleDecodeSample.class);
    private static final ResourceLoader RESOURCE_LOADER = ResourceLoaderUtil.DEFAULT_LOADER;
    private static final byte[] BIN_MESSAGE = {-64, -48, -125, 35, 90, 33, 13, 123, 54, 63, -92, 23, 114, -79, -124,
            -115, -126, 95, -109, -106, -128};
  
    public static void main(final String[] args) {
        final EngineSettings engineSettings = new EngineSettings();
        engineSettings.setDialects("sample/CmeFastFixDialect.xml");
        final Engine engine = Engine.init(engineSettings);
        try {
            final Version fixVersion = Version.getById("CmeFastHandler");
            final InputStream templatesInputStream = RESOURCE_LOADER.getResource("sample/templates.xml");
            final Decoder decoder = new Decoder(templatesInputStream, FastVersion.FAST_1_1, fixVersion);
            LOG.info("Message to decode: {} bytes, {}", BIN_MESSAGE.length, BIN_MESSAGE);
            final Message fixMessage = decoder.decode(BIN_MESSAGE);
            LOG.info("Decoded message: {}", fixMessage);
        } catch (final Exception e) {
            LOG.error(e.getMessage(), e);
        } finally {
            engine.shutdown();
        }
    }
}

Simple Encode Sample

Description

This sample demonstrates how to encode a FIX message. The CME FAST template is used.

Usage

  • Run the sample:
    • win: SimpleEncodeSample.bat
    • linux: SimpleEncodeSample.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
import biz.onixs.fix.dictionary.Version;
import biz.onixs.fix.engine.Engine;
import biz.onixs.fix.engine.EngineSettings;
import biz.onixs.fix.fast.Encoder;
import biz.onixs.fix.fast.FastVersion;
import biz.onixs.fix.parser.Message;
import biz.onixs.util.url.ResourceLoader;
import biz.onixs.util.url.ResourceLoaderUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
  
import java.io.InputStream;
  
/**
 * Simple FAST encode sample.
 */
public class SimpleEncodeSample {
    private static final Logger LOG = LoggerFactory.getLogger(SimpleEncodeSample.class);
    private static final ResourceLoader RESOURCE_LOADER = ResourceLoaderUtil.DEFAULT_LOADER;
    private static final String RAW_MESSAGE = "8=FIXT.1.1\u00019=993\u000135=W\u000149=CME\u000134=3\u0001" +
            "52=20100210175614884\u0001369=391473\u00011128=9\u000148=12179\u000122=8\u00011021=2\u00011682=21\u0001" +
            "911=4\u000183=13\u000110=198";
  
    public static void main(final String[] args) {
        final EngineSettings engineSettings = new EngineSettings();
        engineSettings.setDialects("sample/CmeFastFixDialect.xml");
        final Engine engine = Engine.init(engineSettings);
        try {
            final Version fixVersion = Version.getById("CmeFastHandler");
            final InputStream templatesInputStream = RESOURCE_LOADER.getResource("sample/templates.xml");
            final Encoder encoder = new Encoder(templatesInputStream, fixVersion, FastVersion.FAST_1_1);
            final Message fixMessage = new Message(fixVersion, RAW_MESSAGE);
            LOG.info("Message to encode: {}", fixMessage);
            final byte[] binMessage = encoder.encode(fixMessage, 80);
            LOG.info("Encoded message: {} bytes, {}", binMessage.length, binMessage);
        } catch (final Exception e) {
            LOG.error(e.getMessage(), e);
        } finally {
            engine.shutdown();
        }
    }
}