Example #1
0
        async static Task Run()
        {
            using var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client = new Markets.MarketsClient(channel);

            //var cts = new CancellationTokenSource(TimeSpan.FromSeconds(20));
            var ticks = await client.GetAllTicksAsync(new Empty() /*, cancellationToken: cts.Token*/);

            if (ticks.Ticks.Count > 0)
            {
                foreach (var tick in ticks.Ticks)
                {
                    Display(tick);
                }
                Console.WriteLine($"Count={ticks.Ticks.Count}, Min={ticks.Ticks.Min(p => p.Date):HH:mm:ss}, Max={ticks.Ticks.Max(p => p.Date):HH:mm:ss}");
            }
        }
Example #2
0
        async static Task Run()
        {
            using var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client = new Markets.MarketsClient(channel);

            //var cts = new CancellationTokenSource(TimeSpan.FromSeconds(20));
            using var streamingCall = client.GetTickStream(new Empty() /*, cancellationToken: cts.Token*/);

            try
            {
                await foreach (var tick in streamingCall.ResponseStream.ReadAllAsync(/*cancellationToken: cts.Token*/))
                {
                    Display(tick);
                }
            }
            catch (RpcException ex) when(ex.StatusCode == StatusCode.Cancelled)
            {
                Console.WriteLine("Stream cancelled.");
            }
        }