public static void Main (string [] args) { if (args.Length == 0) { Console.WriteLine("Usage:"); Console.WriteLine("RgQuote SYMBOL1 [SYMBOL2 SYMBOL3 SYMBOL_N]"); Environment.Exit(1); } var rh = new RobinhoodClient(); authenticate(rh).Wait(); var quotes = rh.DownloadQuote(args).Result; Console.WriteLine(DateTime.Now); foreach (var q in quotes) { if (q == null) { continue; } Console.WriteLine("{0}\tCh: {1}%\tLTP: {2}\tBID: {3}\tASK: {4}", q.Symbol, q.ChangePercentage, q.LastTradePrice, q.BidPrice, q.AskPrice); } }
private async void Speak(object sender, System.Windows.RoutedEventArgs e) { TaskbarItemInfo taskbarItemInfo = new TaskbarItemInfo(); taskbarItemInfo.ProgressValue = .5; taskbarItemInfo.ProgressState = TaskbarItemProgressState.Paused; var args = new[] { "RgQuote", "F" }; // string[] var rh = new RobinhoodClient(); await authenticate(rh); while (1 < 2) { var quotes = await rh.DownloadQuote(args); //Console.WriteLine(DateTime.Now); foreach (var q in quotes) { if (q != null) { textToSpeech.Text = q.LastTradePrice.ToString(); } } } }
public static void Main(string [] args) { if (args.Length == 0) { Console.WriteLine("Usage:"); Console.WriteLine("RgQuote SYMBOL1 [SYMBOL2 SYMBOL3 SYMBOL_N]"); Environment.Exit(1); } var rh = new RobinhoodClient(); authenticate(rh).Wait(); while (1 < 2) { var quotes = rh.DownloadQuote(args).Result; Console.WriteLine(DateTime.Now); foreach (var q in quotes) { if (q == null) { continue; } Console.WriteLine("{0}\tCh: {1}%\tLTP: {2}\tBID: {3}\tASK: {4}", q.Symbol, q.ChangePercentage, q.LastTradePrice, q.BidPrice, q.AskPrice); } } Console.Read(); }
public static async Task authenticate(RobinhoodClient client) { /// See if we need a new token file - either none exists or file is over X hours old bool shouldGetNewTokenFile = !System.IO.File.Exists(__tokenFile) || !IsTokenFileAgeLessThan(CONSTANTS.TOKEN_FILE_MAX_AGE_HOURS); if (shouldGetNewTokenFile) { await GenerateTokenFile().ConfigureAwait(continueOnCapturedContext: false); } ; //startApp(); /// Run a console app to create a token file /// If the file exists and it's less than X hours old if (System.IO.File.Exists(__tokenFile) && IsTokenFileAgeLessThan(CONSTANTS.TOKEN_FILE_MAX_AGE_HOURS)) { /// Read the access token from the token file var token = System.IO.File.ReadAllText(__tokenFile); /// Use the access token to authenticate await client.Authenticate(token); } }
static bool authenticate(RobinhoodClient client) { if (System.IO.File.Exists(__tokenFile)) { var token = System.IO.File.ReadAllText(__tokenFile); if (!client.Authenticate(token)) { if (System.IO.File.Exists(__tokenFile)) { System.IO.File.Delete(__tokenFile); } return(false); } return(true); } else { Console.Write("username: "******"password: "); string password = getConsolePassword(); if (!client.Authenticate(userName, password)) { return(false); } System.IO.Directory.CreateDirectory( System.IO.Path.GetDirectoryName(__tokenFile)); System.IO.File.WriteAllText(__tokenFile, client.AuthToken); return(true); } }
public static void AttemptLogin() { try { var rh = new RobinhoodClient(); //Utils.MessageBoxModal("Attempting Authentication..."); RhLogins.authenticate(rh).Wait(); _token = rh.AuthToken; _resultsLabel = "Authentication"; if (rh.AuthToken == null) { Utils.MessageBoxModal("No Authentication token."); return; } else { //Utils.MessageBoxModal("Authentication succeeded."); } } catch (Exception exc) { Utils.MessageBoxModal(exc.ToString()); } }
// This method gets called by the runtime. Use this method to add services to the container public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Stock Market API", Version = "v1" }); }); // Add S3 to the ASP.NET Core dependency injection framework. services.AddAWSService <Amazon.S3.IAmazonS3>(); services.AddMvcCore(options => { options.Filters.Add(typeof(ModelValidatorAttribute)); }); services.AddTransient <IStockMarketQuoteManager, StockMarketQuoteManager>(); if (!RobinhoodClient.Init(Configuration).Result) { throw new TypeInitializationException("RobinhoodClient", new Exception("RobinhoodClient could not initialized.")); } }
public static void TestLogin() { var rh = new RobinhoodClient(); var tokenBefore = rh.AuthToken; RhLogins.authenticate(rh).Wait(); Debug.Assert(tokenBefore != rh.AuthToken, "Rh Login"); }
static async Task CancelOrder() { using (RobinhoodClient client = new RobinhoodClient(_token)) { var result = await client.CancelOrder(_orderId); if (result.StatusCode == System.Net.HttpStatusCode.OK) { } } }
static async Task Login() { using (RobinhoodClient client = new RobinhoodClient()) { var result = await client.Login(_username, _password); if (result.StatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine(result.Data.Token); } } }
static async Task LoginWithToken() { using (RobinhoodClient client = new RobinhoodClient(_token)) { var result = await client.Quote("TWTR"); if (result.StatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine(result.Data.Symbol); } } }
static async Task GetQuote() { using (RobinhoodClient client = new RobinhoodClient(_token)) { var result = await client.Quote("TWTR"); if (result.StatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine(result.Data.BidPrice); } } }
static async Task GetInstrument() { using (RobinhoodClient client = new RobinhoodClient(_token)) { var result = await client.Instrument(UrlManager.GetInstrumentNumber(_instrumentTwitter)); if (result.StatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine(result.Data.Name); } } }
static async Task GetUserInformations() { using (RobinhoodClient client = new RobinhoodClient(_token)) { var result = await client.User(); if (result.StatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine(result.Data.Username); } } }
public static async Task Login() { //Read login credentials StreamReader loginFile = File.OpenText("Login.login"); Username = loginFile.ReadLine(); Password = loginFile.ReadLine(); Client = new RobinhoodClient(); await Client.Authenticate(Username, Password); UpdateAccountInfo(); }
static async Task GenerateTokenFile() { //Console.Write("username: "); var rh = new RobinhoodClient(); await rh.Authenticate(CONSTANTS.USER_NAME, CONSTANTS.PASSWORD).ConfigureAwait(continueOnCapturedContext: false);; System.IO.Directory.CreateDirectory( System.IO.Path.GetDirectoryName(__tokenFile)); System.IO.File.WriteAllText(__tokenFile, rh.AuthToken); }
static async Task ListPositions() { using (RobinhoodClient client = new RobinhoodClient(_token)) { var result = await client.Positions(); if (result.StatusCode == System.Net.HttpStatusCode.OK) { result.Data.Results.ForEach(position => Console.WriteLine(position.Quantity) ); } } }
static async Task ListOrders() { using (RobinhoodClient client = new RobinhoodClient(_token)) { var result = await client.Orders(); if (result.StatusCode == System.Net.HttpStatusCode.OK) { result.Data.Results.ForEach(order => Console.WriteLine(order.Price) ); } } }
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)); }
internal static async Task <Quote> GetQuote(string symbol) { try { var rh = new RobinhoodClient(_token); _quote = await rh.DownloadQuote(symbol).ConfigureAwait(continueOnCapturedContext: false); } catch (Exception exc) { Utils.MessageBoxModal(exc.ToString()); } return(null); }
static async Task ListAccounts() { using (RobinhoodClient client = new RobinhoodClient(_token)) { var result = await client.Accounts(); if (result.StatusCode == System.Net.HttpStatusCode.OK) { result.Data.Results.ForEach(account => Console.WriteLine(account.AccountNumber) ); } } }
internal static async Task <OptionQuote[]> GetOptionQuote(string symbol, string expires, decimal strikePrice, int nRange) { try { _resultsLabel = $"{symbol} {expires} {strikePrice}"; var rh = new RobinhoodClient(_token); _options = await rh.DownloadOptionQuotes(new string[] { symbol, expires, strikePrice.ToString(), nRange.ToString() }) .ConfigureAwait(continueOnCapturedContext: false); } catch { } //catch (Exception exc) //{ // Utils.MessageBoxModal(exc.ToString()); //} return(new OptionQuote[1]); }
internal static async Task <Quote> AttemptToGetQuote(string symbol) { try { Utils.MessageBoxModal($"Attempting to get Quote for {symbol}..."); var rh = new RobinhoodClient(_token); _results = await rh.DownloadQuote(symbol).ConfigureAwait(continueOnCapturedContext: false); _resultsLabel = symbol; Utils.MessageBoxModal("Quote succeeded."); } catch (Exception exc) { Utils.MessageBoxModal(exc.ToString()); } return(null); }
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); }
internal static async Task <OptionQuote[]> AttemptToGetOptionQuote(string symbol, string expires, decimal strikePrice) { try { _resultsLabel = $"{symbol} {expires} {strikePrice}"; Utils.MessageBoxModal($"Attempting to get Option Quote for {_resultsLabel}..."); var rh = new RobinhoodClient(_token); _results = await rh.DownloadOptionQuotes(new string[] { symbol, expires, strikePrice.ToString(), "2" }) .ConfigureAwait(continueOnCapturedContext: false); Utils.MessageBoxModal("Option Quote succeeded."); } catch (Exception exc) { Utils.MessageBoxModal(exc.ToString()); } return(null); }
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); }
static async Task GetPortfolios() { using (RobinhoodClient client = new RobinhoodClient(_token)) { var resultPortfolios = await client.Portfolios(); if (resultPortfolios.StatusCode == System.Net.HttpStatusCode.OK) { resultPortfolios.Data.Results.ForEach(portfolio => Console.WriteLine(portfolio.MarketValue) ); } //by accountNumber var resultPortfolio = await client.Portfolios(UrlManager.GetAccountNumber(_account)); if (resultPortfolio.StatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine(resultPortfolio.Data.MarketValue); } } }
static async Task authenticate(RobinhoodClient client) { if (System.IO.File.Exists(__tokenFile)) { var token = System.IO.File.ReadAllText(__tokenFile); await Task.FromResult(client.Authenticate(token)); } else { Console.Write("username: "******"password: "); string password = getConsolePassword(); await Task.FromResult(client.Authenticate(userName, password)); System.IO.Directory.CreateDirectory( System.IO.Path.GetDirectoryName(__tokenFile)); System.IO.File.WriteAllText(__tokenFile, client.AuthToken); } }
static async Task NewOrder() { using (RobinhoodClient client = new RobinhoodClient(_token)) { var result = await client.Orders(new Model.NewOrder() { Account = _account, Price = 10, Quantity = 1, Side = Model.Side.Buy, TimeInForce = "gfd", Trigger = "immediate", Type = "market", Symbol = "TWTR", Instrument = _instrumentTwitter }); if (result.IsSuccessStatusCode) { _orderId = result.Data.Id; } } }
static async Task authenticate(RobinhoodClient client, string userName, string pwd) { if (System.IO.File.Exists(__tokenFile)) { var token = System.IO.File.ReadAllText(__tokenFile); await client.Authenticate(token); } else { //Console.Write("username: "******"jamiator21"; //Console.ReadLine(); //Console.WriteLine("username: jamiator21"); // Console.Write("password: "******"Complicated12";// getConsolePassword(); await client.Authenticate(userName, pwd); System.IO.Directory.CreateDirectory( System.IO.Path.GetDirectoryName(__tokenFile)); System.IO.File.WriteAllText(__tokenFile, client.AuthToken); } }
static async Task authenticate (RobinhoodClient client) { if (System.IO.File.Exists(__tokenFile)) { var token = System.IO.File.ReadAllText(__tokenFile); await client.Authenticate(token); } else { Console.Write("username: "******"password: "); string password = getConsolePassword(); await client.Authenticate(userName, password); System.IO.Directory.CreateDirectory( System.IO.Path.GetDirectoryName(__tokenFile)); System.IO.File.WriteAllText(__tokenFile, client.AuthToken); } }
public InstrumentCache (RobinhoodClient client) { _client = client; _symbolToInstrument = new Dictionary<string, Instrument>(); _instrumentKeyToIntrument = new Dictionary<string, Instrument>(); }
/// <summary> /// Logs the user out of the brokerage account /// </summary> public void SignOut() { // Cannot sign out, so simply create a new client which isn't signed in Client = new RobinhoodClient(); }
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"); } } }