コード例 #1
0
        public void CandlestickBar_Write_Works()
        {
            //Arrange
            var CandlestickBars = new CandlestickBars(1000);

            CandlestickBars.BarUpdated += delegate(ICandlestickBar current) { };
            var priceBar1 = new PriceBar(DateTime.Now.Ticks, 2, 3, 4, 0);
            var priceBar2 = new PriceBar();
            var priceBar3 = new PriceBar(DateTime.Now.Ticks, 1, 2, 3, 4);

            priceBar2.Write(DateTime.Now.Ticks, priceBar3.Open, priceBar3.High, priceBar3.Low, priceBar3.Close);

            //Act
            CandlestickBars.Write(priceBar1);
            CandlestickBars.Write(priceBar3);
            CandlestickBars.Write(priceBar2);
            CandlestickBars.Write(priceBar3.Timestamp, priceBar3.Open, priceBar3.High, priceBar3.Low, priceBar3.Close);

            //Assert
            Assert.AreEqual(4, CandlestickBars.Length);
            Assert.AreEqual(CandlestickBars.Current.Timestamp, priceBar3.Timestamp);
            Assert.AreEqual(CandlestickBars.Previous.Timestamp, priceBar2.Timestamp);
        }
コード例 #2
0
        public void CandlestickBar_Persistence_Works()
        {
            var destinationFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            var filePersistence = new FilePersistenceService();

            var fileWriter = filePersistence.CreateFileWriter(destinationFile);

            //Arrange
            var candlesticks = new CandlestickBars(100, fileWriter);

            //Action
            candlesticks.Write(DateTime.Now.Ticks, 1, 2, 3, 4);

            fileWriter.Close();

            //Assert
            Assert.IsTrue(File.Exists(destinationFile));
            Assert.IsTrue(new FileInfo(destinationFile).Length > 0);
        }