示例#1
0
        public void OHLCBar_Write_Works()
        {
            //Arrange
            var ohlcBars = new OHLCBars(10);
            var ohlcBar1 = new OHLCBar(DateTime.Now.Ticks, 1, 2, 3, 4);
            var ohlcBar2 = new OHLCBar(DateTime.Now.Ticks, 1, 2, 3, 4);

            //Act
            ohlcBars.Write(ohlcBar1.Timestamp, ohlcBar1.Open, ohlcBar1.High, ohlcBar1.Low, ohlcBar1.Close);
            ohlcBars.Write(ohlcBar2.Timestamp, ohlcBar2.Open, ohlcBar2.High, ohlcBar2.Low, ohlcBar2.Close);
            ohlcBars.Write(ohlcBar1.Timestamp, ohlcBar1.Open, ohlcBar1.High, ohlcBar1.Low, ohlcBar1.Close);

            //Assert
            Assert.AreEqual(3, ohlcBars.Length);
            Assert.AreEqual(ohlcBars.Current.Timestamp, ohlcBar1.Timestamp);
            Assert.AreEqual(ohlcBars.Current.Open, ohlcBar1.Open);
            Assert.AreEqual(ohlcBars.Current.High, ohlcBar1.High);
            Assert.AreEqual(ohlcBars.Current.Low, ohlcBar1.Low);
            Assert.AreEqual(ohlcBars.Current.Close, ohlcBar1.Close);

            Assert.AreEqual(ohlcBars.Previous.Timestamp, ohlcBar2.Timestamp);
            Assert.AreEqual(ohlcBars.Previous.Open, ohlcBar2.Open);
            Assert.AreEqual(ohlcBars.Previous.High, ohlcBar2.High);
            Assert.AreEqual(ohlcBars.Previous.Low, ohlcBar2.Low);
            Assert.AreEqual(ohlcBars.Previous.Close, ohlcBar2.Close);
        }
示例#2
0
        public void OHLCBar_Persistence_Works()
        {
            //Arrange
            var destinationFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            var filePersistence = new FilePersistenceService();
            var fileWriter      = filePersistence.CreateFileWriter(destinationFile);

            var ohlcBars = new OHLCBars(100, fileWriter);

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

            fileWriter.Close();

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