Ejemplo n.º 1
0
        public static void FullSp500Test()
        {
            Console.WriteLine("Getting sp500...");
            string[] sp500 = InvestingToolkit.GetEquityGroupAsync(EquityGroup.SP500).Result;

            HttpClient hc = new HttpClient();

            List <string> Failures = new List <string>();
            int           t        = 1;

            foreach (string s in sp500)
            {
                Console.Write("Tring " + s + " (" + t.ToString() + "/" + sp500.Length.ToString() + ")... ");
                try
                {
                    EdgarSearch es = EdgarSearch.CreateAsync(s, "4", null, EdgarSearchOwnershipFilter.only).Result;
                    foreach (EdgarSearchResult esr in es.Results)
                    {
                        if (esr.Filing == "4")
                        {
                            FilingDocument[] docs = esr.GetDocumentFormatFilesAsync().Result;
                            foreach (FilingDocument fd in docs)
                            {
                                if (fd.DocumentName.ToLower().Contains(".xml"))
                                {
                                    //Console.WriteLine("Tryng to get " + fd.Url + " ...");
                                    HttpResponseMessage hrm = hc.GetAsync(fd.Url).Result;
                                    string content          = hrm.Content.ReadAsStringAsync().Result;
                                    StatementOfBeneficialOwnership form4 = StatementOfBeneficialOwnership.ParseXml(content);
                                }
                            }
                        }
                    }
                    Console.WriteLine("Success");
                }
                catch
                {
                    Failures.Add(s);
                    Console.WriteLine("FAILURE!");
                }
                t = t + 1;
            }

            Console.WriteLine("DONE!");
            Console.WriteLine("Failures:");
            foreach (string s in Failures)
            {
                Console.WriteLine(s);
            }
        }
        public async Task <string> PrepareNewForm4TweetAsync(StatementOfBeneficialOwnership form4)
        {
            string ToReturn = null;

            foreach (NonDerivativeTransaction ndt in form4.NonDerivativeTransactions)
            {
                if (ndt.AcquiredOrDisposed == AcquiredDisposed.Acquired)                        //They acquired
                {
                    if (ndt.TransactionCode != null)                                            //It is indeed a transaction, not just a holding report
                    {
                        if (ndt.TransactionCode == TransactionType.OpenMarketOrPrivatePurchase) //Open market purchase
                        {
                            //Get the equity cost
                            Equity e = Equity.Create(form4.IssuerTradingSymbol);
                            await e.DownloadSummaryAsync();

                            //Get the name to use
                            string TraderNameToUse = form4.OwnerName;
                            try
                            {
                                TraderNameToUse = Aletheia.AletheiaToolkit.NormalizeAndRearrangeForm4Name(form4.OwnerName);
                            }
                            catch
                            {
                            }

                            //Start
                            ToReturn = "*INSIDER BUY ALERT*" + Environment.NewLine;
                            ToReturn = ToReturn + form4.OwnerName;

                            //Is there an officer title? If so, loop it in
                            if (form4.OwnerOfficerTitle != null && form4.OwnerOfficerTitle != "")
                            {
                                ToReturn = ToReturn + ", " + form4.OwnerOfficerTitle + ", ";
                            }
                            else
                            {
                                ToReturn = ToReturn + " ";
                            }

                            //Continue
                            ToReturn = ToReturn + "purchased " + ndt.TransactionQuantity.Value.ToString("#,##0") + " shares of $" + form4.IssuerTradingSymbol.Trim().ToUpper();

                            //Was a transaction price supplied?
                            if (ndt.TransactionPricePerSecurity.HasValue)
                            {
                                ToReturn = ToReturn + " at $" + ndt.TransactionPricePerSecurity.Value.ToString("#,##0.00");
                            }

                            //Add a period
                            ToReturn = ToReturn + "." + Environment.NewLine;

                            //How much they own following transaction
                            float worth = e.Summary.Price * ndt.SecuritiesOwnedFollowingTransaction;
                            ToReturn = ToReturn + form4.OwnerName + " now owns " + ndt.SecuritiesOwnedFollowingTransaction.ToString("#,##0") + " shares worth $" + worth.ToString("#,##0") + " of " + form4.IssuerName + " stock.";
                        }
                    }
                }
            }

            //Throw an error if ToReturn is still null (the above process did not satisfy anything)
            if (ToReturn == null)
            {
                throw new Exception("The Form 4 type is not supported for tweeting.");
            }

            return(ToReturn);
        }
        /// <summary>
        /// This will scan the newly filed Form 4's and return the ones that are new (have not been seen yet). Thus, this will mark the new ones as observed.
        /// </summary>
        public async Task <StatementOfBeneficialOwnership[]> ObserveNewForm4sAsync()
        {
            //Get the last observed filing URL
            string LastObservedFilingUrl = await DownloadLatestObservedForm4FilingUrlAsync();

            //Search!
            EdgarLatestFilingsSearch elfs = await EdgarLatestFilingsSearch.SearchAsync("4", EdgarSearchOwnershipFilter.only, EdgarSearchResultsPerPage.Entries40);

            //Get a list of new filings
            List <EdgarLatestFilingResult> NewlyObservedFilings = new List <EdgarLatestFilingResult>();

            if (LastObservedFilingUrl != null)
            {
                foreach (EdgarLatestFilingResult esr in elfs.Results)
                {
                    if (LastObservedFilingUrl == esr.DocumentsUrl)
                    {
                        break;
                    }
                    else
                    {
                        NewlyObservedFilings.Add(esr);
                    }
                }
            }
            else //If there isn't a latest received filings url in azure, just add all of them
            {
                foreach (EdgarLatestFilingResult esr in elfs.Results)
                {
                    NewlyObservedFilings.Add(esr);
                }
            }

            //Get a list of statmenet of changes in beneficial ownership for each of them
            List <StatementOfBeneficialOwnership> ToReturn = new List <StatementOfBeneficialOwnership>();

            foreach (EdgarLatestFilingResult esr in NewlyObservedFilings)
            {
                EdgarSearchResult esrt = new EdgarSearchResult();
                esrt.DocumentsUrl = esr.DocumentsUrl; //Have to plug it into here because this is the only class has has the GetDocumentFormatFilesAsync method
                FilingDocument[] docs = await esrt.GetDocumentFormatFilesAsync();

                foreach (FilingDocument fd in docs)
                {
                    if (fd.DocumentName.ToLower().Contains(".xml") && fd.DocumentType == "4")
                    {
                        try
                        {
                            StatementOfBeneficialOwnership form4 = await StatementOfBeneficialOwnership.ParseXmlFromWebUrlAsync(fd.Url);

                            ToReturn.Add(form4);
                        }
                        catch
                        {
                        }
                    }
                }
            }

            //Log the most recent seen form 4 (it would just be the first one in the list of results)
            await UploadLatestObservedForm4FilingUrlAsync(elfs.Results[0].DocumentsUrl);

            //Return
            return(ToReturn.ToArray());
        }
Ejemplo n.º 4
0
        public static void IndividualTest(string[] args)
        {
            StatementOfBeneficialOwnership form4 = StatementOfBeneficialOwnership.ParseXmlFromWebUrlAsync(args[0]).Result;

            Console.WriteLine(JsonConvert.SerializeObject(form4));
        }