Пример #1
0
        internal void GivenBarDataRequest_WithBars_ReturnsValidBarDataResponse()
        {
            // Arrange
            var provider = new BarProvider(
                this.container,
                this.messagingAdapter,
                this.repository,
                this.barSerializer);

            provider.Start().Wait();

            var barType = StubBarType.AUDUSD_OneMinuteAsk();
            var bar1    = StubBarProvider.Build();
            var bar2    = StubBarProvider.Build();

            this.repository.Add(barType, bar1);
            this.repository.Add(barType, bar2);

            var query = new Dictionary <string, string>
            {
                { "DataType", "Bar[]" },
                { "Symbol", barType.Symbol.Value },
                { "Specification", barType.Specification.ToString() },
                { "FromDateTime", StubZonedDateTime.UnixEpoch().ToIso8601String() },
                { "ToDateTime", StubZonedDateTime.UnixEpoch().ToIso8601String() },
                { "Limit", "0" },
            };

            var request = new DataRequest(
                query,
                Guid.NewGuid(),
                StubZonedDateTime.UnixEpoch());

            // Act
            var response = (DataResponse)provider.FindData(request);
            var bars     = this.barSerializer.DeserializeBlob(response.Data);

            // Assert
            Assert.Equal(typeof(DataResponse), response.Type);
            Assert.Equal(2, bars.Length);
            Assert.Equal(bar1, bars[0]);
            Assert.Equal(bar2, bars[1]);
        }
        internal void CanSerializeAndDeserialize_BarDataResponses()
        {
            // Arrange
            var dataSerializer = new BarSerializer();
            var symbol         = new Symbol("AUD/USD", new Venue("FXCM"));
            var barSpec        = new BarSpecification(1, BarStructure.Minute, PriceType.Bid);
            var correlationId  = Guid.NewGuid();

            var bars           = new[] { StubBarProvider.Build(), StubBarProvider.Build() };
            var serializedBars = dataSerializer.Serialize(bars);

            var metadata = new Dictionary <string, string>
            {
                { "Symbol", symbol.Value },
                { "Specification", barSpec.ToString() },
            };

            var data = dataSerializer.SerializeBlob(serializedBars, metadata);

            var response = new DataResponse(
                data,
                typeof(Bar[]).Name,
                dataSerializer.BlobEncoding,
                correlationId,
                Guid.NewGuid(),
                StubZonedDateTime.UnixEpoch());

            // Act
            var serializedResponse   = this.serializer.Serialize(response);
            var deserializedResponse = (DataResponse)this.serializer.Deserialize(serializedResponse);
            var deserializedData     = dataSerializer.DeserializeBlob(deserializedResponse.Data);

            // Assert
            Assert.Equal(response, deserializedResponse);
            Assert.Equal(bars, deserializedData);
            Assert.Equal(correlationId, deserializedResponse.CorrelationId);
            this.Output.WriteLine(Convert.ToBase64String(serializedResponse));
            this.Output.WriteLine(Encoding.UTF8.GetString(serializedResponse));
        }