public void BookMatchSerialize()
        {
            var saved = (BookMatch)CreateBook(BookType.Match);

            using (var memory = new MemoryStream())
            {
                using (var serial = GdaxFile.OpenWrite(memory, true))
                {
                    serial.Serialize(saved);
                }

                memory.Seek(0, SeekOrigin.Begin);
                using (var serial = GdaxFile.OpenRead(memory, true))
                {
                    var read = serial.Deserialize() as BookMatch;

                    AssertBase(saved, read);
                    Assert.AreEqual(saved.Price, read.Price);
                    Assert.AreEqual(saved.TradeId, read.TradeId);
                    Assert.AreEqual(saved.MakerOrderId, read.MakerOrderId);
                    Assert.AreEqual(saved.TakerOrderId, read.TakerOrderId);
                    Assert.AreEqual(saved.Size, read.Size);
                }
            }
        }
        public void SerializeProductBook()
        {
            var product = new ProductBook(42);

            product.Buys.Add(new ProductOffer {
                OrderId = Guid.NewGuid(), Price = 4210.2m, Size = 0.004m
            });
            product.Sells.Add(new ProductOffer {
                OrderId = Guid.NewGuid(), Price = 3852.12m, Size = 2.56m
            });
            product.Sells.Add(new ProductOffer {
                OrderId = Guid.NewGuid(), Price = 3642.12m, Size = 7.12m
            });

            using (var memory = new MemoryStream())
            {
                using (var serial = GdaxFile.OpenWrite(memory, true))
                {
                    serial.Serialize(product, DateTime.UtcNow);
                }

                memory.Seek(0, SeekOrigin.Begin);
                using (var serial = GdaxFile.OpenRead(memory, true))
                {
                    var read = serial.DeserializeProductBook();

                    product.ShouldBeEquivalentTo(read);
                }
            }
        }
示例#3
0
        private void OpenFile()
        {
            ClosePreviousFile();

            _fileDate = DateTime.Today;

            _filename = Path.Combine(_rootPath, GdaxFile.GetFilename(_fileDate, 60));
            _gdaxFile = GdaxFile.OpenWrite(_filename);
            Program.Log.Info($"File '{_filename}' is open");

            if (_productBook != null)
            {
                _gdaxFile.Serialize(_productBook, DateTime.UtcNow);
                Program.Log.Info("Current product book added to file");
            }
        }
        public void SerializeCandle()
        {
            var saved = new Candle(new DateTime(2017, 5, 20, 0, 0, 0, DateTimeKind.Utc), 42, 84, 120.54M, 654.235M, 452.125M);

            using (var memory = new MemoryStream())
            {
                using (var serial = GdaxFile.OpenWrite(memory, true))
                {
                    serial.Serialize(saved);
                }

                memory.Seek(0, SeekOrigin.Begin);
                using (var serial = GdaxFile.OpenRead(memory, true))
                {
                    var read = serial.DeserializeCandle();
                    Assert.AreEqual(saved, read);
                }
            }
        }
        public void SerializeEmptyObject(Type objectType)
        {
            var saved = (BookBase)Activator.CreateInstance(objectType);

            using (var memory = new MemoryStream())
            {
                using (var serial = GdaxFile.OpenWrite(memory, true))
                {
                    serial.Serialize(saved);
                }

                memory.Seek(0, SeekOrigin.Begin);
                using (var serial = GdaxFile.OpenRead(memory, true))
                {
                    var read = serial.Deserialize();
                    AssertBase(saved, read as BookBase);
                }
            }
        }
        public void BookOpenSerialize()
        {
            var saved = (BookOpen)CreateBook(BookType.Open);

            using (var memory = new MemoryStream())
            {
                using (var serial = GdaxFile.OpenWrite(memory, true))
                {
                    serial.Serialize(saved);
                }

                memory.Seek(0, SeekOrigin.Begin);
                using (var serial = GdaxFile.OpenRead(memory, true))
                {
                    var read = serial.Deserialize() as BookOpen;

                    AssertBase(saved, read);
                    Assert.AreEqual(saved.Price, read.Price);
                    Assert.AreEqual(saved.RemainingSize, read.RemainingSize);
                }
            }
        }