Esempio n. 1
0
        public void Start(ITrader trader)
        {
            Console.WriteLine("Enter a stock symbol (for example aapl):");
            string symbol = Console.ReadLine();

            Console.WriteLine("Enter the maximum price you are willing to pay: ");
            double price;

            while (!double.TryParse(Console.ReadLine(), out price))
            {
                Console.WriteLine("Please enter a number.");
            }
            Console.WriteLine(trader.GetService().GetAPIPath());
            try {
                bool purchased = trader.Buy(symbol, price);
                if (purchased)
                {
                    Logger.Instance.Log("Purchased stock!");
                }
                else
                {
                    Logger.Instance.Log("Couldn't buy the stock at that price.");
                }
            } catch (Exception e) {
                Logger.Instance.Log("There was an error while attempting to buy the stock: " + e.Message);
            }
            Console.ReadLine();
        }
Esempio n. 2
0
        [Test] // everything works
        public void TestGetPriceNormalValues()
        {
            //arrange
            string symbol = "aapl";

            _stockApi.GetPrice(symbol).Returns(23.21);

            //act
            double price = _stockApi.GetPrice(symbol);

            _trader.Buy(symbol, price);

            //assert
            _trader.Received().Buy(Arg.Any <string>(), Arg.Any <double>());
        }
Esempio n. 3
0
        public async void Buy(Candle candle)
        {
            Log($"Placing order.. {_inMemoryBot.Name} for  {candle.ClosePrice}");

            try
            {
                ExchangeOrderResult orderResult = await _trader.Buy(_inMemoryBot, candle.ClosePrice);


                if (orderResult != null)
                {
                    await ProcessOrderResult(orderResult, candle);
                }
            }
            catch (Exception e)
            {
                _logger.Error(e);
            }
        }