コード例 #1
0
ファイル: Store.cs プロジェクト: nirgle/trades-gone-wild
        /// <summary>
        /// Add a new Alert record to the store and sets the AlertID in the passed alert
        /// </summary>
        /// <param name="alert"></param>
        public void AddAlert(Alert alert)
        {
            var store = new StoreAlert
            {
                FKInstrumentID = alert.Instrument.InstrumentID,
                ClosestPrice = alert.ClosestPrice,
                DateOpened = alert.OpeningDate,
                PriceTarget = alert.PriceTarget,
                TargetDirection = alert.TargetDirection
            };

            _context
                .StoreAlerts
                .Add(store);

            _context.SaveChanges();

            alert.AlertID = store.AlertID;
        }
コード例 #2
0
        public TradeConsole()
        {
            InitializeComponent();

            _alertManager = new AlertManager();
            _alertManager.ThrowEvent += (sender, args) => OnAlertEvent(args);

            var repo = new Store();

            AllInstruments.SetInstruments(repo.GetInstruments());

            var alerts = repo.GetOpenAlerts();

            foreach (var alert in alerts)
            {
                var instrument = AllInstruments.GetInstrument(alert.Instrument.Market, alert.Instrument.Symbol);

                if (instrument == null)
                    continue;

                Alert a = new Alert
                {
                    AlertID = alert.AlertID,
                    Instrument = instrument,
                    Finished = alert.DateClosed != null,
                    OpeningDate = alert.DateOpened,
                    PriceTarget = alert.PriceTarget,
                    TargetDirection = alert.TargetDirection
                };

                _alertManager.AddAlert(a);
            }

            EnumeratePlans();

            _tickPunker = new TickPunker();
            _tickPunker.ReceivedTick += new ReceivedTickEventHandler(GotTick);
            _tickPunker.StartWatcher();

            AddTextOutput("Started");
        }
コード例 #3
0
        private void AddToStore(Alert alert)
        {
            var repo = new Store();

            repo.AddAlert(alert);
        }
コード例 #4
0
        private void OnKeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar != (char)Keys.Return)
                return;

            string command = txtCommand.Text.ToLower().Trim();

            Regex regex = new Regex(@"^w\s+([a-z]{6})\s+([0-9\.]+)$");
            Match match = regex.Match(command);

            if (match.Success == true)
            {
                string symbol = match.Groups[1].Value.ToUpper();
                decimal price = Convert.ToDecimal(match.Groups[2].Value);

                Instrument instrument = AllInstruments.GetInstrument("Forex", symbol);

                if (instrument == null)
                {
                    AddTextOutput("Unknown instrument " + instrument);
                }
                else
                {
                    var alert = new Alert
                    {
                        Instrument = instrument,
                        OpeningDate = DateTime.UtcNow,
                        PriceTarget = price
                    };

                    AddToStore(alert);

                    _alertManager.AddAlert(alert);

                    AddTextOutput("");
                    EnumeratePlans();
                }
            }
        }
コード例 #5
0
 public void AddAlert(Alert alert)
 {
     _alerts.Add(alert);
 }
コード例 #6
0
ファイル: Alert.cs プロジェクト: nirgle/trades-gone-wild
 public void AddAlert(Alert alert)
 {
     _alerts.Add(alert);
 }
コード例 #7
0
ファイル: Store.cs プロジェクト: nirgle/trades-gone-wild
        /// <summary>
        /// Update the volatile fields of the passed alert in the store
        /// </summary>
        /// <param name="alert"></param>
        public void UpdateAlert(Alert alert)
        {
            var store = _context
                .StoreAlerts
                .Where(a => a.AlertID == alert.AlertID)
                .FirstOrDefault();

            if (store == null)
                return;

            store.ClosestPrice = alert.ClosestPrice;
            store.TargetDirection = alert.TargetDirection;

            if (alert.Finished == true)
            {
                if (store.DateClosed == null)
                    store.DateClosed = DateTime.UtcNow;
            }
        }