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);
 }
예제 #2
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();
        }