Example #1
0
        static void Main()
        {
            INewsPublishService publisher = new EuroNewsAgency();
            var subscriber1 = new Cumhuriyet();
            var subscriber2 = new Bloomberg();

            publisher.OnBreakingNews += subscriber1.BreakingNewsSubscription;
            publisher.OnEconomyNews  += subscriber1.EconomyNewsSubscription;
            publisher.OnSportsNews   += subscriber1.SportsNewsSubscription;

            publisher.OnEconomyNews += subscriber2.EconomyNews;

            ((EuroNewsAgency)publisher).BreakingNewsRelease("New laws in EU", "Germany releases new laws for refugees.");
            ((EuroNewsAgency)publisher).EconomyNewsRelease("EUR/TRY currency rate", "Currency rate difference increased to 6,27 TL");
        }
Example #2
0
        /// <summary>
        /// Returns a string that represents the current object.
        /// </summary>
        /// <returns>A string that represents the current object.</returns>
        public override string ToString()
        {
            var str = string.Empty;

            if (!Bloomberg.IsEmpty())
            {
                str += " Bloom {0}".Put(Bloomberg);
            }

            if (!Cusip.IsEmpty())
            {
                str += " CUSIP {0}".Put(Cusip);
            }

            if (!IQFeed.IsEmpty())
            {
                str += " IQFeed {0}".Put(IQFeed);
            }

            if (!Isin.IsEmpty())
            {
                str += " ISIN {0}".Put(Isin);
            }

            if (!Ric.IsEmpty())
            {
                str += " RIC {0}".Put(Ric);
            }

            if (!Sedol.IsEmpty())
            {
                str += " SEDOL {0}".Put(Sedol);
            }

            if (InteractiveBrokers != null)
            {
                str += " InteractiveBrokers {0}".Put(InteractiveBrokers);
            }

            if (!Plaza.IsEmpty())
            {
                str += " Plaza {0}".Put(Plaza);
            }

            return(str);
        }
Example #3
0
        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            Stopwatch stopwatch = new Stopwatch();

            DateTime startDate;
            var      endDate = DateTime.Today.GetBusinessDay(-1);

            var options = new CommandLineOptions();

            if (!Parser.Default.ParseArguments(args, options))
            {
                Environment.Exit(Parser.DefaultExitCodeFail);
            }

            DateTime.TryParse(String.Join(".", options.startDate), out startDate);

            var logging = new Logging(options.LogFile);

            Trace.WriteLine(options.ToString());

            var config = new ConfigBase();

            config.Load(options.Settings);

            if (!options.NoDownload)
            {
                IDataSource dataSource = new Bloomberg();
                dataSource.Connect();

                HashSet <string> shareNames = new HashSet <string>();

                // get specifications
                var sheet = new Sheet();
                sheet.Download(new string[] { config.GetValue("sheetCode"), config.GetValue("shareNames") });
                var shareIDs = sheet.toShares();
                shareNames.UnionWith(
                    dataSource.GetFields(shareIDs.ToList(), "ID_BB_GLOBAL")
                    );

                sheet.Download(new string[] { config.GetValue("sheetCode"), config.GetValue("indices") });
                var indexNames = sheet.toShares();

                sheet.Download(new string[] { config.GetValue("sheetCode"), config.GetValue("fields") });
                var fields = new List <Field>();
                sheet.toFields <Field>(fields);

                //download index compositions
                if (indexNames != null && indexNames.Count() > 0)
                {
                    //obtain components of indices
                    var names = dataSource.DownloadMultipleComponents(indexNames.ToList(), "INDX_MEMBERS");

                    //convert tickers -> BB IDs
                    shareNames.UnionWith(dataSource.GetFields(names, "ID_BB_GLOBAL"));
                }

                LocalDisk disk = new LocalDisk();
                disk.SetPath(options.Dir);

                //delete data for shares-reload and shares-delete
                {
                    sheet.Download(new string[] { config.GetValue("sheetCode"), config.GetValue("shares-reload") });
                    var sharesReload = dataSource.GetFields(sheet.toShares().ToList(), "ID_BB_GLOBAL");

                    sheet.Download(new string[] { config.GetValue("sheetCode"), config.GetValue("shares-delete") });
                    var sharesDelete = dataSource.GetFields(sheet.toShares().ToList(), "ID_BB_GLOBAL");

                    foreach (var item in sharesDelete.Concat(sharesReload))
                    {
                        disk.DeleteDirectory(item.StripOfIllegalCharacters());
                    }

                    //delete shares-delete names from list of downloadable shares
                    foreach (var item in sharesDelete)
                    {
                        if (shareNames.Contains(item))
                        {
                            shareNames.Remove(item);
                        }
                    }
                }

                shareNames = new HashSet <string>(shareNames.Where(item => item.Contains("BBG") & !item.Contains(" ")));

                //roundtrip to tickers and back to bb_ids - as some bb_ids represent the same share
                var ticker      = dataSource.GetFields(shareNames.ToList(), "EQY_FUND_TICKER");
                var asset_class = dataSource.GetFields(shareNames.ToList(), "BPIPE_REFERENCE_SECURITY_CL_RT");
                var tickers     = ticker.Zip(asset_class, (first, last) => first + " " + last);
                HashSet <string> unique_tickers = new HashSet <string>(tickers);
                shareNames = new HashSet <string>(dataSource.GetFields(unique_tickers.ToList(), "ID_BB_GLOBAL").ToList());

                //download and save data
                stopwatch.Start();
                {
                    var shares = new SharesBatch(shareNames.ToList(), fields, dataSource, disk, startDate, endDate);
                    shares.PerformOperations();

                    Trace.Write("Processing Individual: ");
                    foreach (var shareName in shareNames)
                    {
                        Share share = new Share(name: shareName, fields: fields, dataSource: dataSource, fileAccess: disk, startDate: startDate, endDate: endDate);
                        share.DoWork();
                    }
                }
                dataSource.Disconnect();

                //download fieldInfo
                {
                    if (shareNames.Count() > 0)
                    {
                        dataSource.Connect(dataType: "//blp/apiflds");
                        disk.SetPath(options.FieldInfoDir);
                        Share share = new Share(name: shareNames.First(), fields: fields, dataSource: dataSource, fileAccess: disk, startDate: startDate, endDate: endDate);
                        share.DoWorkFieldInfo();
                        dataSource.Disconnect();
                    }
                }
                stopwatch.Stop();
                Trace.WriteLine("Time spent downloading from BB: " + stopwatch.Elapsed.ToString());
            }


            //upload data via SQL connection
            if (!options.NoUpload)
            {
                stopwatch.Restart();
                {
                    LocalDisk disk = new LocalDisk();
                    disk.SetPath(options.Dir);

                    var database = new MySQL(config.GetValue("sqlIP"), config.GetValue("sqlUser"), config.GetValue("sqlPass"), config.GetValue("sqlDB"), disk);
                    database.DoWork();
                }

                {
                    LocalDisk disk = new LocalDisk();
                    disk.SetPath(options.FieldInfoDir);

                    var database = new MySQL(config.GetValue("sqlIP"), config.GetValue("sqlUser"), config.GetValue("sqlPass"), config.GetValue("sqlDB"), disk);
                    database.DoWorkFieldInfo();
                }
                stopwatch.Stop();
                Trace.WriteLine("Time spent uploading: " + stopwatch.Elapsed.ToString());
                logging.Close();
            }
        }