コード例 #1
0
ファイル: TWSUtils.cs プロジェクト: QANTau/QDMS
        public static string TimespanToDurationString(TimeSpan t, QDMS.BarSize minFreq)
        {
            //   duration:
            //     This is the time span the request will cover, and is specified using the
            //     format: , i.e., 1 D, where valid units are: S (seconds) D (days) W (weeks)
            //     M (months) Y (years) If no unit is specified, seconds are used. "years" is
            //     currently limited to one.
            if (minFreq > QDMS.BarSize.OneMonth)
                return Math.Ceiling(Math.Max(1, t.TotalDays / 365)).ToString("0") + " Y";
            if(minFreq >= QDMS.BarSize.OneMonth)
                return Math.Ceiling(Math.Max(1, t.TotalDays / 29)).ToString("0") + " M";
            if(minFreq >= QDMS.BarSize.OneWeek)
                return Math.Ceiling(Math.Max(1, t.TotalDays / 7)).ToString("0") + " W";
            if (minFreq >= QDMS.BarSize.OneDay || t.TotalSeconds > 86400)
            {
                if (t.TotalDays > 14)
                {
                    //This is a ridiculous hack made necessary by the incredibly bad TWS API
                    //For longer periods, if we specify the period as a # of days, the request is rejected!
                    //so instead we do it as the number of weeks and everything is A-OK
                    return Math.Ceiling(t.TotalDays / 7).ToString("0") + " W";
                }
                else
                {
                    return Math.Ceiling(Math.Max(1, t.TotalDays)).ToString("0") + " D";
                }
            }

            return Math.Ceiling(t.TotalSeconds).ToString("0") + " S";
        }
コード例 #2
0
ファイル: JobFactory.cs プロジェクト: leo90skk/qdms
        public JobFactory(IHistoricalDataBroker hdb,
            string host,
            int port,
            string username,
            string password,
            string sender,
            string email,
            UpdateJobSettings updateJobSettings,
            QDMS.IDataStorage localStorage,
            IInstrumentSource instrumentSource,
            IEconomicReleaseBroker erb) : base()
        {
            _hdb = hdb;

            _host = host;
            _port = port;
            _username = username;
            _password = password;
            _sender = sender;
            _email = email;
            _updateJobSettings = updateJobSettings;
            _localStorage = localStorage;
            _instrumentSource = instrumentSource;
            _erb = erb;
        }
コード例 #3
0
ファイル: TWSUtils.cs プロジェクト: QANTau/QDMS
 /// <summary>
 /// Returns the maximum period length of a historical data request, in seconds, depending on the data frequency.
 /// </summary>
 /// <param name="frequency"></param>
 /// <returns>Maximum allowed length in </returns>
 public static int MaxRequestLength(QDMS.BarSize frequency)
 {
     //The limitations are laid out here: https://www.interactivebrokers.com/en/software/api/apiguide/api/historical_data_limitations.htm
     if (frequency <= QDMS.BarSize.OneSecond)      return 1800;
     if (frequency <= QDMS.BarSize.FiveSeconds)    return 7200;
     if (frequency <= QDMS.BarSize.FifteenSeconds) return 14400;
     if (frequency <= QDMS.BarSize.ThirtySeconds)  return 24 * 3600;
     if (frequency <= QDMS.BarSize.OneMinute)      return 2 * 24 * 3600;
     if (frequency <= QDMS.BarSize.ThirtyMinutes)  return 7 * 24 * 3600;
     if (frequency <= QDMS.BarSize.OneHour)        return 29 * 24 * 3600;
     return 365 * 24 * 3600;
 }
コード例 #4
0
ファイル: TWSUtils.cs プロジェクト: ychaim/qdms
        public static Krs.Ats.IBNet.BarSize BarSizeConverter(QDMS.BarSize freq)
        {
            switch (freq)
                {
                    case QDMS.BarSize.Tick:
                        throw new Exception("Bar size conversion impossible, TWS does not suppor tick BarSize");
                    case QDMS.BarSize.OneSecond:
                        return Krs.Ats.IBNet.BarSize.OneSecond;
                    case QDMS.BarSize.FiveSeconds:
                        return Krs.Ats.IBNet.BarSize.FiveSeconds;
                    case QDMS.BarSize.FifteenSeconds:
                        return Krs.Ats.IBNet.BarSize.FifteenSeconds;
                    case QDMS.BarSize.ThirtySeconds:
                        return Krs.Ats.IBNet.BarSize.ThirtySeconds;
                    case QDMS.BarSize.OneMinute:
                        return Krs.Ats.IBNet.BarSize.OneMinute;
                    case QDMS.BarSize.TwoMinutes:
                        return Krs.Ats.IBNet.BarSize.TwoMinutes;
                    case QDMS.BarSize.FiveMinutes:
                        return Krs.Ats.IBNet.BarSize.FiveMinutes;
                    case QDMS.BarSize.FifteenMinutes:
                        return Krs.Ats.IBNet.BarSize.FifteenMinutes;
                    case QDMS.BarSize.ThirtyMinutes:
                        return Krs.Ats.IBNet.BarSize.ThirtyMinutes;
                    case QDMS.BarSize.OneHour:
                        return Krs.Ats.IBNet.BarSize.OneHour;
                    case QDMS.BarSize.OneDay:
                        return Krs.Ats.IBNet.BarSize.OneDay;
                    case QDMS.BarSize.OneWeek:
                        return Krs.Ats.IBNet.BarSize.OneWeek;
                    case QDMS.BarSize.OneMonth:
                        return Krs.Ats.IBNet.BarSize.OneMonth;
                    case QDMS.BarSize.OneQuarter:
                        throw new Exception("Bar size conversion impossible, TWS does not suppor quarter BarSize.");
                    case QDMS.BarSize.OneYear:
                        return Krs.Ats.IBNet.BarSize.OneYear;

                    default:
                        return Krs.Ats.IBNet.BarSize.OneDay;
                }
        }
コード例 #5
0
ファイル: TWSUtils.cs プロジェクト: kod3r/qdms
 public static Krs.Ats.IBNet.BarSize BarSizeConverter(QDMS.BarSize freq)
 {
     if (freq == QDMS.BarSize.Tick) throw new Exception("Bar size conversion impossible, TWS does not suppor tick size");
     return (Krs.Ats.IBNet.BarSize)(int)freq;
 }
コード例 #6
0
ファイル: TWSUtils.cs プロジェクト: kod3r/qdms
        public static string TimespanToDurationString(TimeSpan t, QDMS.BarSize minFreq)
        {
            //   duration:
            //     This is the time span the request will cover, and is specified using the
            //     format: , i.e., 1 D, where valid units are: S (seconds) D (days) W (weeks)
            //     M (months) Y (years) If no unit is specified, seconds are used. "years" is
            //     currently limited to one.
            if (minFreq > QDMS.BarSize.OneMonth)
                return Math.Ceiling(t.TotalDays / 365).ToString("0") + " Y";
            if(minFreq >= QDMS.BarSize.OneMonth)
                return Math.Ceiling(t.TotalDays / 29).ToString("0") + " M";
            if(minFreq >= QDMS.BarSize.OneWeek)
                return Math.Ceiling(t.TotalDays / 7).ToString("0") + " W";
            if (minFreq >= QDMS.BarSize.OneDay)
                return Math.Ceiling(t.TotalDays).ToString("0") + " D";

            return Math.Ceiling(t.TotalSeconds).ToString("0") + " S";
        }