[Quantproject-developers] QuantProject/b2_DataAccess/Tables Bars.cs, 1.8, 1.9
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2009-02-08 16:43:38
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv7782/b2_DataAccess/Tables Modified Files: Bars.cs Log Message: Added GetLow and GetHigh methods; code has been reorganized properly. Now the EmptyQueryException is thrown if necessary. Index: Bars.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables/Bars.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Bars.cs 5 Feb 2009 22:11:54 -0000 1.8 --- Bars.cs 8 Feb 2009 16:43:34 -0000 1.9 *************** *** 123,159 **** } ! /// <summary> ! /// Returns the close for the given ticker at the specified date ! /// time ! /// </summary> ! /// <param name="ticker">ticker for which the close has to be returned</param> ! /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> ! /// <returns></returns> ! public static double GetClose( string ticker, DateTime dateTime, int intervalFrameInSeconds ) { ! DataTable dataTable = SqlExecutor.GetDataTable( ! "select " + Bars.Close + " from bars " + "where " + Bars.TickerFieldName + "='" + ticker + "' and " + Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + ! "and " + Bars.DateTimeForOpen + "=" + SQLBuilder.GetDateTimeConstant(dateTime) ); ! return (double)dataTable.Rows[0][0]; } /// <summary> ! /// Returns the open for the given ticker at the specified date ! /// time /// </summary> /// <param name="ticker">ticker for which the raw open has to be returned</param> ! /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bars</param> /// <returns></returns> public static double GetOpen( string ticker, DateTime dateTime, int intervalFrameInSeconds ) { ! DataTable dataTable = SqlExecutor.GetDataTable( ! "select " + Bars.Open + " from bars " + ! "where " + Bars.TickerFieldName + "='" + ticker + "' and " + ! Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + ! "and " + Bars.DateTimeForOpen + "=" + SQLBuilder.GetDateTimeConstant(dateTime) ); ! return (double)dataTable.Rows[0][0]; } // /// <summary> --- 123,185 ---- } ! #region GetOpen, GetHigh, GetLow, GetClose ! ! private static double getValueFromBar( string ticker, DateTime dateTime, int intervalFrameInSeconds, ! string fieldNameContainingValue) { ! double returnValue = Double.NaN; ! string sqlQuery = "select " + fieldNameContainingValue + " from bars " + "where " + Bars.TickerFieldName + "='" + ticker + "' and " + Bars.IntervalFrameInSeconds + "='" + intervalFrameInSeconds + "' " + ! "and " + Bars.DateTimeForOpen + "=" + SQLBuilder.GetDateTimeConstant(dateTime); ! DataTable dataTable = SqlExecutor.GetDataTable( sqlQuery ); ! if( dataTable.Rows.Count > 0 ) ! returnValue = (double)dataTable.Rows[0][0]; ! else ! throw new EmptyQueryException( sqlQuery ); ! return returnValue; } /// <summary> ! /// Returns the open for the given ticker for the given bar that opens at the specified date time /// </summary> /// <param name="ticker">ticker for which the raw open has to be returned</param> ! /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bar</param> /// <returns></returns> public static double GetOpen( string ticker, DateTime dateTime, int intervalFrameInSeconds ) { ! return getValueFromBar(ticker, dateTime, intervalFrameInSeconds, Bars.Open); ! } ! /// <summary> ! /// Returns the high for the given ticker for the given bar that opens at the specified date time ! /// </summary> ! /// <param name="ticker">ticker for which the raw high has to be returned</param> ! /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bar</param> ! /// <returns></returns> ! public static double GetHigh( string ticker, DateTime dateTime, int intervalFrameInSeconds ) ! { ! return getValueFromBar(ticker, dateTime, intervalFrameInSeconds, Bars.High); ! } ! /// <summary> ! /// Returns the low for the given ticker for the given bar that opens at the specified date time ! /// </summary> ! /// <param name="ticker">ticker for which the raw low has to be returned</param> ! /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bar</param> ! /// <returns></returns> ! public static double GetLow( string ticker, DateTime dateTime, int intervalFrameInSeconds ) ! { ! return getValueFromBar(ticker, dateTime, intervalFrameInSeconds, Bars.Low); ! } ! /// <summary> ! /// Returns the close for the given ticker for the given bar that opens at the specified date time ! /// </summary> ! /// <param name="ticker">ticker for which the raw close has to be returned</param> ! /// <param name="intervalFrameInSeconds">interval frame in seconds for the ticker's bar</param> ! /// <returns></returns> ! public static double GetClose( string ticker, DateTime dateTime, int intervalFrameInSeconds ) ! { ! return getValueFromBar(ticker, dateTime, intervalFrameInSeconds, Bars.Close); } + #endregion // /// <summary> |