PlaceOrder(NewOrderSingle newOrderSingle)
        {
            var json = await _rawClient.PlaceOrder(newOrderSingle.ToDictionary());

            return(json.ToObject <OrderSnapshot>());
        }
Пример #2
0
        PlaceOrder(NewOrderSingle newOrderSingle)
        {
            var json = await _rawClient.PlaceOrder(newOrderSingle.ToDictionary()).ConfigureAwait(false);

            return(new OrderSnapshot(json));
        }
Пример #3
0
        public static void Main (string [] args)
        {
            var rh = new RobinhoodClient();

            authenticate(rh).Wait();

            Account account = rh.DownloadAllAccounts().Result.First();

            Instrument instrument = null;
            while (instrument == null)
            {
                try
                {
                    Console.Write("Symbol: ");
                    var symbol = Console.ReadLine().ToUpperInvariant();
                    instrument = rh.FindInstrument(symbol).Result.First(i => i.Symbol == symbol);
                    Console.WriteLine(instrument.Name);
                }
                catch
                {
                    Console.WriteLine("Problem. Try again.");
                }
            }

            int qty = 0;
            while (true)
            {
                
                Console.Write("Quantity (positive for buy, negative for sell): ");
                string q = Console.ReadLine();
                if (Int32.TryParse(q, out qty))
                {
                    break;
                }
            }

            decimal price = 0m;
            while (true)
            {
                Console.Write("Limit price (or 0 for Market order): ");
                string p = Console.ReadLine();
                if (Decimal.TryParse(p, out price))
                {
                    break;
                }
            }

            TimeInForce tif = TimeInForce.Unknown;
            while (true)
            {
                Console.Write("Time in Force (GFD or GTC): ");
                string t = Console.ReadLine();
                if (t.Equals("GFD", StringComparison.InvariantCultureIgnoreCase))
                {
                    tif = TimeInForce.GoodForDay;
                    break;
                }
                else if (t.Equals("GTC", StringComparison.InvariantCultureIgnoreCase))
                {
                    tif = TimeInForce.GoodTillCancel;
                    break;
                }
            }


            var newOrderSingle = new NewOrderSingle(instrument);
            newOrderSingle.AccountUrl = account.AccountUrl;
            newOrderSingle.Quantity   = Math.Abs(qty);
            newOrderSingle.Side       = qty > 0 ? Side.Buy : Side.Sell;

            newOrderSingle.TimeInForce = tif;
            if (price == 0)
            {
                newOrderSingle.OrderType = OrderType.Market;
            }
            else
            {
                newOrderSingle.OrderType = OrderType.Limit;
                newOrderSingle.Price = price;
            }


            var order = rh.PlaceOrder(newOrderSingle).Result;
            Console.WriteLine("{0}\t{1}\t{2} x {3}\t{4}",
                                order.Side,
                                instrument.Symbol,
                                order.Quantity,
                                order.Price.HasValue ? order.Price.ToString() : "mkt",
                                order.State);
            if (!String.IsNullOrEmpty(order.RejectReason))
            {
                Console.WriteLine(order.RejectReason);
            }
            else
            {
                Console.WriteLine("Press C to cancel this order, or anything else to quit");
                var x = Console.ReadKey();
                if (x.KeyChar == 'c' || x.KeyChar == 'C')
                {
                    rh.CancelOrder(order.CancelUrl).Wait();
                    Console.WriteLine("Cancelled");
                }
            }
        }