コード例 #1
0
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        public object Clone()
        {
            var clone = new ContinuousFuture
            {
                InstrumentID       = InstrumentID,
                Instrument         = Instrument,
                UnderlyingSymbol   = UnderlyingSymbol,
                UnderlyingSymbolID = UnderlyingSymbolID,
                Month          = Month,
                RolloverType   = RolloverType,
                RolloverDays   = RolloverDays,
                AdjustmentMode = AdjustmentMode,
                UseJan         = UseJan,
                UseFeb         = UseFeb,
                UseMar         = UseMar,
                UseApr         = UseApr,
                UseMay         = UseMay,
                UseJun         = UseJun,
                UseJul         = UseJul,
                UseAug         = UseAug,
                UseSep         = UseSep,
                UseOct         = UseOct,
                UseNov         = UseNov,
                UseDec         = UseDec
            };

            return(clone);
        }
コード例 #2
0
ファイル: ContinuousFutureTest.cs プロジェクト: leo90skk/qdms
 public void UseMonthSerializesCorrectlyWhenSetToFalse()
 {
     var ms = new MemoryStream();
     var cf = new ContinuousFuture();
     cf.UseDec = false;
     var serialized = MyUtils.ProtoBufSerialize(cf, ms);
     var cf2 = MyUtils.ProtoBufDeserialize<ContinuousFuture>(serialized, ms);
     Assert.AreEqual(false, cf2.UseDec);
 }
コード例 #3
0
        public void RaisesDataEventWithTheContinuousFuturesAlias()
        {
            var cf = new ContinuousFuture()
            {
                ID = 1,
                InstrumentID = 1,
                Month = 1,
                UnderlyingSymbol = new UnderlyingSymbol
                {
                    ID = 1,
                    Symbol = "VIX",
                    Rule = new ExpirationRule()
                }
            };

            var inst = new Instrument
            {
                ID = 1,
                Symbol = "VIXCONTFUT",
                IsContinuousFuture = true,
                ContinuousFuture = cf,
                Datasource = new Datasource { ID = 999, Name = "MockSource" }
            };

            var req = new RealTimeDataRequest(inst, BarSize.FiveSeconds);

            _cfBrokerMock.Setup(x => x.RequestFrontContract(It.IsAny<Instrument>(), It.IsAny<DateTime?>())).Returns(0);
            int assignedID = 0;
            _dataSourceMock.Setup(x => x.RequestRealTimeData(It.IsAny<RealTimeDataRequest>())).Callback<RealTimeDataRequest>(r => assignedID = r.AssignedID);

            bool raisedCorrectSymbol = false;
            _broker.RealTimeDataArrived += (sender, e) =>
                raisedCorrectSymbol = raisedCorrectSymbol ? raisedCorrectSymbol : e.InstrumentID == 1;
            _broker.RequestRealTimeData(req);

            var frontFutureInstrument = new Instrument
            {
                Symbol = "VXF4",
                ID = 2,
                Datasource = new Datasource { ID = 999, Name = "MockSource" }
            };

            _cfBrokerMock.Raise(x => x.FoundFrontContract += null, new FoundFrontContractEventArgs(0, frontFutureInstrument, DateTime.Now));

            _dataSourceMock.Raise(x => x.DataReceived += null,
                new RealTimeDataEventArgs(2, MyUtils.ConvertToTimestamp(DateTime.Now), 100, 100, 100, 100, 50, 100, 2, assignedID));

            Thread.Sleep(50);

            Assert.IsTrue(raisedCorrectSymbol);
        }
コード例 #4
0
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        public object Clone()
        {
            var clone = new Instrument
            {
                ID                 = ID,
                Symbol             = Symbol,
                UnderlyingSymbol   = UnderlyingSymbol,
                PrimaryExchangeID  = PrimaryExchangeID,
                Name               = Name,
                ExchangeID         = ExchangeID,
                Type               = Type,
                Multiplier         = Multiplier,
                Expiration         = Expiration,
                OptionType         = OptionType,
                Strike             = Strike,
                Currency           = Currency,
                MinTick            = MinTick,
                Industry           = Industry,
                Category           = Category,
                Subcategory        = Subcategory,
                IsContinuousFuture = IsContinuousFuture,
                ContinuousFutureID = ContinuousFutureID,
                ValidExchanges     = ValidExchanges,
                DatasourceID       = DatasourceID,
                Exchange           = Exchange,
                PrimaryExchange    = PrimaryExchange,
                Datasource         = Datasource,
                Tags               = Tags == null ? null : Tags.ToList(),
                Sessions           = Sessions == null ? null : Sessions.Select(x => (InstrumentSession)x.Clone()).ToList(),
                SessionsSource     = SessionsSource,
                SessionTemplateID  = SessionTemplateID,
                DatasourceSymbol   = DatasourceSymbol,
                TradingClass       = TradingClass
            };

            if (ContinuousFuture != null)
            {
                clone.ContinuousFuture = (ContinuousFuture)ContinuousFuture.Clone();
            }
            return(clone);
        }
コード例 #5
0
        public void SetUp()
        {
            _clientMock = new Mock<IDataClient>();
            _instrumentMgrMock = new Mock<IInstrumentSource>();
            _broker = new ContinuousFuturesBroker(_clientMock.Object, _instrumentMgrMock.Object);

            _cfInst = new Instrument();
            _cfInst.Type = InstrumentType.Future;
            _cfInst.DatasourceID = 1;
            _cfInst.Datasource = new Datasource { ID = 1, Name = "Interactive Brokers" };

            var cf = new ContinuousFuture();
            cf.Month = 1;
            _cfInst.IsContinuousFuture = true;
            _cfInst.ContinuousFuture = cf;
            _cfInst.ContinuousFuture.AdjustmentMode = ContinuousFuturesAdjustmentMode.NoAdjustment;

            var vix = new UnderlyingSymbol();
            vix.Rule = new ExpirationRule
            {
                DaysBefore = 30,
                DayType = DayType.Calendar,
                ReferenceRelativeMonth = RelativeMonth.NextMonth,
                ReferenceUsesDays = false,
                ReferenceWeekDay = DayOfTheWeek.Friday,
                ReferenceWeekDayCount = WeekDayCount.Third,
                ReferenceDayMustBeBusinessDay = true
            };
            vix.Symbol = "VIX";

            _cfInst.ContinuousFuture.UnderlyingSymbol = vix;

            _req = new HistoricalDataRequest(
                _cfInst,
                BarSize.OneDay,
                new DateTime(2013, 1, 1),
                new DateTime(2013, 2, 1));
        }
コード例 #6
0
ファイル: ContinuousFuture.cs プロジェクト: ychaim/qdms
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        public object Clone()
        {
            var clone = new ContinuousFuture
            {
                InstrumentID = InstrumentID,
                Instrument = Instrument,
                UnderlyingSymbol = UnderlyingSymbol,
                UnderlyingSymbolID = UnderlyingSymbolID,
                Month = Month,
                RolloverType = RolloverType,
                RolloverDays = RolloverDays,
                AdjustmentMode = AdjustmentMode,
                UseJan = UseJan,
                UseFeb = UseFeb,
                UseMar = UseMar,
                UseApr = UseApr,
                UseMay = UseMay,
                UseJun = UseJun,
                UseJul = UseJul,
                UseAug = UseAug,
                UseSep = UseSep,
                UseOct = UseOct,
                UseNov = UseNov,
                UseDec = UseDec
            };

            return clone;
        }
コード例 #7
0
        public void RequestsFrontContractFromCFBrokerForContinuousFuturesRequests()
        {
            var cf = new ContinuousFuture()
            {
                ID = 1,
                InstrumentID = 1,
                Month = 1,
                UnderlyingSymbol = new UnderlyingSymbol
                {
                    ID = 1,
                   Symbol = "VIX",
                   Rule = new ExpirationRule()
                }
            };

            var inst = new Instrument
            {
                ID = 1,
                Symbol = "VIXCONTFUT",
                IsContinuousFuture = true,
                ContinuousFuture = cf,
                Datasource = new Datasource { ID = 999, Name = "MockSource" }
            };

            var req = new RealTimeDataRequest(inst, BarSize.FiveSeconds);

            _cfBrokerMock.Setup(x => x.RequestFrontContract(It.IsAny<Instrument>(), It.IsAny<DateTime?>())).Returns(0);

            _broker.RequestRealTimeData(req);

            _cfBrokerMock.Verify(x => x.RequestFrontContract(It.IsAny<Instrument>(), It.IsAny<DateTime?>()));
        }
コード例 #8
0
        public void RequestsCorrectFuturesContractForContinuousFutures()
        {
            var cf = new ContinuousFuture()
            {
                ID = 1,
                InstrumentID = 1,
                Month = 1,
                UnderlyingSymbol = new UnderlyingSymbol
                {
                    ID = 1,
                    Symbol = "VIX",
                    Rule = new ExpirationRule()
                }
            };

            var inst = new Instrument
            {
                ID = 1,
                Symbol = "VIXCONTFUT",
                IsContinuousFuture = true,
                ContinuousFuture = cf,
                Datasource = new Datasource { ID = 999, Name = "MockSource" }
            };

            var req = new RealTimeDataRequest(inst, BarSize.FiveSeconds);

            _cfBrokerMock.Setup(x => x.RequestFrontContract(It.IsAny<Instrument>(), It.IsAny<DateTime?>())).Returns(0);

            _broker.RequestRealTimeData(req);

            var frontFutureInstrument = new Instrument
            {
                Symbol = "VXF4",
                ID = 2,
                Datasource = new Datasource { ID = 999, Name = "MockSource" }
            };

            _cfBrokerMock.Raise(x => x.FoundFrontContract += null, new FoundFrontContractEventArgs(0, frontFutureInstrument, DateTime.Now));

            _dataSourceMock.Verify(x => x.RequestRealTimeData(
                It.Is<RealTimeDataRequest>(y =>
                    y.Instrument.ID == 2)), Times.Once);
        }
コード例 #9
0
        public void SetUp()
        {
            _clientMock = new Mock<IDataClient>();
            _instrumentMgrMock = new Mock<IInstrumentSource>();
            _broker = new ContinuousFuturesBroker(_clientMock.Object, _instrumentMgrMock.Object);

            _cfInst = new Instrument();
            _cfInst.Type = InstrumentType.Future;
            _cfInst.DatasourceID = 1;
            _cfInst.Datasource = new Datasource { ID = 1, Name = "Interactive Brokers" };

            var cf = new ContinuousFuture();
            cf.Month = 1;
            _cfInst.ContinuousFuture = cf;
            _cfInst.ContinuousFuture.AdjustmentMode = ContinuousFuturesAdjustmentMode.NoAdjustment;

            var underlying = new UnderlyingSymbol();
            underlying.Symbol = "VIX";

            _cfInst.ContinuousFuture.UnderlyingSymbol = underlying;

            _req = new HistoricalDataRequest(
                _cfInst,
                BarSize.OneDay,
                new DateTime(2013, 1, 1),
                new DateTime(2013, 2, 1));
        }