/// <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); }