Configuration of weekly session

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Configuration of weekly session

Yong-Jhen Hong-3
QuickFIX/J Documentation: http://www.quickfixj.org/documentation/
QuickFIX/J Support: http://www.quickfixj.org/support/

Hi all!

I work as an engineer in a local trading software company in Taiwan.
In our solution for outbound trading, we use QuickFIX/J for
communication with FIX gateways. It works fine for us most of the time,
thanks for the great work, developers!

I find some problems with weekly session in QuickFIX/J in our test
environment these days though:

1. I can't confiure a weekly session using SessionSettings with
an InputStream object (in my case, a FileInputStream object),
because SessionSettings doesn't work well with multibyte characters,
and the name of weekdays in our locale (zh-TW) is in multibyte
characters. Therefore I change the code to use InputStreamReader to read
characters instead.

2. When parsing name of weekdays in class DayConverter, only the leading
two characters are used for comparison, maybe for easier configuration.
But the leading two characters in our locale is all the same for the
7 weekdays, thus it always match the first one (Sunday).
I would suggest not just using the leading two characters for
comparison, it will still work fine for people using only two characters
to confiure.

3. Weekdays (StartDay, EndDay) is always in UTC, even when I set
TimeZone to our local one. For example:

TimeZone=Asia/Taipei
StartTime=06:45:00
EndTime=06:44:59

If I set both StartDay and EndDay to Wednesday (the equivalent,
localized one, in multibyte characters, of course ;)
it would be a weekly session of from Wednesday 22:45:00 UTC
to Wednesday 22:44:59 UTC,
instead of from Tuesday 22:45:00 UTC to Tuesdasy 22:44:59 UTC.
(Note: Wednesday 06:45:00 in Taipei is Tuesday 22:45:00 UTC)


I made some changes to solve the 3 problems above in my own way,
the patch is attached with this mail.
Hope it can be adoped by our developers or help somebody else ;)

Regards,
yongjhen

--
Yong-Jhen Hong ([hidden email])
Senior Software Engineer
Financial Solution Dept.
ICE Technology Corp.
Taiwan


diff -rud quickfixj-1.1.0-src\quickfixj\core\src\main\java\quickfix\DayConverter.java quickfixj-1.1.0-src-patched\quickfixj\core\src\main\java\quickfix\DayConverter.java
--- quickfixj-1.1.0-src\quickfixj\core\src\main\java\quickfix\DayConverter.java Wed Apr 11 08:44:47 2007
+++ quickfixj-1.1.0-src-patched\quickfixj\core\src\main\java\quickfix\DayConverter.java Wed May 23 18:48:20 2007
@@ -37,14 +37,11 @@
      */
     public static int toInteger(String dayName) throws ConfigError {
         String dayNames[] = new DateFormatSymbols(Locale.getDefault()).getWeekdays();
-        if (dayName.length() >= 2) {
-            String abbr = dayName.substring(0, 2).toLowerCase();
-            for (int i = 1; i < dayNames.length; i++) {
-                if (dayNames[i].toLowerCase().startsWith(abbr)) {
-                    return i;
-                }
-            }
-        }
+ for (int i = 1; i < dayNames.length; i++) {
+    if (dayNames[i].toLowerCase().startsWith(dayName)) {
+ return i;
+    }
+ }
         throw new ConfigError("invalid format for day (valid values: "
                 + Arrays.asList(dayNames).subList(1, dayNames.length)
                 + " or prefix); actual value was '" + dayName + "'");
diff -rud quickfixj-1.1.0-src\quickfixj\core\src\main\java\quickfix\SessionSchedule.java quickfixj-1.1.0-src-patched\quickfixj\core\src\main\java\quickfix\SessionSchedule.java
--- quickfixj-1.1.0-src\quickfixj\core\src\main\java\quickfix\SessionSchedule.java Wed Apr 11 08:44:51 2007
+++ quickfixj-1.1.0-src-patched\quickfixj\core\src\main\java\quickfix\SessionSchedule.java Thu May 24 11:05:29 2007
@@ -75,12 +75,15 @@
         localTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(matcher.group(1)));
         localTime.set(Calendar.MINUTE, Integer.parseInt(matcher.group(2)));
         localTime.set(Calendar.SECOND, Integer.parseInt(matcher.group(3)));
-        Calendar startTime = SystemTime.getUtcCalendar();
-        startTime.setTime(localTime.getTime());
         int startDay = NOT_SET;
         if (weeklySession) {
             startDay = getDay(settings, sessionID, Session.SETTING_START_DAY, NOT_SET);
+    localTime.set(Calendar.DAY_OF_WEEK, startDay);
         }
+        Calendar startTime = SystemTime.getUtcCalendar();
+        startTime.setTime(localTime.getTime());
+        if (weeklySession)
+    startDay = startTime.get(Calendar.DAY_OF_WEEK);
 
         matcher = TIME_PATTERN.matcher(endTimeString);
         if (!matcher.find()) {
@@ -90,12 +93,15 @@
         localTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(matcher.group(1)));
         localTime.set(Calendar.MINUTE, Integer.parseInt(matcher.group(2)));
         localTime.set(Calendar.SECOND, Integer.parseInt(matcher.group(3)));
-        Calendar endTime = SystemTime.getUtcCalendar();
-        endTime.setTime(localTime.getTime());
         int endDay = NOT_SET;
         if (weeklySession) {
             endDay = getDay(settings, sessionID, Session.SETTING_END_DAY, NOT_SET);
+    localTime.set(Calendar.DAY_OF_WEEK, endDay);
         }
+        Calendar endTime = SystemTime.getUtcCalendar();
+        endTime.setTime(localTime.getTime());
+        if (weeklySession)
+    endDay = endTime.get(Calendar.DAY_OF_WEEK);
 
         this.startTime = new TimeEndPoint(startDay, startTime);
         this.endTime = new TimeEndPoint(endDay, endTime);
@@ -297,6 +303,8 @@
 
         // Now the localized equivalents, if necessary
         if (sessionTimeZone != null && !TimeZone.getTimeZone("UTC").equals(sessionTimeZone)) {
+    ti.getStart().setTimeZone(sessionTimeZone);
+    ti.getEnd().setTimeZone(sessionTimeZone);
             dowFormat.setTimeZone(sessionTimeZone);
             timeFormat.setTimeZone(sessionTimeZone);
 
@@ -310,9 +318,10 @@
 
     private void formatTimeInterval(StringBuffer buf, TimeInterval timeInterval,
             SimpleDateFormat timeFormat) {
+ Calendar calStart = timeInterval.getStart();
         if (!isDailySession()) {
             buf.append("weekly, ");
-            formatDayOfWeek(buf, startTime.getDay());
+            formatDayOfWeek(buf, calStart.get(Calendar.DAY_OF_WEEK));
             buf.append(" ");
         } else {
             buf.append("daily, ");
@@ -322,11 +331,12 @@
 
         buf.append(" - ");
 
+ Calendar calEnd = timeInterval.getEnd();
         if (!isDailySession()) {
-            formatDayOfWeek(buf, endTime.getDay());
+            formatDayOfWeek(buf, calEnd.get(Calendar.DAY_OF_WEEK));
             buf.append(" ");
         }
-        buf.append(timeFormat.format(timeInterval.getEnd().getTime()));
+        buf.append(timeFormat.format(calEnd.getTime()));
     }
 
     private void formatDayOfWeek(StringBuffer buf, int dayOfWeek) {
@@ -353,4 +363,4 @@
     private int timeInSeconds(int hour, int minute, int second) {
         return (hour * 3600) + (minute * 60) + second;
     }
-}
\ No newline at end of file
+}
diff -rud quickfixj-1.1.0-src\quickfixj\core\src\main\java\quickfix\SessionSettings.java quickfixj-1.1.0-src-patched\quickfixj\core\src\main\java\quickfix\SessionSettings.java
--- quickfixj-1.1.0-src\quickfixj\core\src\main\java\quickfix\SessionSettings.java Wed Apr 11 08:44:51 2007
+++ quickfixj-1.1.0-src-patched\quickfixj\core\src\main\java\quickfix\SessionSettings.java Wed May 23 18:51:57 2007
@@ -23,6 +23,8 @@
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.Reader;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.util.HashMap;
@@ -361,7 +363,8 @@
             Properties currentSection = null;
             String currentSectionId = null;
             Tokenizer tokenizer = new Tokenizer();
-            Tokenizer.Token token = tokenizer.getToken(inputStream);
+    Reader reader = new InputStreamReader(inputStream);
+            Tokenizer.Token token = tokenizer.getToken(reader);
             while (token != null) {
                 if (token.getType() == Tokenizer.SECTION_TOKEN) {
                     storeSection(currentSectionId, currentSection);
@@ -373,12 +376,12 @@
                         currentSection = new Properties(getSessionProperties(DEFAULT_SESSION_ID));
                     }
                 } else if (token.getType() == Tokenizer.ID_TOKEN) {
-                    Tokenizer.Token valueToken = tokenizer.getToken(inputStream);
+                    Tokenizer.Token valueToken = tokenizer.getToken(reader);
                     if (currentSection != null && token != null) {
                         currentSection.put(token.getValue(), valueToken.getValue());
                     }
                 }
-                token = tokenizer.getToken(inputStream);
+                token = tokenizer.getToken(reader);
             }
             storeSection(currentSectionId, currentSection);
         } catch (IOException e) {
@@ -464,39 +467,39 @@
 
         private StringBuffer sb = new StringBuffer();
 
-        private Token getToken(InputStream inputStream) throws IOException {
+        private Token getToken(Reader reader) throws IOException {
             if (ch == '\0') {
-                ch = nextCharacter(inputStream);
+                ch = nextCharacter(reader);
             }
-            skipWhitespace(inputStream);
+            skipWhitespace(reader);
             if (isLabelCharacter(ch)) {
                 sb.setLength(0);
                 do {
                     sb.append(ch);
-                    ch = nextCharacter(inputStream);
+                    ch = nextCharacter(reader);
                 } while (isLabelCharacter(ch));
                 return new Token(ID_TOKEN, sb.toString());
             } else if (ch == '=') {
-                ch = nextCharacter(inputStream);
+                ch = nextCharacter(reader);
                 sb.setLength(0);
                 if (isValueCharacter(ch)) {
                     do {
                         sb.append(ch);
-                        ch = nextCharacter(inputStream);
+                        ch = nextCharacter(reader);
                     } while (isValueCharacter(ch));
                 }
                 return new Token(VALUE_TOKEN, sb.toString().trim());
             } else if (ch == '[') {
-                ch = nextCharacter(inputStream);
-                Token id = getToken(inputStream);
+                ch = nextCharacter(reader);
+                Token id = getToken(reader);
                 // check ]
-                ch = nextCharacter(inputStream); // skip ]
+                ch = nextCharacter(reader); // skip ]
                 return new Token(SECTION_TOKEN, id.getValue());
             } else if (ch == '#') {
                 do {
-                    ch = nextCharacter(inputStream);
+                    ch = nextCharacter(reader);
                 } while (!isNewLineCharacter(ch));
-                return getToken(inputStream);
+                return getToken(reader);
             }
             return null;
         }
@@ -517,14 +520,14 @@
             return (byte) ch == -1;
         }
 
-        private char nextCharacter(InputStream inputStream) throws IOException {
-            return (char) inputStream.read();
+        private char nextCharacter(Reader reader) throws IOException {
+            return (char) reader.read();
         }
 
-        private void skipWhitespace(InputStream inputStream) throws IOException {
+        private void skipWhitespace(Reader reader) throws IOException {
             if (Character.isWhitespace(ch)) {
                 do {
-                    ch = nextCharacter(inputStream);
+                    ch = nextCharacter(reader);
                 } while (Character.isWhitespace(ch));
             }
         }
@@ -687,4 +690,4 @@
         toStream(out);
         return new String(out.toByteArray());
     }
-}
\ No newline at end of file
+}

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Quickfixj-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quickfixj-users
Reply | Threaded
Open this post in threaded view
|

Re: Configuration of weekly session

Stephen Bate
QuickFIX/J Documentation: http://www.quickfixj.org/documentation/
QuickFIX/J Support: http://www.quickfixj.org/support/
Thanks Yong-Jhen,

I've added an RFE with your suggested patches.

Steve

> -----Original Message-----
> From: [hidden email] [mailto:quickfixj-
> [hidden email]] On Behalf Of Yong-Jhen Hong
> Sent: Thursday, May 24, 2007 12:36 AM
> To: [hidden email]
> Subject: [Quickfixj-users] Configuration of weekly session
>
> QuickFIX/J Documentation: http://www.quickfixj.org/documentation/
> QuickFIX/J Support: http://www.quickfixj.org/support/



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Quickfixj-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quickfixj-users