示例#1
0
        public static Account GetAccount()
        {
            if (rhAccount == null)
            {
                rhAccount = rh.DownloadAllAccounts().Result.First();
            }

            return(rhAccount);
        }
        /// <summary>
        /// Retrieves the account information
        /// </summary>
        /// <param name="callback">Callback executed after the information has been retrieved</param>
        public void GetAccountInfo(Broker.AccountCallback callback)
        {
            Client.DownloadAllAccounts().ContinueWith((accounts) =>
            {
                if (accounts.IsCompleted && !accounts.IsFaulted)
                {
                    RobinhoodAccount                   = accounts.Result[0];
                    Broker.Account account             = new Broker.Account();
                    account.BuyingPower                = RobinhoodAccount.BuyingPower;
                    account.Cash                       = RobinhoodAccount.Cash;
                    account.CashAvailableForWithdrawal = RobinhoodAccount.Cash - accounts.Result[0].CashHeldForOrders;
                    account.CashHeldForOrders          = RobinhoodAccount.CashHeldForOrders;
                    account.UnclearedDeposits          = RobinhoodAccount.UnclearedDeposits;
                    account.UnsettledFunds             = RobinhoodAccount.UnsettledFunds;

                    Client.DownloadSinglePortfolio(RobinhoodAccount.AccountNumber).ContinueWith((portfolio) =>
                    {
                        AccountPortfolio p = portfolio.Result;
                        account.TotalValue = p.Equity;
                        callback(account);
                    });
                }
                else
                {
                    callback(null);
                }
            });
        }
示例#3
0
        internal static async Task <OptionQuote[]> AttemptToGetAccountData()
        {
            try
            {
                _resultsLabel = $"Account Data";
                Utils.MessageBoxModal($"Attempting to get Account Data ...");

                var rh = new RobinhoodClient(_token);

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

                _results = account;

                Utils.MessageBoxModal("Account Data succeeded.");
            }
            catch (Exception exc)
            {
                Utils.MessageBoxModal(exc.ToString());
            }
            return(null);
        }
示例#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");
                }
            }
        }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args">
        /// args = new string[] { "QQQ", "2019-04-29", "call", "293", "1", "0.01" };
        /// </param>
        private async Task <OrderSnapshot> PlaceOptionOrderAsync(string[] args)
        {
            Debug.Print(System.Reflection.MethodBase.GetCurrentMethod().Name);
            var rh = new RobinhoodClient(_token);

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

            JToken instrumentData = null;

            while (instrumentData == null)
            {
                try
                {
                    // Console.Write("Symbol: ");
                    rh.DownloadOptionStrikeInstrument(args).Wait();

                    instrumentData = rh.results;

                    //Console.WriteLine(instrument.Name);
                }
                catch (Exception ex)
                {
                    //MessageBox.Show(ex.Message + "\n\nInstrument problem. Try again.");
                    System.Threading.Thread.Sleep(1000);
                }
            }

            int qty = Convert.ToInt32(args[4]);

            decimal price = Convert.ToDecimal(args[5]);

            TimeInForce tif = TimeInForce.GoodTillCancel;

            OptionInstrument instrument = new OptionInstrument()
            {
                InstrumentUrl = new Url <OptionInstrument>(instrumentData.SelectToken("url").ToString()),
                Symbol        = instrumentData.SelectToken("chain_symbol").ToString()
            };

            var newOptionOrderSingle = new NewOptionOrderSingle(instrument);

            newOptionOrderSingle.AccountUrl  = account.AccountUrl;
            newOptionOrderSingle.Quantity    = Math.Abs(qty);
            newOptionOrderSingle.Side        = qty > 0 ? Side.Buy : Side.Sell;
            newOptionOrderSingle.TimeInForce = tif;
            newOptionOrderSingle.OrderType   = OrderType.Limit;
            newOptionOrderSingle.Price       = price;

            var order = await rh.PlaceOptionOrder(newOptionOrderSingle);

            //if (!String.IsNullOrEmpty(order.ErrorMessage))
            //    //MessageBox.Show(order.ErrorMessage);
            //else
            //    //MessageBox.Show(string.Format("{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))
            //{
            //    //MessageBox.Show(order.RejectReason);
            //}

            return(order);
        }
示例#6
0
 public static void UpdateAccountInfo()
 {
     UserAccount = Client.DownloadAllAccounts().Result.First();
 }
示例#7
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");
                }
            }
        }