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); } } }
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); } } }
private IEnumerable <T> GetBooks <T>(ProductType productType, DateTime time, int granularity = MinGranularity) where T : class { bool dataExists; do { var filename = Path.Combine(_dataPath, GdaxFile.GetRelativePath(productType, granularity), GdaxFile.GetFilename(time, granularity)); dataExists = File.Exists(filename); if (dataExists) { using (var serialiser = GdaxFile.OpenRead(filename)) { var eof = false; do { T book = null; try { var obj = serialiser.Deserialize(); // Return fake BookMatch for candles (for simulation from candle dump) book = obj is T ? obj as T : ((Candle)obj).ToBookMatch(ProductType.BTC_EUR) as T; } catch (EndOfStreamException) { eof = true; } if (book != null) // && book.Time >= time) { yield return(book); } } while (!eof); time += TimeSpan.FromDays(1); } } } while (dataExists); }
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); } } }