Beispiel #1
0
        public async Task <Task> RegisterStreamAsync(StreamInfo <T> streamInfo, List <T> initData = null)
        {
            var data = StreamData <T> .Create(streamInfo, initData);

            _lock.EnterWriteLock();

            try
            {
                _streamList.Add(data);
            }
            finally
            {
                _lock.ExitWriteLock();
            }

            if (initData == null)
            {
                return(data.CompletionTask.Task);
            }

            var tasks = initData.Select(value => WriteStreamAsync(data, value)).ToList();

            await Task.WhenAll(tasks);

            return(data.CompletionTask.Task);
        }
Beispiel #2
0
        public Task RegisterStream(StreamInfo <T> streamInfo, T initData = null)
        {
            var data = StreamData <T> .Create(streamInfo, initData);

            _streamList.Add(data);

            if (initData != null)
            {
                data.Stream.WriteAsync(initData);
            }

            return(data.CompletionTask.Task);
        }
Beispiel #3
0
        private void RemoveStream(StreamData <T> streamData)
        {
            _lock.EnterWriteLock();
            try
            {
                streamData.CompletionTask.TrySetResult(1);
                _streamList.Remove(streamData);
            }
            finally
            {
                _lock.ExitWriteLock();
            }

            Console.WriteLine($"Remove stream connect (peer: {streamData.Peer})");
        }
Beispiel #4
0
 private async Task WriteStreamAsync(StreamData <T> streamData, T data)
 {
     try
     {
         await streamData.Stream.WriteAsync(data);
     }
     catch (InvalidOperationException)
     {
         RemoveStream(streamData);
     }
     catch (Exception e)
     {
         _log.Error(e, "Can't write to stream", context: streamData.Peer);
         RemoveStream(streamData);
     }
 }
        private Orderbook GetOrderbook(Orderbook data, StreamData <Orderbook> streamData, bool updateDate)
        {
            if (streamData.LastSentData == null)
            {
                return(data);
            }

            var newOrderBook = _mapper.Map <Domain.Entities.Orderbook>(data);
            var oldOrderBook = _mapper.Map <Domain.Entities.Orderbook>(streamData.LastSentData);

            Domain.Entities.Orderbook update = _orderbooksService.GetOrderbookUpdates(oldOrderBook, newOrderBook);

            var result = _mapper.Map <Orderbook>(update);

            result.Asks.AddRange(_mapper.Map <List <Orderbook.Types.PriceVolume> >(update.Asks));
            result.Bids.AddRange(_mapper.Map <List <Orderbook.Types.PriceVolume> >(update.Bids));

            if (updateDate)
            {
                result.Timestamp = Timestamp.FromDateTime(DateTime.UtcNow);
            }

            return(result);
        }
Beispiel #6
0
 internal virtual T ProcessPingDataBeforeSend(T data, StreamData <T> streamData)
 {
     return(data);
 }
 internal override PublicTradeUpdate ProcessPingDataBeforeSend(PublicTradeUpdate data, StreamData <PublicTradeUpdate> streamData)
 {
     return(new PublicTradeUpdate());
 }
 internal override Orderbook ProcessPingDataBeforeSend(Orderbook data, StreamData <Orderbook> streamData)
 {
     return(GetOrderbook(data, streamData, true));
 }
Beispiel #9
0
 private void RemoveStream(StreamData <T> streamData)
 {
     streamData.CompletionTask.TrySetResult(1);
     _streamList.Remove(streamData);
     Console.WriteLine($"Remove stream connect (peer: {streamData.Peer})");
 }