public void SellAlert(string symbolName, double price) { IPortfolioManager pm = new PortfolioManager(); PositionMessage pos = pm.GetPosition(symbolName); UserAgent ua = new UserAgent(); ua.generateAlert(symbolName, tradeTypes.Sell, pos.Quantity, price); }
public void LoadSettingsFromDb() { PortfolioManager pm = new PortfolioManager(); pm.LoadSettings(); PortfolioRule r = pm.Rules.FirstOrDefault<PortfolioRule>(x => typeof(AllocationRule).IsInstanceOfType(x)); Assert.IsNotNull(r); AllocationRule a = (AllocationRule)r; Assert.AreEqual(0.9, a.MaxAllocation); }
public void CreateWithSettings() { Dictionary<string, string> settings = new Dictionary<string, string>(); settings.Add("MAX_POSITION_RATIO", "0.9"); PortfolioManager pm = new PortfolioManager(settings); PortfolioRule r = pm.Rules.FirstOrDefault<PortfolioRule>(x => typeof(AllocationRule).IsInstanceOfType(x)); Assert.IsNotNull(r); AllocationRule a = (AllocationRule)r; Assert.AreEqual(0.9, a.MaxAllocation); }
public void OnTick(object source, ElapsedEventArgs e) { PortfolioManager pm = new PortfolioManager(); List<PositionMessage> pos = pm.GetOpenPositions(); List<string> owned = pos.Select(x => x.SymbolName).ToList<string>(); _owner.WatchForSell = owned; SortedSet<string> watched = new SortedSet<string>(); IWatchListManager wlm = new WatchListManager(); List<WatchList> lists = wlm.GetAllWatchLists(); foreach (WatchList wl in lists) { foreach (WatchListItem i in wl.Items) { watched.Add(i.SymbolName); } } _owner.WatchForBuy = watched.ToList<string>(); }
public void PlaceABuyTrade() { Portfolio port = new Portfolio(); port.Cash = 1000; Position pos = new Position(); pos.PositionId = 3; pos.quantity = 0; pos.price = 0; Trade t = new Trade(); PortfolioManager pm = new PortfolioManager(); // this test might need to initialize the rules pm.ProcessBuyTrade(t, "GOOG", 10, 2.5, pos, port); Assert.AreEqual("GOOG", t.SymbolName); Assert.AreEqual(10, t.quantity); Assert.AreEqual(2.5, t.price); Assert.AreEqual(tradeTypes.Buy, t.type); Assert.AreEqual(3, t.PositionId); Assert.AreEqual(10, pos.quantity); Assert.AreEqual(25, pos.price); Assert.AreEqual(975, port.Cash); }
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(); }
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(); }
public void BuyAlert(string symbolName, int quantity, double price) { PortfolioManager pm = new PortfolioManager(); IUserAgent ua = new UserAgent(); ua.generateAlert(symbolName, tradeTypes.Buy, pm.DefaultBuySize(price), price); }