Beispiel #1
0
        public void processAlertResponse(string alertID, responseCodes alertResponseCode, string alertResponse)
        {
            ILog log = Logger;
            log.DebugFormat("Alert generated: {0} {1}", alertID, alertResponse);
            TraderContext db = DbContext;
            Guid alertGuid = Guid.Parse(alertID);
            Alert alert = db.Alerts.Where(x => x.AlertId == alertGuid).FirstOrDefault();
            if (alert == null)
            {
                log.WarnFormat("Alert not found: {0}", alertID);
                return;
            }
            alert.ResponseCode = alertResponseCode;
            alert.Response = alertResponse;
            db.SaveChanges();

            if (alert.ResponseCode == responseCodes.Accept)
            {
                PortfolioManager pm = new PortfolioManager();
                pm.LoadSettings();
                if (alert.Type == tradeTypes.Buy)
                {
                    pm.buy(alert.Symbol.name, alert.Quantity);
                }
                else
                {
                    pm.sell(alert.Symbol.name, alert.Quantity);
                }
            }
            db.Dispose();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            StreamWriter write = new StreamWriter(ConfigurationManager.AppSettings.Get("ErrorsPath"));

                using (Imap map = new Imap())
                {
                    map.ConnectSSL("imap.gmail.com");
                    map.Login("*****@*****.**", "algSweng500");

                    //select only the inbox to search and only show unread messages
                    map.SelectInbox();
                    List<long> uids = map.Search(Flag.Unseen);

                    foreach (long uid in uids)
                    {
                        try
                        {
                            string eml = map.GetMessageByUID(uid);
                            IMail mail = new MailBuilder().CreateFromEml(eml);

                            string title = mail.Subject;

                            if (!title.Contains("Please purchase"))
                            {

                                string message = mail.Text;

                                //get the stock symbol
                                string[] Symbolsplit = title.Split(new char[0]);
                                string symbol = Symbolsplit[1].ToString();

                                //get the amount to sell or buy
                                string AmountExtract = Regex.Match(title, @"\d+").Value;
                                int quantity = Int32.Parse(AmountExtract);

                                //convert the message and title to lowercase so the if statement will have no errors
                                message = message.ToLower();
                                title = title.ToLower();

                                PortfolioManager Manage = new PortfolioManager();
                                if (message.Contains("yes") && title.Contains("sell"))
                                {
                                    Manage.sell(symbol, quantity);
                                }
                                else if (message.Contains("yes") && title.Contains("buy"))
                                {
                                    Manage.buy(symbol, quantity);
                                }
                                else
                                {
                                    //adding just incase we find a need for it
                                }
                            }
                            else
                            {
                                map.MarkMessageUnseenByUID(uid);
                                write.WriteLine("Mail DLL ERROR");
                            }
                        }
                        catch (Exception ex)
                        {
                            write.WriteLine("Error Occurred Processing Email");
                            write.WriteLine("Email UID: " + uid);
                            write.WriteLine("Exception: " + ex.ToString());
                        }
                    }
                }
                write.Close();
        }