INET Nordic FIX protocols extending to nanosecond granularity timestamps - quickfix

All INET Nordic FIX protocols will be enhanced by extending to nanosecond granularity timestamps on 16.oktober 2015 (see notification and section 3.1.1 in the spec).
The timestamps will look like this: 20150924-10:35:20.840117690
quickfix currently rejects messages that contain fields with this new format with the error: Incorrect data format for value
Are there any plans to support this new format? Or maybe some workaround?

You can first try modifying your data dictionary. For example if you are using fix42.xml that comes with QuickFIX, you can change the affected timestamp fields from type='UTCTIMESTAMP' to type='STRING'.
If that isn't enough, you should instead write a patch against QuickFIX in C++, which should be somewhat straightforward once you know where to patch it, which I think is UtcTimeStampConvertor, around here: https://github.com/quickfix/quickfix/blob/master/src/C%2B%2B/FieldConvertors.h#L564
I think you need to add a case 27: above case 21: near the top, because your format has six extra digits. It looks like the rest of the function doesn't care about the total field length.
Of course if you want to actually inspect the sub-millisecond precision part of these timestamps, you'll need to do more.

No plans in QF/n, but only because this is the first I've heard of this.
I'll need to write some tests to see what the repercussions are. It may be that the time/date parser just truncates the extra nano places when it converts the string to a DateTime.
I've opened an issue: https://github.com/connamara/quickfixn/issues/352

This change is as far as I know kind of breaking the fix protocol definition of timestamps but that's another story.
There is a static class in QuickFixn called DateTimeConverter under QuickFix/Fields/Converters.
To get this to work correctly you would need to add format strings in lines in that class.
Add "yyyyMMdd-HH:mm:ss.fffffff" to DATE_TIME_FORMATS and "HH:mm:ss.fffffff" to TIME_ONLY_FORMATS so that it would look like this.
/// <summary>
/// Convert DateTime to/from String
/// </summary>
public static class DateTimeConverter
{
public const string DATE_TIME_FORMAT_WITH_MILLISECONDS = "{0:yyyyMMdd-HH:mm:ss.fff}";
public const string DATE_TIME_FORMAT_WITHOUT_MILLISECONDS = "{0:yyyyMMdd-HH:mm:ss}";
public const string DATE_ONLY_FORMAT = "{0:yyyyMMdd}";
public const string TIME_ONLY_FORMAT_WITH_MILLISECONDS = "{0:HH:mm:ss.fff}";
public const string TIME_ONLY_FORMAT_WITHOUT_MILLISECONDS = "{0:HH:mm:ss}";
public static string[] DATE_TIME_FORMATS = { "yyyyMMdd-HH:mm:ss.fffffff", "yyyyMMdd-HH:mm:ss.fff", "yyyyMMdd-HH:mm:ss" };
public static string[] DATE_ONLY_FORMATS = { "yyyyMMdd" };
public static string[] TIME_ONLY_FORMATS = { "HH:mm:ss.fffffff", "HH:mm:ss.fff", "HH:mm:ss" };
public static DateTimeStyles DATE_TIME_STYLES = DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal;
public static CultureInfo DATE_TIME_CULTURE_INFO = CultureInfo.InvariantCulture;

Related

What is the purpose of the line "public Word(#NonNull String word) {this.mWord = word;}" in this example?

I'm trying to figure out how to use Android's Room library for implementing a prepopulated sqlite database in my app and I came across this Android tutorial. One of the lines (the one in the title) confuses me though, because in another tutorial (also by Android), this line isn't present. Why is this line of code present in the first tutorial but not the second? What is its purpose?
I ask this because my code (which I'm basing off the second tutorial) doesn't include this line and yet this post by a different user attempting to do something similar with a prepopulated database does include it.
Here is some of the code I have (each of the fields has a getter method which just returns this.thatfield'sname):
#Entity (tableName = "words")
public class Words {
#PrimaryKey
#NonNull
#ColumnInfo (name = "word_id")
private int wordId;
#ColumnInfo(name = "a_words")
private String aWords;
#ColumnInfo(name = "b_words")
private String bWords;
#ColumnInfo(name = "c_words")
private String cWords;
This code gives me a "Cannot find setter for field" but just changing the fields from public to private seems to solve that (not sure if this is the best way to solve this error, though).
Why is this line of code present in the first tutorial but not the second?
That line is an additional class constructor that takes 1 non-null String and sets the mWord member/variable to the provided String.
Without then you can only use myWord = new Word(); to instantiate a Word object and the value would be either the default value if provided or null.
With the additional constructor then you could use both
myWord = new Word();
or
myOtherWord = new Word("A Word");
So, in short it's provided an alternative way of constructing/instantiating a new Object of that Class.
Using your code then you could have, for example :-
#Entity(tableName = "words")
class Words {
#ColumnInfo(name = "word_id")
#PrimaryKey
private int wordId;
#ColumnInfo(name = "a_words")
String aWords;
#ColumnInfo(name = "b_words")
String bWords;
#ColumnInfo(name = "c_words")
String cWords;
public void setWordId(int wordId, String aWord, String bWords, String c) {
this.wordId = wordId;
this.aWords = aWord;
this.bWords = bWords;
this.cWords = c;
}
}
Note for demonstration the parameter names use 3 different standards, ideally you would stick to a single standard/convention for naming the parameters.
So now you could use the one constructor that expects 4 parameters e.g.
myWord = new Words(1,"Apple","Banana","Cherry");
which equates to
myWord = new Words();
myWord.wordId = 1;
myWord.aWords = "Apple;
myWord.bWords = "Banana";
myWord.cWords = "Cherry";
As you have specified a constructor, the default constructor is no longer usable.
What is its purpose?
As can be seen, additional constructors, can reduce the amount of coding, there use will also prompt for the values (hence the use of useful parameter names improves i.e. c as above is not very meaningful at all (although in conjunction with the other parameters if would be better than x))

How do I insert Postgres "infinity" into a Timestamp field with JOOQ?

I have a column defined like this:
expiry timestamp(0) without time zone not null
With Postgres, I can issue SQL like:
insert into my_table(expiry) values ('infinity')
I've been digging through the JOOQ doco, but couldn't find any example of dealing with this.
Can I do that with JOOQ - and what would it look like?
Additionally, is it possible using an UpdatableRecord? Is there some kind of infinity "flag" instance of Timestamp I can use?
Ok, found a way to do it directly.
MyRecord r = db.insertInto(
MY_RECORD,
MY_RECORD.ID,
MY_RECORD.CREATED,
MY_RECORD.EXPIRY
).values(
val(id),
currentTimestamp(),
val("infinity").cast(Timestamp.class)
).returning().fetchOne();
But that feels more like a workaround than the right way to do it. Casting a string to a timestamp seems a little bit round-about to me, so I wrote a CustomField to make using it and querying easier:
public class TimestampLiteral extends CustomField<Timestamp> {
public static final TimestampLiteral INFINITY =
new TimestampLiteral("'infinity'");
public static final TimestampLiteral NEGATIVE_INFINITY =
new TimestampLiteral("'-infinity'");
public static final TimestampLiteral TODAY =
new TimestampLiteral("'today'");
private String literalValue;
public TimestampLiteral(String literalValue){
super("timestamp_literal", SQLDataType.TIMESTAMP);
this.literalValue = literalValue;
}
#Override
public void accept(Context<?> context){
context.visit(delegate(context.configuration()));
}
private QueryPart delegate(Configuration configuration){
switch( configuration.dialect().family() ){
case POSTGRES:
return DSL.field(literalValue);
default:
throw new UnsupportedOperationException(
"Dialect not supported because I don't know how/if this works in other databases.");
}
}
}
Then the query is:
MyRecord r = db.insertInto(
MY_RECORD,
MY_RECORD.ID,
MY_RECORD.CREATED,
MY_RECORD.EXPIRY
).values(
val(id),
TimestampLiteral.TODAY,
TimestampLiteral.INFINITY
).returning().fetchOne();
Don't know if this is necessarily the "right" way to do this, but it seems to work for the moment.
Still interested to hear if there's a way to do this with an UpdatableRecord.
I create a java.sql.Timestamp passing org.postgresql.PGStatement.DATE_POSITIVE_INFINITY to its constructor.
create.insertInto(
MY_RECORD,
MY_RECORD.ID,
MY_RECORD.CREATED,
MY_RECORD.EXPIRY
).values(
1,
new Timestamp(System.currentTimeMillis()),
new Timestamp(PGStatement.DATE_POSITIVE_INFINITY)
).execute();

public static class or const

Should I rather create a public static class or use internal constants?
I am working on a very large application and noticed the use of const string at numerous places.This is used to compare the users selection
const string Thatch = "Thatch";
const string BrickAndTimberFrame= "Brick And Timber Frame";
const string OtherRoof = "Other";
etc......
etc......
What I want to do is to rather create public static class in the Core Application (see code below). The reason for this is that I only have to change/add a value at one place only.
public static class RoofConstruction
{
public static String Thatch{ get { return "Thatch"; } }
public static String BrickAndTimberFrame { get { return "Brick And Timber Frame"; } }
etc....
etc....
}
The compare function will then look like this
internal bool SlateTileOrConcreteRoof()
{
return RiskInformation.RoofConstruction.Value == RoofConstruction.Slate ||
RiskInformation.RoofConstruction == RoofConstruction.TileAndSlate ||
RiskInformation.RoofConstruction == RoofConstruction.Concrete;
}
Please add any comments/improvements etc
Generally speaking, I think that “the defining characteristic of ‘a Good Class™’,” is that “it does the right thing, nevermind(!) ‘how, exactly,” it does it.”
When you export constants from the class, this suggests that an unknown-number of other sections of the application (present and future ...) will contain logic that tests against that string.
Therefore, the question that only you can really answer: “do they really care about ‘the value of that string,’ or do they want ‘the answer to a yes-or-no question, which is answered in part based on the value of that string?’” This might guide your decision about what is best to do. (Mind you, I do not think that there is any sort of bright-line rule. I have done it both ways...)

IntelliSense/ReSharper and custom Quickfixn library generation

I am developing a Quickfix/n initiator to be used with several counterparties, in the same instance, all using the same version of FIX (4.2 in this instance) but utilizing a unique messaging specification and I would like to use Intellisense/ReSharper to develop said initiator.
Previously I have used the generate.rb script to create source code from a modified FIX##.xml file but would like to use something like FIX42.DeutcheBank.xml, FIX42.CME.xml, FIX42.Whatever, to generate the source with the generate.rb ruby script or a modified version thereof so they can be parsed by IntelliSense/ReSharper and I am having issues because they all use "FIX.4.2" as begin strings and thus causes a compile error.
I know that I can just refer to a field/group via a key like Tags["BidForwardPointsCME"] or something similar with a DataDictionary but, as stated, I would like to be able to use IntelliSense/ReSharper and reference the message fields/groups with something like Quickfix.CounterParty.WhateverField and using the same dll.
I've banged my head against the internet for answers for 3-4 days with no luck - Is what I would like to do possible? If so, how would one go about it?
Hi in advance to Grant Birchmeier <:-]
For anyone that ever is trying to do this, the answer is pretty simple - probably not the most efficient but it works as far as I know.
the trick is to edit two ruby generation scripts (messages_gen.rb and generate.rb) and place the additional FIX specification XML file(s) in the spec/fix directory.
Assuming that you have a custom FIX xml file for Foo Exchange and that the Foo Exchange uses FIX 4.2, you need to name it FIX.xml (Example: FIXFooExchange.xml)
Next, you will have to override the FIX version in messages_gen.rb like so:
def self.gen_basemsg fixver, destdir
beginstring = fixver
if beginstring.match(/^FIX50/)
beginstring = "FIXT11"
end
if beginstring.match(/^FIXFooExchange/)
beginstring = "FIX42"
end
Next you need to add your custom fix version to 6 method definitions in the generate.rb file.
Those methods are:
initialize
agg_fields
get_field_def
generate_messages
generate_csproj
generate_message_factories
Here are a few examples:
def initialize
#fix40 = FIXDictionary.load spec('FIX40')
#fix41 = FIXDictionary.load spec('FIX41')
#fix42 = FIXDictionary.load spec('FIX42')
#fix43 = FIXDictionary.load spec('FIX43')
#fix44 = FIXDictionary.load spec('FIX44')
#fix50 = FIXDictionary.load spec('FIX50')
#fix50sp1 = FIXDictionary.load spec('FIX50SP1')
#fix50sp2 = FIXDictionary.load spec('FIX50SP2')
#fixFooExchange = FIXDictionary.load spec('FIXFooExchange')
#src_path = File.join File.dirname(__FILE__), '..', 'QuickFIXn'
end
def get_field_def fld_name
# we give priority to latest fix version
fld = merge_field_defs(
#fix50sp2.fields[fld_name],
#fix50sp1.fields[fld_name],
#fix50.fields[fld_name],
#fix44.fields[fld_name],
#fixFooExchange.fields[fld_name],
#fix43.fields[fld_name],
#fix42.fields[fld_name],
#fix41.fields[fld_name],
#fix40.fields[fld_name]
)
End
Basically you just copy one line and replace the fix version with the customized exchange xml data dictionary name.
The class BeginString in FixValues.cs should be modified to look like this:
public class BeginString
{
public const string FIXT11 = "FIXT.1.1";
public const string FIX50 = "FIX.5.0";
public const string FIX44 = "FIX.4.4";
public const string FIX43 = "FIX.4.3";
public const string FIXFooExchange = "FIX.4.2";
public const string FIX42 = "FIX.4.2";
public const string FIX41 = "FIX.4.1";
public const string FIX40 = "FIX.4.0";
}
The Values.cs file contains a single class which should be changed to look like this:
public class Values
{
public const string BeginString_FIXT11 = "FIXT.1.1";
public const string BeginString_FIX50 = "FIX.5.0";
public const string BeginString_FIX44 = "FIX.4.4";
public const string BeginString_FIX43 = "FIX.4.3";
public const string BeginString_FIXFooExchange = "FIX.4.2";
public const string BeginString_FIX42 = "FIX.4.2";
public const string BeginString_FIX41 = "FIX.4.1";
public const string BeginString_FIX40 = "FIX.4.0";
}
Do those things and then run the generate.bat file and you should be able to reference namespaces via '.' rather than using the base FIX version.
Here are some examples:
using QuickFix.FIXFooExchange;
using Message = QuickFix.Message;
QuickFix.FIXFooExchange.MessageFactory mF = new QuickFix.FIXFooExchange.MessageFactory();
and reference message properties like:
string customField = message.yourCustomFieldName.getValue().ToUpper();
instead of by
string customField = message["yourCustomFieldName"].getValue().ToUpper();
Lastly, you need to edit 2 .cs files: FixValues.cs and Values.cs
I've tested this pretty extensively and it seems to work but I would advise that you do testing before you put anything in production.
So the problem is you want 1 QF initiator process to connect to several different counterparties where each session uses a separate data dictionary?
Don't you do this using DataDictionary=somewhere/FIX42.xml in the configuration file?
See also http://quickfixn.org/tutorial/configuration.html AppDataDictionary: This setting supports the possibility of a custom application data dictionary for each session.

Size of class with static member and accessor

I have a question regarding efficiency. I am writing an app for windows phone 7 and care a lot about memory, as I am using extremely long lists.
My question is, what is the size of a class that apart from using normal properties like int, string etc, has also a static int property and an accessor property for the forementioned static field? I need to use a static field, but cannot access it using databinding, thus my question.
An example:
private static int _property1;
public int Property1
{
get { return _property1; }
}
public int property2;
public int property3;
I would be really grateful for your answers.
Here you have static field _property1, which will be shared between all the instances of class, means it will create only one copy of _property1, if someone changes the value of static field it will reflect to every place. So it will increase the efficiency regardless you need to restrict the other users to set/reset static variables..