From 5cd0198cc153d94d8ea5959a9dc156e4511cb4d9 Mon Sep 17 00:00:00 2001 From: Mike Gatny Date: Mon, 12 Sep 2016 15:18:29 -0400 Subject: [PATCH 1/3] Examples in various languages --- .gitignore | 1 + README.md | 11 ++- go/README.md | 7 ++ go/msg_test.go | 85 +++++++++++++++++++ java/README.md | 7 ++ java/pom.xml | 57 +++++++++++++ .../java/org/fixtradingcommunity/MsgTest.java | 83 ++++++++++++++++++ javascript/README.md | 7 ++ javascript/msg_test.js | 50 +++++++++++ ruby/.ruby-version | 1 + ruby/README.md | 7 ++ ruby/msg_test.rb | 59 +++++++++++++ 12 files changed, 374 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 go/README.md create mode 100644 go/msg_test.go create mode 100644 java/README.md create mode 100644 java/pom.xml create mode 100644 java/src/test/java/org/fixtradingcommunity/MsgTest.java create mode 100644 javascript/README.md create mode 100644 javascript/msg_test.js create mode 100644 ruby/.ruby-version create mode 100644 ruby/README.md create mode 100644 ruby/msg_test.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e8ee010 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +scratch/ diff --git a/README.md b/README.md index 465a01d..2b1bcac 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # fix-json-encoding ## License + FIX JSON Encoding is © Copyright 2016 FIX Protocol Limited. Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,4 +14,12 @@ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and -limitations under the License. \ No newline at end of file +limitations under the License. + +## Examples + +- [Go](blob/master/go) +- [Java](blob/master/java) +- [Javascript](blob/master/javascript) +- [Ruby](blob/master/ruby) + diff --git a/go/README.md b/go/README.md new file mode 100644 index 0000000..be11db2 --- /dev/null +++ b/go/README.md @@ -0,0 +1,7 @@ +## Go (golang) Reference Code + +Example of parsing FIX JSON Encoding in Go. Run it with: + +```shell +go test +``` diff --git a/go/msg_test.go b/go/msg_test.go new file mode 100644 index 0000000..480dbe1 --- /dev/null +++ b/go/msg_test.go @@ -0,0 +1,85 @@ +package msgtest + +import ( + "encoding/json" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +type NoMDEntries struct { + MDEntryType string + MDEntryPx string + MDEntrySize string + MDEntryDate string + MDEntryTime string +} + +type MarketDataSnapshotFullRefresh struct { + BeginString string + MsgType string + MsgSeqNum string + SenderCompID string + TargetCompID string + SendingTime string + SecurityIDSource string + SecurityID string + MDReqID string + NoMDEntries []NoMDEntries +} + +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"} + ] + }`) +) + +func TestJSON(t *testing.T) { + // When the JSON is parsed + var msg MarketDataSnapshotFullRefresh + err := json.Unmarshal(data, &msg) + 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) + + // And the body fields should be + assert.Equal(t, "8", msg.SecurityIDSource) + assert.Equal(t, "ESU6", msg.SecurityID) + assert.Equal(t, "789", msg.MDReqID) + + // And the NoMDEntries repeating group should contain two entries + assert.Len(t, msg.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) + + // 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) +} diff --git a/java/README.md b/java/README.md new file mode 100644 index 0000000..c3be16b --- /dev/null +++ b/java/README.md @@ -0,0 +1,7 @@ +## Java Reference Code + +Example of parsing FIX JSON Encoding in Java. Run it with: + +```shell +mvn test +``` diff --git a/java/pom.xml b/java/pom.xml new file mode 100644 index 0000000..fd93aea --- /dev/null +++ b/java/pom.xml @@ -0,0 +1,57 @@ + + 4.0.0 + org.fixtradingcommunity.fix-examples + json-msg-test + 0.0.1-SNAPSHOT + jar + ${project.groupId}:${project.artifactId} + FIX/JSON encoding spike + 2016 + + + FIX Trading Community + http://http://www.fixtradingcommunity.org/ + + + + The Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + + + UTF-8 + 4.11 + 1.8 + 2.6.2 + + + + + com.google.code.gson + gson + ${gson.version} + + + junit + junit + test + ${junit.version} + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + ${java.version} + ${java.version} + + + + + diff --git a/java/src/test/java/org/fixtradingcommunity/MsgTest.java b/java/src/test/java/org/fixtradingcommunity/MsgTest.java new file mode 100644 index 0000000..4cddb4d --- /dev/null +++ b/java/src/test/java/org/fixtradingcommunity/MsgTest.java @@ -0,0 +1,83 @@ +package org.fixtradingcommunity; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.Before; +import com.google.gson.*; + +public class MsgTest { + static class NoMDEntries { + String MDEntryType; + String MDEntryPx; + String MDEntrySize; + String MDEntryDate; + String MDEntryTime; + } + + static class MarketDataSnapshotFullRefresh { + String BeginString; + String MsgType; + String MsgSeqNum; + String SenderCompID; + String TargetCompID; + String SendingTime; + String SecurityIDSource; + String SecurityID; + String MDReqID; + NoMDEntries[] NoMDEntries; + } + + 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\"}", + "]", + "}" + ); + + @Test + public void testJson() { + // When the JSON is parsed + 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); + + // And the body fields should be + assertEquals("8", msg.SecurityIDSource); + assertEquals("ESU6", msg.SecurityID); + assertEquals("789", msg.MDReqID); + + // And the NoMDEntries repeating group should contain two entries + assertEquals(2, msg.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); + + // 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); + } +} diff --git a/javascript/README.md b/javascript/README.md new file mode 100644 index 0000000..94713c1 --- /dev/null +++ b/javascript/README.md @@ -0,0 +1,7 @@ +## Javascript Reference Code + +Example of parsing FIX JSON Encoding in Javascript. Run it with: + +```shell +node msg_test.js +``` diff --git a/javascript/msg_test.js b/javascript/msg_test.js new file mode 100644 index 0000000..eb97834 --- /dev/null +++ b/javascript/msg_test.js @@ -0,0 +1,50 @@ +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"}' + + ' ]' + + '}'; + +// 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"); + +// And the body fields should be +assert.equal(msg.SecurityIDSource, "8"); +assert.equal(msg.SecurityID, "ESU6"); +assert.equal(msg.MDReqID, "789"); + +// And the NoMDEntries repeating group should contain two entries +assert.equal(msg.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"); + +// 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"); diff --git a/ruby/.ruby-version b/ruby/.ruby-version new file mode 100644 index 0000000..b1b25a5 --- /dev/null +++ b/ruby/.ruby-version @@ -0,0 +1 @@ +2.2.2 diff --git a/ruby/README.md b/ruby/README.md new file mode 100644 index 0000000..bc2a9b3 --- /dev/null +++ b/ruby/README.md @@ -0,0 +1,7 @@ +## Ruby Reference Code + +Example of parsing FIX JSON Encoding in Ruby. Run it with: + +```shell +ruby msg_test.rb +``` diff --git a/ruby/msg_test.rb b/ruby/msg_test.rb new file mode 100644 index 0000000..fe2b721 --- /dev/null +++ b/ruby/msg_test.rb @@ -0,0 +1,59 @@ +require 'minitest/autorun' +require 'json' + +class TestJson < MiniTest::Unit::TestCase + def setup + @data = < Date: Mon, 12 Sep 2016 15:21:11 -0400 Subject: [PATCH 2/3] Fixup links --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2b1bcac..364e6a6 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ limitations under the License. ## Examples -- [Go](blob/master/go) -- [Java](blob/master/java) -- [Javascript](blob/master/javascript) -- [Ruby](blob/master/ruby) +- [Go](go/) +- [Java](java/) +- [Javascript](javascript/) +- [Ruby](ruby/) From 8fe98f0f92d0e4a86efe40aa6f90a25cc43d8e48 Mon Sep 17 00:00:00 2001 From: Mike Gatny Date: Mon, 12 Sep 2016 16:00:52 -0400 Subject: [PATCH 3/3] Separate header, body, trailer --- .gitignore | 1 + go/msg_test.go | 100 +++++++++-------- .../java/org/fixtradingcommunity/MsgTest.java | 104 ++++++++++-------- javascript/msg_test.js | 72 ++++++------ ruby/msg_test.rb | 72 ++++++------ 5 files changed, 197 insertions(+), 152 deletions(-) diff --git a/.gitignore b/.gitignore index e8ee010..892d2fd 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +java/target/ scratch/ diff --git a/go/msg_test.go b/go/msg_test.go index 480dbe1..4f6aa24 100644 --- a/go/msg_test.go +++ b/go/msg_test.go @@ -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": { + } }`) ) @@ -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) } diff --git a/java/src/test/java/org/fixtradingcommunity/MsgTest.java b/java/src/test/java/org/fixtradingcommunity/MsgTest.java index 4cddb4d..3547487 100644 --- a/java/src/test/java/org/fixtradingcommunity/MsgTest.java +++ b/java/src/test/java/org/fixtradingcommunity/MsgTest.java @@ -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; @@ -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\": {", + "}", "}" ); @@ -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); } } diff --git a/javascript/msg_test.js b/javascript/msg_test.js index eb97834..497dea1 100644 --- a/javascript/msg_test.js +++ b/javascript/msg_test.js @@ -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"); diff --git a/ruby/msg_test.rb b/ruby/msg_test.rb index fe2b721..7c1540d 100644 --- a/ruby/msg_test.rb +++ b/ruby/msg_test.rb @@ -5,19 +5,25 @@ class TestJson < MiniTest::Unit::TestCase def setup @data = <