Exemplo n.º 1
0
        public override async Task <Empty> InitializeService(Empty request, ServerCallContext context)
        {
            Logger.Here().Information("BGN");
            try {
                var response = orderService.InitializeServiceAsync(request);

                Logger.Here().Information("END");
                return(await response);
            } catch (Exception e) {
                Logger.Here().Warning(e.Message);
                throw new RpcException(new Status(StatusCode.Internal, e.Message));
            }
        }
Exemplo n.º 2
0
        private static async Task DoSomething(IOrderServiceRpcClient client)
        {
            Random        rnd     = new Random();
            List <String> tickers = new List <String> {
                "ERX", "SPY", "DIA", "QQQ", "UPRO", "SPXU", "OILU", "OILD"
            };

            Display("Initializing service...");
            try {
                await client.InitializeServiceAsync(new Empty());
            } catch (Exception e) {
                Display("An error occurred: " + e.Message);
            }
            Display("Service initialized");

            // Quote quote = await client.GetQuoteAsync(new StringMessage { Value = "ERX" });
            // Display(quote.ToString());

            int             numThreads = 10;
            int             numTrades  = 100;
            ParallelOptions opt        = new ParallelOptions()
            {
                MaxDegreeOfParallelism = numThreads
            };

            Parallel.For(0, numTrades, opt, async i => {
                String ticker = tickers[rnd.Next(1, tickers.Count + 1) - 1];
                Display("Submitting order...");
                OrderResponse response = null;
                try {
                    response = await client.SubmitOrderAsync(new OrderRequest {
                        AccountId   = "gRPC-BUY",
                        Action      = OrderAction.OrderBuy,
                        Ticker      = ticker,
                        Type        = OrderType.OrderMarket,
                        Quantity    = 10,
                        OrderPrice  = 0,
                        TimeInForce = OrderTimeInForce.OrderDay
                    });
                } catch (Exception e) {
                    Display("An error occurred: " + e.Message);
                }
                Display("Order submitted: " + response.ToString());
            });
        }