/// <summary>
        /// Cancels an outstanding order for the specified symbol
        /// </summary>
        /// <param name="symbol">The symbol to cancel the order for</param>
        public void CancelOrder(string symbol)
        {
            var response = Client.DownloadAllOrders().Result;
            var order    = response.Where((a) => { return(a.InstrumentId.Equals(Instruments.GetSymbol <IList <OrderSnapshot> >(a.InstrumentId, response))); });

            if (order.Count() > 0)
            {
                Client.CancelOrder(order.First().CancelUrl);
            }
        }
        static async Task CancelOrder()
        {
            using (RobinhoodClient client = new RobinhoodClient(_token))
            {
                var result = await client.CancelOrder(_orderId);

                if (result.StatusCode == System.Net.HttpStatusCode.OK)
                {
                }
            }
        }
        CancelAllOrders(this RobinhoodClient rh, IEnumerable <OrderSnapshot> orders)
        {
            var tasks = new List <Task>();

            foreach (var o in orders)
            {
                if (o.CancelUrl != null)
                {
                    tasks.Add(rh.CancelOrder(o.CancelUrl));
                }
            }

            return(Task.WhenAll(tasks));
        }
Exemple #4
0
        public static async Task <bool> CancelOrder(OrderSnapshot order)

        {
            if (order != null)
            {
                bool isPending = order.State != null && order.State == "unconfirmed";  /// does this say pending or is there a better way
                                                                                       /// if the order is pending or the order is partial
                if (isPending)
                {
                    var rh = new RobinhoodClient(_token);

                    ///     cancel the order
                    await rh.CancelOrder(order.CancelUrl).ConfigureAwait(false);

                    return(true);
                }
            }

            return(false);
        }
Exemple #5
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");
                }
            }
        }
Exemple #6
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");
                }
            }
        }