private void AlterShortLimit(KeyValuePair <Symbol, TradeBar> data, OrderTicket liveticket)
        {
            var     limit    = liveticket.Get(OrderField.LimitPrice);
            decimal newLimit = limit;

            //currentSignalInfo.TradeAttempts++;
            if (newLimit < data.Value.Low)
            {
                newLimit = data.Value.Close - 0.01m;
            }
            OrderResponse response = liveticket.Update(new UpdateOrderFields
            {
                LimitPrice = newLimit,
                Tag        = "Update #" + (liveticket.UpdateRequests.Count + 1)
            });

            if (response.IsSuccess)
            {
                Log(string.Format("Long Order {0}. Status: {1} Updated {2} to new price {3}.", liveticket.OrderId, liveticket.Status, limit, newLimit));
            }
            else
            {
                if (!response.IsProcessed)
                {
                    Log(string.Format("Order {0} not yet processed to new price {1}", liveticket.OrderId, limit));
                }
                if (response.IsError)
                {
                    Log(response.ToString());
                }
            }
        }
Ejemplo 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());
            });
        }