Beispiel #1
0
        public void Trade()
        {
            foreach (var stockSignal in _stockSignals)
            {
                var assessment = stockSignal.Assess();

                if (assessment.Recommendation > 0)
                {
                    const int amount = 1;
                    var       price  = _stockbroker.GetPrice(assessment.Symbol) * amount;
                    if (Balance >= price)
                    {
                        Balance -= _stockbroker.Buy(assessment.Symbol, amount);
                        _portfolio.Add(assessment.Symbol, amount);
                    }
                }
                else if (assessment.Recommendation < 0)
                {
                    const int amount = 1;

                    if (_portfolio.Has(assessment.Symbol, amount))
                    {
                        Balance += _stockbroker.Sell(assessment.Symbol, amount);
                        _portfolio.Remove(assessment.Symbol, amount);
                    }
                }
            }
        }