Ejemplo n.º 1
0
        public void StoreData_SecurityCacheHasTradeAndQuoteTick()
        {
            // Arrange
            var securityCache = new SecurityCache();
            var time          = DateTime.Now;

            var quote = new Tick(time, Symbol.Empty, 100, 102)
            {
                TickType = TickType.Quote
            };

            securityCache.StoreData(new[] { quote }, typeof(Tick));

            var trade = new Tick(time.AddMilliseconds(1), Symbol.Empty, 100, 100, 102)
            {
                TickType = TickType.Trade
            };

            securityCache.StoreData(new[] { trade }, typeof(Tick));

            // Adding OpenInterest as Tick or OpenInterest should not matter
            var openInterest = new OpenInterest(time, Symbol.Empty, 1000);

            securityCache.StoreData(new[] { openInterest }, typeof(Tick));           // Add as Tick
            securityCache.StoreData(new[] { openInterest }, typeof(OpenInterest));   // Add as OI

            // Assert
            Assert.IsTrue(securityCache.HasData(typeof(Tick)));
            Assert.True(securityCache.GetData <Tick>().Equals(trade));
            Assert.True(securityCache.GetData <OpenInterest>().Equals(openInterest));

            Assert.True(securityCache.GetAll <Tick>().LastOrDefault(x => x.TickType == TickType.Quote).Equals(quote));
            Assert.True(securityCache.GetAll <Tick>().LastOrDefault(x => x.TickType == TickType.Trade).Equals(trade));
        }
Ejemplo n.º 2
0
        public void AccessesByDataType()
        {
            var now      = DateTime.UtcNow;
            var tradeBar = new TradeBar {
                Symbol = Symbols.SPY, Time = now
            };
            var quandl = new Quandl {
                Symbol = Symbols.SPY, Time = now
            };
            var quoteBar = new QuoteBar {
                Symbol = Symbols.SPY, Time = now
            };
            var tick = new Tick(now, Symbols.SPY, 1.1m, 2.1m)
            {
                TickType = TickType.Trade
            };
            var openInterest = new OpenInterest(now, Symbols.SPY, 1);
            var split        = new Split(Symbols.SPY, now, 1, 1, SplitType.SplitOccurred);
            var delisting    = new Delisting(Symbols.SPY, now, 1, DelistingType.Delisted);

            var slice = new Slice(now, new BaseData[] { quoteBar, tradeBar, quandl, tick, split, delisting, openInterest });

            Assert.AreEqual(slice.Get(typeof(TradeBar))[Symbols.SPY], tradeBar);
            Assert.AreEqual(slice.Get(typeof(Quandl))[Symbols.SPY], quandl);
            Assert.AreEqual(slice.Get(typeof(QuoteBar))[Symbols.SPY], quoteBar);
            Assert.AreEqual(slice.Get(typeof(Tick))[Symbols.SPY], tick);
            Assert.AreEqual(slice.Get(typeof(Split))[Symbols.SPY], split);
            Assert.AreEqual(slice.Get(typeof(Delisting))[Symbols.SPY], delisting);
            Assert.AreEqual(slice.Get(typeof(OpenInterest))[Symbols.SPY], openInterest);
        }
Ejemplo n.º 3
0
        public void AddData_SecurityCacheHasTradeAndQuoteTick()
        {
            // Arrange
            var securityCache = new SecurityCache();
            var time          = DateTime.Now;

            var quote = new Tick(time, Symbol.Empty, 100, 102)
            {
                TickType = TickType.Quote
            };

            securityCache.AddData(quote);

            var trade = new Tick(time, Symbol.Empty, 100, 100, 102)
            {
                TickType = TickType.Trade
            };

            securityCache.AddData(trade);

            var openInterest = new OpenInterest(time, Symbol.Empty, 1000);

            securityCache.AddData(openInterest);

            // Assert
            Assert.True(securityCache.GetData().Equals(trade));
            Assert.True(securityCache.GetData <Tick>().Equals(trade));

            Assert.True(securityCache.GetAll <Tick>().LastOrDefault(x => x.TickType == TickType.Quote).Equals(quote));
            Assert.True(securityCache.GetAll <Tick>().LastOrDefault(x => x.TickType == TickType.Trade).Equals(trade));
        }
Ejemplo n.º 4
0
        private void EscapeUsingUserControl(object e)
        {
            Globals.IsOiWindowOPen = false;
            OpenInterest oOpenInterest = e as OpenInterest;

            oOpenInterest.Hide();
        }
Ejemplo n.º 5
0
        public void PythonGetBySymbolOpenInterest()
        {
            using (Py.GIL())
            {
                dynamic test = PythonEngine.ModuleFromString("testModule",
                                                             @"
from AlgorithmImports import *
from QuantConnect.Tests import *

def Test(slice):
    data = slice.Get(OpenInterest)
    value = data[Symbols.AAPL].Value
    if value != 33:
        raise Exception('Unexpected value')").GetAttr("Test");
                var now         = DateTime.UtcNow;
                var TradeBarSpy = new TradeBar {
                    Symbol = Symbols.SPY, Time = now, Value = 8
                };
                var TradeBarAapl = new TradeBar {
                    Symbol = Symbols.AAPL, Time = now, Value = 9
                };
                var unlinkedDataSpy = new UnlinkedData {
                    Symbol = Symbols.SPY, Time = now, Value = 10
                };
                var unlinkedDataAapl = new UnlinkedData {
                    Symbol = Symbols.AAPL, Time = now, Value = 11
                };
                var openInterest = new OpenInterest(now, Symbols.AAPL, 33);
                var slice        = new Slice(now, new BaseData[] { unlinkedDataSpy, TradeBarAapl, unlinkedDataAapl, TradeBarSpy, openInterest });

                Assert.DoesNotThrow(() => test(new PythonSlice(slice)));
            }
        }
Ejemplo n.º 6
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = (SecurityCode != null
                                 ? SecurityCode.GetHashCode()
                                 : 0);
         hashCode = (hashCode * 397) ^ (OptionNumber != null
                                 ? OptionNumber.GetHashCode()
                                 : 0);
         hashCode = (hashCode * 397) ^ (OptionCode != null
                                 ? OptionCode.GetHashCode()
                                 : 0);
         hashCode = (hashCode * 397) ^ Bid.GetHashCode();
         hashCode = (hashCode * 397) ^ BidVolume.GetHashCode();
         hashCode = (hashCode * 397) ^ Ask.GetHashCode();
         hashCode = (hashCode * 397) ^ AskVolume.GetHashCode();
         hashCode = (hashCode * 397) ^ Volume.GetHashCode();
         hashCode = (hashCode * 397) ^ Bid2.GetHashCode();
         hashCode = (hashCode * 397) ^ BidVolume2.GetHashCode();
         hashCode = (hashCode * 397) ^ Ask2.GetHashCode();
         hashCode = (hashCode * 397) ^ AskVolume2.GetHashCode();
         hashCode = (hashCode * 397) ^ Bid3.GetHashCode();
         hashCode = (hashCode * 397) ^ BidVolume3.GetHashCode();
         hashCode = (hashCode * 397) ^ Ask3.GetHashCode();
         hashCode = (hashCode * 397) ^ AskVolume3.GetHashCode();
         hashCode = (hashCode * 397) ^ Bid4.GetHashCode();
         hashCode = (hashCode * 397) ^ BidVolume4.GetHashCode();
         hashCode = (hashCode * 397) ^ Ask4.GetHashCode();
         hashCode = (hashCode * 397) ^ AskVolume4.GetHashCode();
         hashCode = (hashCode * 397) ^ Bid5.GetHashCode();
         hashCode = (hashCode * 397) ^ BidVolume5.GetHashCode();
         hashCode = (hashCode * 397) ^ Ask5.GetHashCode();
         hashCode = (hashCode * 397) ^ AskVolume5.GetHashCode();
         hashCode = (hashCode * 397) ^ (Greeks != null
                                 ? Greeks.GetHashCode()
                                 : 0);
         hashCode = (hashCode * 397) ^ OpenInterest.GetHashCode();
         hashCode = (hashCode * 397) ^ Turnover.GetHashCode();
         hashCode = (hashCode * 397) ^ UncoveredPositionQuantity.GetHashCode();
         hashCode = (hashCode * 397) ^ PreviousSettlementPrice.GetHashCode();
         hashCode = (hashCode * 397) ^ OpeningPrice.GetHashCode();
         hashCode = (hashCode * 397) ^ AuctionReferencePrice.GetHashCode();
         hashCode = (hashCode * 397) ^ AuctionReferenceQuantity.GetHashCode();
         hashCode = (hashCode * 397) ^ HighestPrice.GetHashCode();
         hashCode = (hashCode * 397) ^ LowestPrice.GetHashCode();
         hashCode = (hashCode * 397) ^ LatestTradedPrice.GetHashCode();
         hashCode = (hashCode * 397) ^ Change.GetHashCode();
         hashCode = (hashCode * 397) ^ ChangePercentage.GetHashCode();
         hashCode = (hashCode * 397) ^ PreviousClose.GetHashCode();
         hashCode = (hashCode * 397) ^ (Name != null
                                 ? Name.GetHashCode()
                                 : 0);
         return(hashCode);
     }
 }
Ejemplo n.º 7
0
        public override int GetHashCode()
        {
            unchecked
            {
                var hash = 17;
                hash = hash * 29 + RequestId != null?RequestId.GetHashCode() : 0;

                hash = hash * 29 + Timestamp.GetHashCode();
                hash = hash * 29 + High.GetHashCode();
                hash = hash * 29 + Low.GetHashCode();
                hash = hash * 29 + Open.GetHashCode();
                hash = hash * 29 + Close.GetHashCode();
                hash = hash * 29 + PeriodVolume.GetHashCode();
                hash = hash * 29 + OpenInterest.GetHashCode();
                return(hash);
            }
        }
Ejemplo n.º 8
0
        public void OpenInterestSerializationRoundTrip()
        {
            var openInterest = new OpenInterest(DateTime.UtcNow, Symbols.AAPL, 10);

            var serializedTick = openInterest.ProtobufSerialize();

            // verify its correct
            using (var stream = new MemoryStream(serializedTick))
            {
                var result = (Tick)Serializer.Deserialize <IEnumerable <BaseData> >(stream).First();

                Assert.IsNull(result.Symbol);
                Assert.AreEqual(openInterest.Time, result.Time);
                Assert.AreEqual(openInterest.EndTime, result.EndTime);
                Assert.AreEqual(openInterest.Value, result.Value);
            }
        }
        public override int GetHashCode()
        {
            unchecked
            {
                var hash = 17;
                hash = hash * 29 + RequestId != null?RequestId.GetHashCode() : 0;

                hash = hash * 29 + Symbol.GetHashCode();
                hash = hash * 29 + ExchangeId.GetHashCode();
                hash = hash * 29 + SecurityType.GetHashCode();
                hash = hash * 29 + (Last.HasValue ? Last.GetHashCode() : 0);
                hash = hash * 29 + (TradeSize.HasValue ? TradeSize.GetHashCode() : 0);
                hash = hash * 29 + (TradedMarket.HasValue ? TradedMarket.GetHashCode() : 0);
                hash = hash * 29 + (TradeDate.HasValue ? TradeDate.GetHashCode() : 0);
                hash = hash * 29 + (TradeTime.HasValue ? TradeTime.GetHashCode() : 0);
                hash = hash * 29 + (Open.HasValue ? Open.GetHashCode() : 0);
                hash = hash * 29 + (High.HasValue ? High.GetHashCode() : 0);
                hash = hash * 29 + (Low.HasValue ? Low.GetHashCode() : 0);
                hash = hash * 29 + (Close.HasValue ? Close.GetHashCode() : 0);
                hash = hash * 29 + (Bid.HasValue ? Bid.GetHashCode() : 0);
                hash = hash * 29 + (BidMarket.HasValue ? BidMarket.GetHashCode() : 0);
                hash = hash * 29 + (BidSize.HasValue ? BidSize.GetHashCode() : 0);
                hash = hash * 29 + (Ask.HasValue ? Ask.GetHashCode() : 0);
                hash = hash * 29 + (AskMarket.HasValue ? AskMarket.GetHashCode() : 0);
                hash = hash * 29 + (AskSize.HasValue ? AskSize.GetHashCode() : 0);
                hash = hash * 29 + (Volume.HasValue ? Volume.GetHashCode() : 0);
                hash = hash * 29 + (PDayVolume.HasValue ? PDayVolume.GetHashCode() : 0);
                hash = hash * 29 + (UpVolume.HasValue ? UpVolume.GetHashCode() : 0);
                hash = hash * 29 + (DownVolume.HasValue ? DownVolume.GetHashCode() : 0);
                hash = hash * 29 + (NeutralVolume.HasValue ? NeutralVolume.GetHashCode() : 0);
                hash = hash * 29 + (TradeCount.HasValue ? TradeCount.GetHashCode() : 0);
                hash = hash * 29 + (UpTrades.HasValue ? UpTrades.GetHashCode() : 0);
                hash = hash * 29 + (DownTrades.HasValue ? DownTrades.GetHashCode() : 0);
                hash = hash * 29 + (NeutralTrades.HasValue ? NeutralTrades.GetHashCode() : 0);
                hash = hash * 29 + (VWAP.HasValue ? VWAP.GetHashCode() : 0);
                hash = hash * 29 + (MutualDiv.HasValue ? MutualDiv.GetHashCode() : 0);
                hash = hash * 29 + (SevenDayYield.HasValue ? SevenDayYield.GetHashCode() : 0);
                hash = hash * 29 + (OpenInterest.HasValue ? OpenInterest.GetHashCode() : 0);
                hash = hash * 29 + (Settlement.HasValue ? Settlement.GetHashCode() : 0);
                hash = hash * 29 + (SettlementDate.HasValue ? SettlementDate.GetHashCode() : 0);
                hash = hash * 29 + (ExpirationDate.HasValue ? ExpirationDate.GetHashCode() : 0);
                hash = hash * 29 + (Strike.HasValue ? Strike.GetHashCode() : 0);
                return(hash);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Pushes the tick into this enumerator. This tick will be aggregated into a OI bar
        /// and emitted after the alotted time has passed
        /// </summary>
        /// <param name="data">The new data to be aggregated</param>
        public void ProcessData(Tick data)
        {
            OpenInterest working;

            if (!_queue.TryPeek(out working))
            {
                // the consumer took the working bar, or time ticked over into next bar
                var currentLocalTime = _timeProvider.GetUtcNow().ConvertFromUtc(_timeZone);
                var barStartTime     = currentLocalTime.RoundDown(_barSize);
                working         = new OpenInterest(barStartTime, data.Symbol, data.Value);
                working.EndTime = barStartTime + _barSize;
                _queue.Enqueue(working);
            }
            else
            {
                working.Value = data.Value;
            }
        }
Ejemplo n.º 11
0
        public void HandlesOpenInterestTicks([ValueSource(nameof(ResolutionCases))] Resolution resolution, [ValueSource(nameof(SymbolCases))] Symbol symbol)
        {
            // Arrange
            var converter             = new PandasConverter();
            var tickType              = TickType.OpenInterest;
            var dataType              = LeanData.GetDataType(resolution, tickType);
            var subcriptionDataConfig = new SubscriptionDataConfig(dataType, symbol, resolution,
                                                                   TimeZones.Chicago, TimeZones.Chicago,
                                                                   tickType: tickType, fillForward: false,
                                                                   extendedHours: true, isInternalFeed: true);
            var openinterest = new List <OpenInterest>();

            for (int i = 0; i < 10; i++)
            {
                var line = $"{1000 * i},{11 * i}";
                var openInterestTicks = new OpenInterest(subcriptionDataConfig, symbol, line, new DateTime(2017, 10, 10));
                openinterest.Add(openInterestTicks);
            }

            // Act
            dynamic dataFrame = converter.GetDataFrame(openinterest);

            //Assert
            using (Py.GIL())
            {
                Assert.IsFalse(dataFrame.empty.AsManagedObject(typeof(bool)));

                var subDataFrame = dataFrame.loc[symbol.Value];
                Assert.IsFalse(subDataFrame.empty.AsManagedObject(typeof(bool)));

                Assert.IsTrue(subDataFrame.get("openinterest") != null);

                var count = subDataFrame.shape[0].AsManagedObject(typeof(int));
                Assert.AreEqual(count, 10);

                for (var i = 0; i < count; i++)
                {
                    var index = subDataFrame.index[i];
                    var value = subDataFrame.loc[index].openinterest.AsManagedObject(typeof(decimal));
                    Assert.AreEqual(openinterest[i].Value, value);
                }
            }
        }
Ejemplo n.º 12
0
        public void StoreData_TargetToModify_SecurityCacheHasTradeAndQuoteTick()
        {
            // Arrange
            var sourceToShare = new SecurityCache();
            var time          = DateTime.Now;

            var quote = new Tick(time, Symbol.Empty, 100, 102)
            {
                TickType = TickType.Quote
            };

            sourceToShare.StoreData(new[] { quote }, typeof(Tick));

            var trade = new Tick(time, Symbol.Empty, 100, 100, 102)
            {
                TickType = TickType.Trade
            };

            sourceToShare.StoreData(new[] { trade }, typeof(Tick));

            // Adding OpenInterest as Tick or OpenInterest should not matter
            var openInterest = new OpenInterest(time, Symbol.Empty, 1000);

            sourceToShare.StoreData(new[] { openInterest }, typeof(Tick));           // Add as Tick
            sourceToShare.StoreData(new[] { openInterest }, typeof(OpenInterest));   // Add as OI

            var targetToModify = new SecurityCache();

            SecurityCache.ShareTypeCacheInstance(sourceToShare, targetToModify);

            // Assert
            Assert.IsTrue(targetToModify.HasData(typeof(Tick)));
            Assert.True(targetToModify.GetData <Tick>().Equals(trade));
            Assert.True(targetToModify.GetData <OpenInterest>().Equals(openInterest));

            Assert.True(targetToModify.GetAll <Tick>().LastOrDefault(x => x.TickType == TickType.Quote).Equals(quote));
            Assert.True(targetToModify.GetAll <Tick>().LastOrDefault(x => x.TickType == TickType.Trade).Equals(trade));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Pushes the tick into this enumerator. This tick will be aggregated into a OI bar
        /// and emitted after the alotted time has passed
        /// </summary>
        /// <param name="data">The new data to be aggregated</param>
        public void ProcessData(Tick data)
        {
            OpenInterest working;

            if (!_queue.TryPeek(out working))
            {
                // the consumer took the working bar, or time ticked over into next bar
                var utcNow           = _timeProvider.GetUtcNow();
                var currentLocalTime = utcNow.ConvertFromUtc(_timeZone);
                var barStartTime     = currentLocalTime.RoundDown(_barSize);
                working         = new OpenInterest(barStartTime, data.Symbol, data.Value);
                working.EndTime = barStartTime + _barSize;
                _queue.Enqueue(working);

                if (_liveMode)
                {
                    _realTimeScheduleEventService.ScheduleEvent(_barSize.Subtract(currentLocalTime - barStartTime), utcNow);
                }
            }
            else
            {
                working.Value = data.Value;
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Handle a new price update packet:
        /// </summary>
        private void OnLevel1SummaryUpdateEvent(object sender, Level1SummaryUpdateEventArgs e)
        {
            // if ticker is not found, unsubscribe
            if (e.NotFound)
            {
                Unsubscribe(e.Symbol);
            }

            // only update if we have a value
            if (e.Last == 0)
            {
                return;
            }

            // only accept trade and B/A updates
            if (e.TypeOfUpdate != Level1SummaryUpdateEventArgs.UpdateType.ExtendedTrade &&
                e.TypeOfUpdate != Level1SummaryUpdateEventArgs.UpdateType.Trade &&
                e.TypeOfUpdate != Level1SummaryUpdateEventArgs.UpdateType.Bid &&
                e.TypeOfUpdate != Level1SummaryUpdateEventArgs.UpdateType.Ask)
            {
                return;
            }

            count++;
            var time = FeedTime;
            var last = (decimal)(e.TypeOfUpdate == Level1SummaryUpdateEventArgs.UpdateType.ExtendedTrade ? e.ExtendedTradingLast : e.Last);

            var symbol = GetLeanSymbol(e.Symbol);

            TickType tradeType;

            switch (symbol.ID.SecurityType)
            {
            // the feed time is in NYC/EDT, convert it into EST
            case SecurityType.Forex:

                time = FeedTime.ConvertTo(TimeZones.NewYork, TimeZones.EasternStandard);
                // TypeOfUpdate always equal to UpdateType.Trade for FXCM, but the message contains B/A and last data
                tradeType = TickType.Quote;

                break;

            // for all other asset classes we leave it as is (NYC/EDT)
            default:

                time      = FeedTime;
                tradeType = e.TypeOfUpdate == Level1SummaryUpdateEventArgs.UpdateType.Bid ||
                            e.TypeOfUpdate == Level1SummaryUpdateEventArgs.UpdateType.Ask ?
                            TickType.Quote :
                            TickType.Trade;
                break;
            }

            var tick = new Tick(time, symbol, last, (decimal)e.Bid, (decimal)e.Ask)
            {
                AskSize  = e.AskSize,
                BidSize  = e.BidSize,
                Quantity = e.IncrementalVolume,
                TickType = tradeType,
                DataType = MarketDataType.Tick
            };

            Emit(tick);
            _prices[e.Symbol] = e.Last;

            if (symbol.ID.SecurityType == SecurityType.Option || symbol.ID.SecurityType == SecurityType.Future)
            {
                if (!_openInterests.ContainsKey(e.Symbol) || _openInterests[e.Symbol] != e.OpenInterest)
                {
                    var oi = new OpenInterest(time, symbol, e.OpenInterest);
                    Emit(oi);

                    _openInterests[e.Symbol] = e.OpenInterest;
                }
            }
        }
Ejemplo n.º 15
0
        public override int GetHashCode()
        {
            var hashCode = -1519320215;

            hashCode = hashCode * -1521134295 + IsStarted.GetHashCode();
            hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(TickerID);

            hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Ticker);

            hashCode = hashCode * -1521134295 + Type.GetHashCode();
            hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(FullName);

            hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Prefix);

            hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Currency);

            hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(ISIN);

            hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Name);

            hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(ShortName);

            hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(ChartName);

            hashCode = hashCode * -1521134295 + Decimals.GetHashCode();
            hashCode = hashCode * -1521134295 + ForgDecimals.GetHashCode();
            hashCode = hashCode * -1521134295 + Open.GetHashCode();
            hashCode = hashCode * -1521134295 + Close.GetHashCode();
            hashCode = hashCode * -1521134295 + Last.GetHashCode();
            hashCode = hashCode * -1521134295 + LastHTML.GetHashCode();
            hashCode = hashCode * -1521134295 + LastSize.GetHashCode();
            hashCode = hashCode * -1521134295 + LastTime.GetHashCode();
            hashCode = hashCode * -1521134295 + LastHtmlTime.GetHashCode();
            hashCode = hashCode * -1521134295 + Change.GetHashCode();
            hashCode = hashCode * -1521134295 + ChangePercentage.GetHashCode();
            hashCode = hashCode * -1521134295 + Min.GetHashCode();
            hashCode = hashCode * -1521134295 + Max.GetHashCode();
            hashCode = hashCode * -1521134295 + DealsCount.GetHashCode();
            hashCode = hashCode * -1521134295 + EqualityComparer <List <StockDeal> > .Default.GetHashCode(Deals);

            hashCode = hashCode * -1521134295 + Traffic.GetHashCode();
            hashCode = hashCode * -1521134295 + TrafficCount.GetHashCode();
            hashCode = hashCode * -1521134295 + OpenInterest.GetHashCode();
            hashCode = hashCode * -1521134295 + Status.GetHashCode();
            hashCode = hashCode * -1521134295 + PanelJS.GetHashCode();
            hashCode = hashCode * -1521134295 + ID.GetHashCode();
            hashCode = hashCode * -1521134295 + RealTime.GetHashCode();
            hashCode = hashCode * -1521134295 + Pe2000.GetHashCode();
            hashCode = hashCode * -1521134295 + Pe2001.GetHashCode();
            hashCode = hashCode * -1521134295 + CloseOneMonth.GetHashCode();
            hashCode = hashCode * -1521134295 + EqualityComparer <TimeSpan> .Default.GetHashCode(CloseOneMonthInterval);

            hashCode = hashCode * -1521134295 + CloseThreeMonth.GetHashCode();
            hashCode = hashCode * -1521134295 + EqualityComparer <TimeSpan> .Default.GetHashCode(CloseThreeMonthInterval);

            hashCode = hashCode * -1521134295 + CloseOneYear.GetHashCode();
            hashCode = hashCode * -1521134295 + EqualityComparer <TimeSpan> .Default.GetHashCode(CloseOneYearInterval);

            hashCode = hashCode * -1521134295 + OneMonthVolatility.GetHashCode();
            hashCode = hashCode * -1521134295 + ThreeMonthVolatility.GetHashCode();
            hashCode = hashCode * -1521134295 + OneYearVolatility.GetHashCode();
            hashCode = hashCode * -1521134295 + Eps2000.GetHashCode();
            hashCode = hashCode * -1521134295 + Eps2001.GetHashCode();
            hashCode = hashCode * -1521134295 + MinOneYear.GetHashCode();
            hashCode = hashCode * -1521134295 + MinOneYearAt.GetHashCode();
            hashCode = hashCode * -1521134295 + MaxOneYear.GetHashCode();
            hashCode = hashCode * -1521134295 + MaxOneYearAt.GetHashCode();
            hashCode = hashCode * -1521134295 + MinOfAllTime.GetHashCode();
            hashCode = hashCode * -1521134295 + MinOfAllTimeAt.GetHashCode();
            hashCode = hashCode * -1521134295 + MaxOfAllTime.GetHashCode();
            hashCode = hashCode * -1521134295 + MaxOfAllTimeAt.GetHashCode();
            hashCode = hashCode * -1521134295 + CloseMinOneYear.GetHashCode();
            hashCode = hashCode * -1521134295 + CloseMinOneYearAt.GetHashCode();
            hashCode = hashCode * -1521134295 + CloseMaxOneYear.GetHashCode();
            hashCode = hashCode * -1521134295 + CloseMaxOneYearAt.GetHashCode();
            hashCode = hashCode * -1521134295 + CloseMinAllTime.GetHashCode();
            hashCode = hashCode * -1521134295 + CloseMinAllTimeAt.GetHashCode();
            hashCode = hashCode * -1521134295 + CloseMaxOfAllTime.GetHashCode();
            hashCode = hashCode * -1521134295 + CloseMaxAllTimeAt.GetHashCode();
            hashCode = hashCode * -1521134295 + TrafficAvgInSixMonth.GetHashCode();
            hashCode = hashCode * -1521134295 + TrafficAvgInOneYear.GetHashCode();
            hashCode = hashCode * -1521134295 + StartCount.GetHashCode();
            hashCode = hashCode * -1521134295 + Kapit.GetHashCode();
            hashCode = hashCode * -1521134295 + BuxKapit.GetHashCode();
            hashCode = hashCode * -1521134295 + ChangeInOneMonth.GetHashCode();
            hashCode = hashCode * -1521134295 + ChangeInThreeMonth.GetHashCode();
            hashCode = hashCode * -1521134295 + ChangeInOneYear.GetHashCode();
            hashCode = hashCode * -1521134295 + StartPrice.GetHashCode();
            hashCode = hashCode * -1521134295 + MinInOneYear.GetHashCode();
            hashCode = hashCode * -1521134295 + MaxInOneYear.GetHashCode();
            hashCode = hashCode * -1521134295 + EqualityComparer <ChartData> .Default.GetHashCode(ImageData);

            return(hashCode);
        }
		protected override void Create() {
#if __BACKTEST
			__cCloses = new List<double[]>(1024);
			__cCloses.Add(new double[] {0, 0, 0, 0});
#endif
			__cTWIBars = BarsOfData(3) as Instrument;
			__cSymbolIds = new Dictionary<string, int>(32);

			//讀取未平倉量
			__cOpenInterest = new OpenInterest(this, 2);
			__cOpenInterest.Initialize();

			//讀取三大法人多空與未平倉量
			__cForeignInvestment = new ForeignInvestment(this, 2);
			__cForeignInvestment.Initialize();

			//建立歷史波動率指標
			__cHistoryV = new HistoryVolatility(this, 2);

			//設定計時器(定期抓未平倉量)
			__cTimer = new Timer(1000);
			__cTimer.AutoReset = false;
			__cTimer.Elapsed += Timer_onElapsed;
			__cTimer.Start();
		}
Ejemplo n.º 17
0
        /// <summary>
        /// Returns true if BookSummary instances are equal
        /// </summary>
        /// <param name="other">Instance of BookSummary to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(BookSummary other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     UnderlyingIndex == other.UnderlyingIndex ||
                     UnderlyingIndex != null &&
                     UnderlyingIndex.Equals(other.UnderlyingIndex)
                     ) &&
                 (
                     Volume == other.Volume ||
                     Volume != null &&
                     Volume.Equals(other.Volume)
                 ) &&
                 (
                     VolumeUsd == other.VolumeUsd ||
                     VolumeUsd != null &&
                     VolumeUsd.Equals(other.VolumeUsd)
                 ) &&
                 (
                     UnderlyingPrice == other.UnderlyingPrice ||
                     UnderlyingPrice != null &&
                     UnderlyingPrice.Equals(other.UnderlyingPrice)
                 ) &&
                 (
                     BidPrice == other.BidPrice ||
                     BidPrice != null &&
                     BidPrice.Equals(other.BidPrice)
                 ) &&
                 (
                     OpenInterest == other.OpenInterest ||
                     OpenInterest != null &&
                     OpenInterest.Equals(other.OpenInterest)
                 ) &&
                 (
                     QuoteCurrency == other.QuoteCurrency ||
                     QuoteCurrency != null &&
                     QuoteCurrency.Equals(other.QuoteCurrency)
                 ) &&
                 (
                     High == other.High ||
                     High != null &&
                     High.Equals(other.High)
                 ) &&
                 (
                     EstimatedDeliveryPrice == other.EstimatedDeliveryPrice ||
                     EstimatedDeliveryPrice != null &&
                     EstimatedDeliveryPrice.Equals(other.EstimatedDeliveryPrice)
                 ) &&
                 (
                     Last == other.Last ||
                     Last != null &&
                     Last.Equals(other.Last)
                 ) &&
                 (
                     MidPrice == other.MidPrice ||
                     MidPrice != null &&
                     MidPrice.Equals(other.MidPrice)
                 ) &&
                 (
                     InterestRate == other.InterestRate ||
                     InterestRate != null &&
                     InterestRate.Equals(other.InterestRate)
                 ) &&
                 (
                     Funding8h == other.Funding8h ||
                     Funding8h != null &&
                     Funding8h.Equals(other.Funding8h)
                 ) &&
                 (
                     MarkPrice == other.MarkPrice ||
                     MarkPrice != null &&
                     MarkPrice.Equals(other.MarkPrice)
                 ) &&
                 (
                     AskPrice == other.AskPrice ||
                     AskPrice != null &&
                     AskPrice.Equals(other.AskPrice)
                 ) &&
                 (
                     InstrumentName == other.InstrumentName ||
                     InstrumentName != null &&
                     InstrumentName.Equals(other.InstrumentName)
                 ) &&
                 (
                     Low == other.Low ||
                     Low != null &&
                     Low.Equals(other.Low)
                 ) &&
                 (
                     BaseCurrency == other.BaseCurrency ||
                     BaseCurrency != null &&
                     BaseCurrency.Equals(other.BaseCurrency)
                 ) &&
                 (
                     CreationTimestamp == other.CreationTimestamp ||
                     CreationTimestamp != null &&
                     CreationTimestamp.Equals(other.CreationTimestamp)
                 ) &&
                 (
                     CurrentFunding == other.CurrentFunding ||
                     CurrentFunding != null &&
                     CurrentFunding.Equals(other.CurrentFunding)
                 ));
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (UnderlyingIndex != null)
         {
             hashCode = hashCode * 59 + UnderlyingIndex.GetHashCode();
         }
         if (Volume != null)
         {
             hashCode = hashCode * 59 + Volume.GetHashCode();
         }
         if (VolumeUsd != null)
         {
             hashCode = hashCode * 59 + VolumeUsd.GetHashCode();
         }
         if (UnderlyingPrice != null)
         {
             hashCode = hashCode * 59 + UnderlyingPrice.GetHashCode();
         }
         if (BidPrice != null)
         {
             hashCode = hashCode * 59 + BidPrice.GetHashCode();
         }
         if (OpenInterest != null)
         {
             hashCode = hashCode * 59 + OpenInterest.GetHashCode();
         }
         if (QuoteCurrency != null)
         {
             hashCode = hashCode * 59 + QuoteCurrency.GetHashCode();
         }
         if (High != null)
         {
             hashCode = hashCode * 59 + High.GetHashCode();
         }
         if (EstimatedDeliveryPrice != null)
         {
             hashCode = hashCode * 59 + EstimatedDeliveryPrice.GetHashCode();
         }
         if (Last != null)
         {
             hashCode = hashCode * 59 + Last.GetHashCode();
         }
         if (MidPrice != null)
         {
             hashCode = hashCode * 59 + MidPrice.GetHashCode();
         }
         if (InterestRate != null)
         {
             hashCode = hashCode * 59 + InterestRate.GetHashCode();
         }
         if (Funding8h != null)
         {
             hashCode = hashCode * 59 + Funding8h.GetHashCode();
         }
         if (MarkPrice != null)
         {
             hashCode = hashCode * 59 + MarkPrice.GetHashCode();
         }
         if (AskPrice != null)
         {
             hashCode = hashCode * 59 + AskPrice.GetHashCode();
         }
         if (InstrumentName != null)
         {
             hashCode = hashCode * 59 + InstrumentName.GetHashCode();
         }
         if (Low != null)
         {
             hashCode = hashCode * 59 + Low.GetHashCode();
         }
         if (BaseCurrency != null)
         {
             hashCode = hashCode * 59 + BaseCurrency.GetHashCode();
         }
         if (CreationTimestamp != null)
         {
             hashCode = hashCode * 59 + CreationTimestamp.GetHashCode();
         }
         if (CurrentFunding != null)
         {
             hashCode = hashCode * 59 + CurrentFunding.GetHashCode();
         }
         return(hashCode);
     }
 }
Ejemplo n.º 19
0
        protected override void OnBarUpdate()
        {
            DateTime dtBegin = DateTime.MaxValue;

            switch (IntervalType)
            {
            case EnumIntervalType.Sec:
                dtBegin = MinBar.D.Date.AddHours(MinBar.D.Hour).AddMinutes(MinBar.D.Minute).AddSeconds(MinBar.D.Second / Interval * Interval);
                break;

            case EnumIntervalType.Min:
                dtBegin = MinBar.D.Date.AddHours(MinBar.D.Hour).AddMinutes(MinBar.D.Minute / Interval * Interval);
                break;

            case EnumIntervalType.Hour:
                dtBegin = MinBar.D.Date.AddHours(MinBar.D.Hour / Interval * Interval);
                break;

            case EnumIntervalType.Day:
                dtBegin = DateTime.ParseExact(MinBar.TradingDay.ToString(), "yyyyMMdd", null);
                break;

            case EnumIntervalType.Week:
                dtBegin = DateTime.ParseExact(MinBar.TradingDay.ToString(), "yyyyMMdd", null);
                dtBegin = dtBegin.Date.AddDays(1 - (byte)dtBegin.DayOfWeek);
                break;

            case EnumIntervalType.Month:
                dtBegin = DateTime.ParseExact(MinBar.TradingDay.ToString(), "yyyyMMdd", null);
                dtBegin = new DateTime(dtBegin.Year, dtBegin.Month, 1);
                break;

            case EnumIntervalType.Year:
                dtBegin = DateTime.ParseExact(MinBar.TradingDay.ToString(), "yyyyMMdd", null);
                dtBegin = new DateTime(dtBegin.Year, 1, 1);
                break;

            default:
                throw new Exception("参数错误");
            }
            if (bar == null)             //首次调用
            {
                bar = new Bar
                {
                    D = dtBegin,
                    I = MinBar.I,
                    V = MinBar.V,                     // kOld.preVol == 0 ? 0 : _tick.Volume - kOld.preVol;
                };
                bar.H  = MinBar.H;
                bar.L  = MinBar.L;
                bar.O  = MinBar.O;
                bar.C  = MinBar.C;
                newbar = true;
            }
            else
            {
                if (bar.D == dtBegin)                 //在当前K线范围内
                {
                    newbar = false;
                    bar.H  = Math.Max(bar.H, MinBar.H);
                    bar.L  = Math.Min(bar.L, MinBar.L);
                    bar.C  = MinBar.C;
                    bar.V  = bar.V + MinBar.V;
                    bar.I  = MinBar.I;
                }
                else if (dtBegin > bar.D)
                {
                    newbar = true;
                    bar.D  = dtBegin;
                    bar.V  = MinBar.V;
                    bar.I  = MinBar.I;
                    bar.O  = MinBar.O;
                    bar.H  = MinBar.H;
                    bar.L  = MinBar.L;
                    bar.C  = MinBar.C;
                }
            }

            if (newbar)
            {
                Date.Add(double.Parse(bar.D.ToString("yyyyMMdd")));
                Time.Add(double.Parse(bar.D.ToString("0.HHmmss")));
                Open.Add(bar.O);
                High.Add(bar.H);
                Low.Add(bar.L);
                Close.Add(bar.C);
                Volume.Add(bar.V);
                OpenInterest.Add(bar.I);
            }
            else
            {
                High[0]         = bar.H;
                Low[0]          = bar.L;
                Close[0]        = bar.C;
                Volume[0]       = bar.V;
                OpenInterest[0] = bar.I;
            }
        }
		protected override void Create() {
			__cOpenInterest = new OpenInterest(this);
			__cOpenInterest.Initialize();
		}
Ejemplo n.º 21
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (TradingDay.Length != 0)
            {
                hash ^= TradingDay.GetHashCode();
            }
            if (InstrumentId.Length != 0)
            {
                hash ^= InstrumentId.GetHashCode();
            }
            if (ExchangeId.Length != 0)
            {
                hash ^= ExchangeId.GetHashCode();
            }
            if (LastPrice != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(LastPrice);
            }
            if (PreSettlementPrice != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(PreSettlementPrice);
            }
            if (PreClosePrice != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(PreClosePrice);
            }
            if (PreOpenInterest != 0)
            {
                hash ^= PreOpenInterest.GetHashCode();
            }
            if (OpenPrice != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(OpenPrice);
            }
            if (HighestPrice != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(HighestPrice);
            }
            if (LowestPrice != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(LowestPrice);
            }
            if (Volume != 0)
            {
                hash ^= Volume.GetHashCode();
            }
            if (TurnOver != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(TurnOver);
            }
            if (OpenInterest != 0)
            {
                hash ^= OpenInterest.GetHashCode();
            }
            if (ClosePrice != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(ClosePrice);
            }
            if (SettlementPrice != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(SettlementPrice);
            }
            if (UpperLimitPrice != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(UpperLimitPrice);
            }
            if (LowerLimitPrice != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(LowerLimitPrice);
            }
            if (UpdateTime.Length != 0)
            {
                hash ^= UpdateTime.GetHashCode();
            }
            if (UpdateMillisec != 0)
            {
                hash ^= UpdateMillisec.GetHashCode();
            }
            if (AveragePrice != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(AveragePrice);
            }
            if (ActionDay.Length != 0)
            {
                hash ^= ActionDay.GetHashCode();
            }
            if (BidPrice != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(BidPrice);
            }
            if (BidVolume != 0)
            {
                hash ^= BidVolume.GetHashCode();
            }
            if (AskPrice != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(AskPrice);
            }
            if (AskVolume != 0)
            {
                hash ^= AskVolume.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }