Skip to content

Commit

Permalink
Separate header, body, trailer
Browse files Browse the repository at this point in the history
  • Loading branch information
mgatny committed Sep 12, 2016
1 parent 6137955 commit 8fe98f0
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 152 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
java/target/
scratch/
100 changes: 57 additions & 43 deletions go/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,47 @@ type NoMDEntries struct {
}

type MarketDataSnapshotFullRefresh struct {
BeginString string
MsgType string
MsgSeqNum string
SenderCompID string
TargetCompID string
SendingTime string
SecurityIDSource string
SecurityID string
MDReqID string
NoMDEntries []NoMDEntries
Header struct {
BeginString string
MsgType string
MsgSeqNum string
SenderCompID string
TargetCompID string
SendingTime string
}

Body struct {
SecurityIDSource string
SecurityID string
MDReqID string
NoMDEntries []NoMDEntries
}

Trailer struct {
}
}

var (
data = []byte(`{
"BeginString": "FIXT.1.1",
"MsgType": "W",
"MsgSeqNum": "4567",
"SenderCompID": "SENDER",
"TargetCompID": "TARGET",
"SendingTime": "20160802-21:14:38.717",
"SecurityIDSource": "8",
"SecurityID": "ESU6",
"MDReqID": "789",
"NoMDEntries": [
{ "MDEntryType": "0", "MDEntryPx": "2179.75", "MDEntrySize": "175", "MDEntryDate": "20160812", "MDEntryTime": "21:14:38.688"},
{ "MDEntryType": "1", "MDEntryPx": "2180.25", "MDEntrySize": "125", "MDEntryDate": "20160812", "MDEntryTime": "21:14:38.688"}
]
"Header": {
"BeginString": "FIXT.1.1",
"MsgType": "W",
"MsgSeqNum": "4567",
"SenderCompID": "SENDER",
"TargetCompID": "TARGET",
"SendingTime": "20160802-21:14:38.717"
},
"Body": {
"SecurityIDSource": "8",
"SecurityID": "ESU6",
"MDReqID": "789",
"NoMDEntries": [
{ "MDEntryType": "0", "MDEntryPx": "2179.75", "MDEntrySize": "175", "MDEntryDate": "20160812", "MDEntryTime": "21:14:38.688"},
{ "MDEntryType": "1", "MDEntryPx": "2180.25", "MDEntrySize": "125", "MDEntryDate": "20160812", "MDEntryTime": "21:14:38.688"}
]
},
"Trailer": {
}
}`)
)

Expand All @@ -54,32 +68,32 @@ func TestJSON(t *testing.T) {
require.Nil(t, err)

// Then the header fields should be
assert.Equal(t, "FIXT.1.1", msg.BeginString)
assert.Equal(t, "W", msg.MsgType)
assert.Equal(t, "4567", msg.MsgSeqNum)
assert.Equal(t, "SENDER", msg.SenderCompID)
assert.Equal(t, "TARGET", msg.TargetCompID)
assert.Equal(t, "20160802-21:14:38.717", msg.SendingTime)
assert.Equal(t, "FIXT.1.1", msg.Header.BeginString)
assert.Equal(t, "W", msg.Header.MsgType)
assert.Equal(t, "4567", msg.Header.MsgSeqNum)
assert.Equal(t, "SENDER", msg.Header.SenderCompID)
assert.Equal(t, "TARGET", msg.Header.TargetCompID)
assert.Equal(t, "20160802-21:14:38.717", msg.Header.SendingTime)

// And the body fields should be
assert.Equal(t, "8", msg.SecurityIDSource)
assert.Equal(t, "ESU6", msg.SecurityID)
assert.Equal(t, "789", msg.MDReqID)
assert.Equal(t, "8", msg.Body.SecurityIDSource)
assert.Equal(t, "ESU6", msg.Body.SecurityID)
assert.Equal(t, "789", msg.Body.MDReqID)

// And the NoMDEntries repeating group should contain two entries
assert.Len(t, msg.NoMDEntries, 2)
assert.Len(t, msg.Body.NoMDEntries, 2)

// And the first entry should be
assert.Equal(t, "0", msg.NoMDEntries[0].MDEntryType)
assert.Equal(t, "2179.75", msg.NoMDEntries[0].MDEntryPx)
assert.Equal(t, "175", msg.NoMDEntries[0].MDEntrySize)
assert.Equal(t, "20160812", msg.NoMDEntries[0].MDEntryDate)
assert.Equal(t, "21:14:38.688", msg.NoMDEntries[0].MDEntryTime)
assert.Equal(t, "0", msg.Body.NoMDEntries[0].MDEntryType)
assert.Equal(t, "2179.75", msg.Body.NoMDEntries[0].MDEntryPx)
assert.Equal(t, "175", msg.Body.NoMDEntries[0].MDEntrySize)
assert.Equal(t, "20160812", msg.Body.NoMDEntries[0].MDEntryDate)
assert.Equal(t, "21:14:38.688", msg.Body.NoMDEntries[0].MDEntryTime)

// And the second entry should be
assert.Equal(t, "1", msg.NoMDEntries[1].MDEntryType)
assert.Equal(t, "2180.25", msg.NoMDEntries[1].MDEntryPx)
assert.Equal(t, "125", msg.NoMDEntries[1].MDEntrySize)
assert.Equal(t, "20160812", msg.NoMDEntries[1].MDEntryDate)
assert.Equal(t, "21:14:38.688", msg.NoMDEntries[1].MDEntryTime)
assert.Equal(t, "1", msg.Body.NoMDEntries[1].MDEntryType)
assert.Equal(t, "2180.25", msg.Body.NoMDEntries[1].MDEntryPx)
assert.Equal(t, "125", msg.Body.NoMDEntries[1].MDEntrySize)
assert.Equal(t, "20160812", msg.Body.NoMDEntries[1].MDEntryDate)
assert.Equal(t, "21:14:38.688", msg.Body.NoMDEntries[1].MDEntryTime)
}
104 changes: 61 additions & 43 deletions java/src/test/java/org/fixtradingcommunity/MsgTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
import com.google.gson.*;

public class MsgTest {
static class Header {
String BeginString;
String MsgType;
String MsgSeqNum;
String SenderCompID;
String TargetCompID;
String SendingTime;
}

static class Trailer {
}

static class NoMDEntries {
String MDEntryType;
String MDEntryPx;
Expand All @@ -15,33 +27,39 @@ static class NoMDEntries {
}

static class MarketDataSnapshotFullRefresh {
String BeginString;
String MsgType;
String MsgSeqNum;
String SenderCompID;
String TargetCompID;
String SendingTime;
String SecurityIDSource;
String SecurityID;
String MDReqID;
NoMDEntries[] NoMDEntries;
static class Body {
String SecurityIDSource;
String SecurityID;
String MDReqID;
NoMDEntries[] NoMDEntries;
}

Header Header;
Body Body;
Trailer Trailer;
}

private final static String data = String.join("\n",
"{",
"\"BeginString\": \"FIXT.1.1\",",
"\"MsgType\": \"W\",",
"\"MsgSeqNum\": \"4567\",",
"\"SenderCompID\": \"SENDER\",",
"\"TargetCompID\": \"TARGET\",",
"\"SendingTime\": \"20160802-21:14:38.717\",",
"\"SecurityIDSource\": \"8\",",
"\"SecurityID\": \"ESU6\",",
"\"MDReqID\": \"789\",",
"\"NoMDEntries\": [",
"{ \"MDEntryType\": \"0\", \"MDEntryPx\": \"2179.75\", \"MDEntrySize\": \"175\", \"MDEntryDate\": \"20160812\", \"MDEntryTime\": \"21:14:38.688\"},",
"{ \"MDEntryType\": \"1\", \"MDEntryPx\": \"2180.25\", \"MDEntrySize\": \"125\", \"MDEntryDate\": \"20160812\", \"MDEntryTime\": \"21:14:38.688\"}",
"]",
"\"Header\": {",
"\"BeginString\": \"FIXT.1.1\",",
"\"MsgType\": \"W\",",
"\"MsgSeqNum\": \"4567\",",
"\"SenderCompID\": \"SENDER\",",
"\"TargetCompID\": \"TARGET\",",
"\"SendingTime\": \"20160802-21:14:38.717\"",
"},",
"\"Body\": {",
"\"SecurityIDSource\": \"8\",",
"\"SecurityID\": \"ESU6\",",
"\"MDReqID\": \"789\",",
"\"NoMDEntries\": [",
"{ \"MDEntryType\": \"0\", \"MDEntryPx\": \"2179.75\", \"MDEntrySize\": \"175\", \"MDEntryDate\": \"20160812\", \"MDEntryTime\": \"21:14:38.688\"},",
"{ \"MDEntryType\": \"1\", \"MDEntryPx\": \"2180.25\", \"MDEntrySize\": \"125\", \"MDEntryDate\": \"20160812\", \"MDEntryTime\": \"21:14:38.688\"}",
"]",
"},",
"\"Trailer\": {",
"}",
"}"
);

Expand All @@ -51,33 +69,33 @@ public void testJson() {
MarketDataSnapshotFullRefresh msg = new Gson().fromJson(data, MarketDataSnapshotFullRefresh.class);

// Then the header fields should be
assertEquals("FIXT.1.1", msg.BeginString);
assertEquals("W", msg.MsgType);
assertEquals("4567", msg.MsgSeqNum);
assertEquals("SENDER", msg.SenderCompID);
assertEquals("TARGET", msg.TargetCompID);
assertEquals("20160802-21:14:38.717", msg.SendingTime);
assertEquals("FIXT.1.1", msg.Header.BeginString);
assertEquals("W", msg.Header.MsgType);
assertEquals("4567", msg.Header.MsgSeqNum);
assertEquals("SENDER", msg.Header.SenderCompID);
assertEquals("TARGET", msg.Header.TargetCompID);
assertEquals("20160802-21:14:38.717", msg.Header.SendingTime);

// And the body fields should be
assertEquals("8", msg.SecurityIDSource);
assertEquals("ESU6", msg.SecurityID);
assertEquals("789", msg.MDReqID);
assertEquals("8", msg.Body.SecurityIDSource);
assertEquals("ESU6", msg.Body.SecurityID);
assertEquals("789", msg.Body.MDReqID);

// And the NoMDEntries repeating group should contain two entries
assertEquals(2, msg.NoMDEntries.length);
assertEquals(2, msg.Body.NoMDEntries.length);

// And the first entry should be
assertEquals("0", msg.NoMDEntries[0].MDEntryType);
assertEquals("2179.75", msg.NoMDEntries[0].MDEntryPx);
assertEquals("175", msg.NoMDEntries[0].MDEntrySize);
assertEquals("20160812", msg.NoMDEntries[0].MDEntryDate);
assertEquals("21:14:38.688", msg.NoMDEntries[0].MDEntryTime);
assertEquals("0", msg.Body.NoMDEntries[0].MDEntryType);
assertEquals("2179.75", msg.Body.NoMDEntries[0].MDEntryPx);
assertEquals("175", msg.Body.NoMDEntries[0].MDEntrySize);
assertEquals("20160812", msg.Body.NoMDEntries[0].MDEntryDate);
assertEquals("21:14:38.688", msg.Body.NoMDEntries[0].MDEntryTime);

// And the second entry should be
assertEquals("1", msg.NoMDEntries[1].MDEntryType);
assertEquals("2180.25", msg.NoMDEntries[1].MDEntryPx);
assertEquals("125", msg.NoMDEntries[1].MDEntrySize);
assertEquals("20160812", msg.NoMDEntries[1].MDEntryDate);
assertEquals("21:14:38.688", msg.NoMDEntries[1].MDEntryTime);
assertEquals("1", msg.Body.NoMDEntries[1].MDEntryType);
assertEquals("2180.25", msg.Body.NoMDEntries[1].MDEntryPx);
assertEquals("125", msg.Body.NoMDEntries[1].MDEntrySize);
assertEquals("20160812", msg.Body.NoMDEntries[1].MDEntryDate);
assertEquals("21:14:38.688", msg.Body.NoMDEntries[1].MDEntryTime);
}
}
72 changes: 39 additions & 33 deletions javascript/msg_test.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,56 @@
const assert = require('assert');

const data = '{' +
' "BeginString": "FIXT.1.1",' +
' "MsgType": "W",' +
' "MsgSeqNum": "4567",' +
' "SenderCompID": "SENDER",' +
' "TargetCompID": "TARGET",' +
' "SendingTime": "20160802-21:14:38.717",' +
' "SecurityIDSource": "8",' +
' "SecurityID": "ESU6",' +
' "MDReqID": "789",' +
' "NoMDEntries": [' +
' { "MDEntryType": "0", "MDEntryPx": "2179.75", "MDEntrySize": "175", "MDEntryDate": "20160812", "MDEntryTime": "21:14:38.688"},' +
' { "MDEntryType": "1", "MDEntryPx": "2180.25", "MDEntrySize": "125", "MDEntryDate": "20160812", "MDEntryTime": "21:14:38.688"}' +
' ]' +
' "Header": {' +
' "BeginString": "FIXT.1.1",' +
' "MsgType": "W",' +
' "MsgSeqNum": "4567",' +
' "SenderCompID": "SENDER",' +
' "TargetCompID": "TARGET",' +
' "SendingTime": "20160802-21:14:38.717"' +
' },' +
' "Body": {' +
' "SecurityIDSource": "8",' +
' "SecurityID": "ESU6",' +
' "MDReqID": "789",' +
' "NoMDEntries": [' +
' { "MDEntryType": "0", "MDEntryPx": "2179.75", "MDEntrySize": "175", "MDEntryDate": "20160812", "MDEntryTime": "21:14:38.688"},' +
' { "MDEntryType": "1", "MDEntryPx": "2180.25", "MDEntrySize": "125", "MDEntryDate": "20160812", "MDEntryTime": "21:14:38.688"}' +
' ]' +
' },' +
' "Trailer": {' +
' }' +
'}';

// When the JSON is parsed
var msg = JSON.parse(data);

// Then the header fields should be
assert.equal(msg.BeginString, "FIXT.1.1");
assert.equal(msg.MsgType, "W");
assert.equal(msg.MsgSeqNum, "4567");
assert.equal(msg.SenderCompID, "SENDER");
assert.equal(msg.TargetCompID, "TARGET");
assert.equal(msg.SendingTime, "20160802-21:14:38.717");
assert.equal(msg.Header.BeginString, "FIXT.1.1");
assert.equal(msg.Header.MsgType, "W");
assert.equal(msg.Header.MsgSeqNum, "4567");
assert.equal(msg.Header.SenderCompID, "SENDER");
assert.equal(msg.Header.TargetCompID, "TARGET");
assert.equal(msg.Header.SendingTime, "20160802-21:14:38.717");

// And the body fields should be
assert.equal(msg.SecurityIDSource, "8");
assert.equal(msg.SecurityID, "ESU6");
assert.equal(msg.MDReqID, "789");
assert.equal(msg.Body.SecurityIDSource, "8");
assert.equal(msg.Body.SecurityID, "ESU6");
assert.equal(msg.Body.MDReqID, "789");

// And the NoMDEntries repeating group should contain two entries
assert.equal(msg.NoMDEntries.length, 2);
assert.equal(msg.Body.NoMDEntries.length, 2);

// And the first entry should be
assert.equal(msg.NoMDEntries[0].MDEntryType, "0");
assert.equal(msg.NoMDEntries[0].MDEntryPx, "2179.75");
assert.equal(msg.NoMDEntries[0].MDEntrySize, "175");
assert.equal(msg.NoMDEntries[0].MDEntryDate, "20160812");
assert.equal(msg.NoMDEntries[0].MDEntryTime, "21:14:38.688");
assert.equal(msg.Body.NoMDEntries[0].MDEntryType, "0");
assert.equal(msg.Body.NoMDEntries[0].MDEntryPx, "2179.75");
assert.equal(msg.Body.NoMDEntries[0].MDEntrySize, "175");
assert.equal(msg.Body.NoMDEntries[0].MDEntryDate, "20160812");
assert.equal(msg.Body.NoMDEntries[0].MDEntryTime, "21:14:38.688");

// And the second entry should be
assert.equal(msg.NoMDEntries[1].MDEntryType, "1");
assert.equal(msg.NoMDEntries[1].MDEntryPx, "2180.25");
assert.equal(msg.NoMDEntries[1].MDEntrySize, "125");
assert.equal(msg.NoMDEntries[1].MDEntryDate, "20160812");
assert.equal(msg.NoMDEntries[1].MDEntryTime, "21:14:38.688");
assert.equal(msg.Body.NoMDEntries[1].MDEntryType, "1");
assert.equal(msg.Body.NoMDEntries[1].MDEntryPx, "2180.25");
assert.equal(msg.Body.NoMDEntries[1].MDEntrySize, "125");
assert.equal(msg.Body.NoMDEntries[1].MDEntryDate, "20160812");
assert.equal(msg.Body.NoMDEntries[1].MDEntryTime, "21:14:38.688");
Loading

0 comments on commit 8fe98f0

Please sign in to comment.