// Update the first field by setting your own ApiKey from AlchemyAPI string apikey = "YOUR APIKEY HERE"; int maxCalls = 1000; Symbol[] symbols = Symbols.GetSymbols(); int callsNumber = 0; for(int i=0;i < symbols.Length;i++) { Symbol sym = symbols[i]; DatabasesData data = Databases.GetDatabasesData(sym.Name, "stocktwits", "title"); DatabasesData sentiment = Databases.GetDatabasesData(sym.Name, "stocktwits", "sentiment"); DatabasesData score = Databases.GetDatabasesData(sym.Name, "stocktwits", "score"); if(data.Value.Length == sentiment.Value.Length && data.Value.Length == score.Value.Length) { bool isUpdatedOnce = false; for(int j=0; j < data.Value.Length; j++) { if(callsNumber >= maxCalls) { return; } if((double)sentiment.Value[j] == 0) // The sentiment is not yet calculated for the tweet located at index (j) { isUpdatedOnce = true; string text = data.Value[j].ToString().Replace("||", "\n"); if(text.StartsWith("#")) { text = text.Substring(1); } string result = App.Net.DownloadString("http://access.alchemyapi.com/calls/text/TextGetTextSentiment?apikey=" + apikey + "&text=" + text); callsNumber++; // Extract the score double tscore = 0; int scorePos = result.IndexOf(""); if(scorePos > 0) { tscore = Double.Parse(result.Substring(scorePos + 7).Split('<')[0], System.Globalization.CultureInfo.InvariantCulture); } if(result.Contains("positive")) { sentiment.Value[j] = 1; score.Value[j] = tscore; } else if(result.Contains("negative")) { sentiment.Value[j] = -1; score.Value[j] = tscore; } else if(result.Contains("neutral")) { sentiment.Value[j] = 0.1; score.Value[j] = tscore; } App.Main.AddToOutputList(sym.Name + " (" + j + "): " + sentiment.Value[j] + " -> " + score.Value[j]); } } if(isUpdatedOnce) { Databases.SaveDatabasesData(sentiment); Databases.SaveDatabasesData(score); } } }