/// <summary>
 /// Searches for stocks based on the symbol string
 /// </summary>
 /// <param name="symbol">The symbol (or portion of) to search for</param>
 /// <param name="callback">Callback executed once the search is complete</param>
 public void Search(string symbol, DataAccessor.SearchCallback callback)
 {
     if (Client.isAuthenticated)
     {
         Client.FindInstrument(symbol).ContinueWith((instrument) =>
         {
             Dictionary <string, string> searchResult = new Dictionary <string, string>();
             foreach (var stock in instrument.Result)
             {
                 if (!searchResult.ContainsKey(stock.Symbol))
                 {
                     searchResult.Add(stock.Symbol, stock.Name);
                 }
             }
             callback(searchResult);
         });
     }
 }
Example #2
0
        public async Task <Instrument> GetInstrument(string symbol)
        {
            Instrument instrument = null;

            if (!_symbolToInstrument.TryGetValue(symbol, out instrument))
            {
                // Find the instrument
                var list = await _client.FindInstrument(symbol).ConfigureAwait(false);

                instrument = list.First(i => i.Symbol == symbol);
                addInstrument(instrument);
            }

            return(instrument);
        }
Example #3
0
        public static List <Stock> GetQuote(List <Stock> stocks = null)
        {
            List <Stock> newList = new List <Stock>();

            if (stocks.Count() > 0 && rh != null)
            {
                IList <Quote> quotes;
                try
                {
                    quotes = rh.DownloadQuote(stocks.Select(s => s.Ticker)).Result;
                }
                catch (Exception e)
                {
                    quotes = null;
                }
                //if (stocks == null)
                //  stocks = new List<Stock>();
                if (quotes != null)
                {
                    foreach (var q in quotes)
                    {
                        if (q is null)
                        {
                            continue;
                        }
                        Instrument instrument = rh.FindInstrument(q.Symbol).Result.FirstOrDefault(i => i.Symbol == q.Symbol);

                        if (instrument is null)
                        {
                            continue;
                        }

                        Stock stock = stocks.Find(s => s.Ticker == q.Symbol);

                        if (stock is null)
                        {
                            stock = new Stock();
                        }

                        stock.Ticker = q.Symbol;
                        //if (stock.Ticker != "AAPL" || stock.LastTradePrice < q.LastTradePrice)
                        stock.LastTradePrice = Math.Round(q.LastTradePrice, 2);
                        //if (stock.Ticker != "AAPL" )


                        stock.ChangePctng   = Math.Round(q.ChangePercentage, 2);
                        stock.AskPrice      = Math.Round(q.AskPrice, 2);
                        stock.BidPrice      = Math.Round(q.BidPrice, 2);
                        stock.InstrumentURL = instrument.InstrumentUrl.Uri.AbsoluteUri;
                        string chngSym = string.Empty;

                        if (q.ChangePercentage < 0)
                        {
                            stock.Color   = Color.IndianRed;
                            stock.ChngSym = "-";
                        }
                        else
                        {
                            stock.Color   = Color.SeaGreen;
                            stock.ChngSym = "+";
                        }

                        //return string.("{0}: ${1} ({2}{3}%)", stock.Ticker,
                        //    lastTradePrice.ToString(),
                        //    chngSym,
                        //    changePctng.ToString());

                        newList.Add(stock);
                    }
                    //NotifyPropertyChanged();
                }
            }
            return(newList);
        }
Example #4
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");
                }
            }
        }
Example #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");
                }
            }
        }