예제 #1
0
        public IObservable <StreamInputEvent <TPayload> > CreateObservableSource <TPayload>(object config, EventShape eventShape)
        {
            //Check the payload type.
            CheckPayloadType <TPayload>();
            //Check config class for the proper type.
            YahooDataInputConfig typedConfig = config as YahooDataInputConfig;

            if (typedConfig == null)
            {
                //Invalid cast
                throw new ArgumentException("Configuration class must be of type YahooDataInputConfig");
            }
            return((IObservable <StreamInputEvent <TPayload> >)CreateProducer(typedConfig, eventShape));
        }
예제 #2
0
        private YahooDataProducer CreateProducer(YahooDataInputConfig config, EventShape eventShape)
        {
            switch (eventShape)
            {
            case EventShape.Point:
                //Create the publisher.
                return(new YahooDataProducer(config));

            default:
                throw new ArgumentException(string.Format(
                                                System.Globalization.CultureInfo.InvariantCulture,
                                                "YahooDataInputFactory cannot instantiate adapter with event shape {0}",
                                                eventShape.ToString()));
            }
        }
예제 #3
0
        public static List <YahooDataEvent> CreateNext(YahooDataInputConfig config, int runNumber)
        {
            List <YahooDataEvent> newReferenceData = new List <YahooDataEvent>();

            string[] Symbols = config.Symbols;

            //TODO: Add Requestor to get data from YahooFinance
            string symbolList = "";

            if (Symbols.Count() > 1)
            {
                symbolList = String.Join("%2C", Symbols.Select(w => "%22" + w + "%22").ToArray());
            }
            else if (Symbols.Count() == 1)
            {
                symbolList = String.Join("%2C", "%22" + Symbols.First() + "%22");
            }
            else
            {
                //throw exception.
                //need symbols
                throw new ArgumentException("No symbols requested.  Need to request at least 1 symbol.");
            }

            string url = string.Format(BASE_URL, symbolList);

            try {
                XDocument doc = XDocument.Load(url);
                while (doc.Root.Element("results").IsEmpty)
                {
                    doc = XDocument.Load(url);
                }
                XElement results = doc.Root.Element("results");
                foreach (string symbol in Symbols)
                {
                    newReferenceData.Add(ParseXmlRequest(symbol, results));
                }
            } catch (Exception ex) {
                Console.WriteLine("RequestDataException: {0}", ex.Message);
            }

            return(newReferenceData);
        }
예제 #4
0
        public static List<YahooDataEvent> CreateNext(YahooDataInputConfig config, int runNumber)
        {
            List<YahooDataEvent> newReferenceData = new List<YahooDataEvent>();
            string[] Symbols = config.Symbols;

            //TODO: Add Requestor to get data from YahooFinance
            string symbolList = "";
            if (Symbols.Count() > 1) {
                symbolList = String.Join("%2C", Symbols.Select(w => "%22" + w + "%22").ToArray());
            } else if (Symbols.Count() == 1) {
                symbolList = String.Join("%2C", "%22" + Symbols.First() + "%22");
            } else {
                //throw exception.
                //need symbols
                throw new ArgumentException("No symbols requested.  Need to request at least 1 symbol.");
            }

            string url = string.Format(BASE_URL, symbolList);
            try {
                XDocument doc = XDocument.Load(url);
                while (doc.Root.Element("results").IsEmpty) {
                    doc = XDocument.Load(url);
                }
                XElement results = doc.Root.Element("results");
                foreach (string symbol in Symbols) {
                    newReferenceData.Add(ParseXmlRequest(symbol, results));
                }
            } catch (Exception ex) {
                Console.WriteLine("RequestDataException: {0}", ex.Message);
            }

            return newReferenceData;
        }
예제 #5
0
        //Process for Yahoo Data
        private static void RunYahooDataProcess(Application cepApplication)
        {
            var config = new YahooDataInputConfig() {
                Symbols = new string[] { "AAPL", "DELL", "MSFT", "GOOG", "GE" },
                RefreshInterval = TimeSpan.FromSeconds(5),
                TimestampIncrement = TimeSpan.FromSeconds(5),
                AlwaysUseNow = true,
                EnqueueCtis = false
            };

            AdvanceTimeSettings ats = new AdvanceTimeSettings(new AdvanceTimeGenerationSettings(
                                                                    TimeSpan.FromMilliseconds(750),
                                                                    TimeSpan.FromMilliseconds(200)),
                null, AdvanceTimePolicy.Drop);

            var data = RxStream<YahooDataEvent>.Create(cepApplication, typeof(YahooDataInputFactory), config,
                EventShape.Point, ats);

            var sinkConfig = new ConsoleOutputConfig() {
                ShowCti = true,
                ShowPayloadToString = false,
                CtiEventColor = ConsoleColor.Blue,
                InsertEventColor = ConsoleColor.Green
            };

            var myQuery = from x in data.ToPointEventStream()
                          select new {
                              x.Symbol,
                              x.LastTradePrice,
                              x.LastUpdateTime
                          };

            var binding = myQuery.ToBinding(cepApplication, typeof(ConsoleOutputFactory), sinkConfig, EventShape.Point);

            binding.Run("Hello");
        }
예제 #6
0
        private static void RunQuery(Application cepApplication)
        {
            var config = new YahooDataInputConfig() {
                Symbols = new string[] { "AAPL", "DELL", "MSFT", "GOOG", "GE" },
                RefreshInterval = TimeSpan.FromSeconds(0.5),
                TimestampIncrement = TimeSpan.FromSeconds(0.5),
                AlwaysUseNow = true,
                EnqueueCtis = false
            };

            AdvanceTimeSettings ats = new AdvanceTimeSettings(new AdvanceTimeGenerationSettings(
                                                                                TimeSpan.FromMilliseconds(1000),
                                                                                TimeSpan.FromMilliseconds(200)),
                                                null, AdvanceTimePolicy.Drop);

            var data = CepStream<YahooDataEvent>.Create(cepApplication, "TestData", typeof(YahooDataInputFactory), config,
                EventShape.Point, ats);

            var query = data.ToQuery(cepApplication, "Test", "Test", typeof(ConsoleOutputFactory),
                new ConsoleOutputConfig() {
                    ShowCti = true,
                    CtiEventColor = ConsoleColor.Yellow,
                    InsertEventColor = ConsoleColor.Magenta
                },
                EventShape.Point, StreamEventOrder.FullyOrdered);

            query.Start();
        }
예제 #7
0
 public InputAdapterBase Create <TPayload>(YahooDataInputConfig configInfo, EventShape eventShape)
 {
     CheckPayloadType <TPayload>();
     return(new ObservableTypedPointInputAdapter <YahooDataEvent, YahooDataInputConfig>(
                CreateProducer(configInfo, eventShape)));
 }