public static StockInfo Create( string ticker, string industry, string companyName, string logo, CurrentPrice currentPrice, PriceTarget priceTarget, Recommendations recommendationTrend ) { var stock = new StockInfo() { Ticker = ticker, Industry = industry, CompanyName = companyName, Logo = logo, CurrentPrice = currentPrice.C, TargetPriceHigh = priceTarget.High, TargetPriceMean = priceTarget.Mean, TargetPriceMedian = priceTarget.Median, TargetPriceLow = priceTarget.Low, StrongBuy = recommendationTrend.StrongBuy, Buy = recommendationTrend.Buy, Hold = recommendationTrend.Hold, Sell = recommendationTrend.Sell, StrongSell = recommendationTrend.StrongSell, }; return(stock); }
public async Task <PriceTarget> GetStockPriceTarget(string tickerSymbol) { //string requestUrl = @"https://finnhub.io/api/v1/stock/price-target?symbol=JPM&token=bt19fvf48v6qjjkjkn7g"; JsonSerializerSettings settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore, Formatting = Formatting.None, Converters = new List <JsonConverter> { new DecimalConverter() } }; string requestUrl = String.Format(@"https://finnhub.io/api/v1/stock/price-target?symbol={0}&token=bt19fvf48v6qjjkjkn7g", tickerSymbol); using (var client = new HttpClient()) { string content = await client.GetStringAsync(requestUrl); PriceTarget returnTarget = null; try { returnTarget = JsonConvert.DeserializeObject <PriceTarget>(content, settings); } catch (JsonException je) { Console.WriteLine(je.Message); } return(returnTarget); } }
/// <summary> /// Creates a new SettingsViewModel. /// </summary> public SettingsViewModel(IPluginSettings settings) { Settings = settings; DisplayedMealTypes = SettingsUtils.GetEnumPairs(Settings.DisplayedMealTypes, MealType.Unknown); _previousTarget = settings.PriceTarget; }
public async Task SetPriceTargetAsync(DateTime date, string ticker, PriceTarget priceTarget) { date = date.Date; using (var connection = new NpgsqlConnection(dbConnection)) { var query = "INSERT INTO target_prices(ticker_id, high, low, mean, median, date, date_added) " + "SELECT c.id, @high, @low, @mean, @median, @date, now() " + "FROM companies c " + "WHERE c.ticker = @ticker; "; var param = new { ticker = ticker, high = priceTarget.High, low = priceTarget.Low, mean = priceTarget.Mean, median = priceTarget.Median, date = date }; await connection.ExecuteAsync(query, param); } }
/// <summary> /// Gets the price of the meal for the specified price target. /// </summary> public double?GetPrice(PriceTarget target) { if (Prices.ContainsKey(target)) { return(Prices[target]); } if (Prices.Any(pair => pair.Key > target)) { return(Prices.First(pair => pair.Key > target).Value); } if (Prices.Any()) { return(Prices.First().Value); } return(null); }
public void SetCurrentPrice( PriceTarget target ) { if ( Prices.ContainsKey( target ) ) { CurrentPrice = Prices[target]; } else if ( Prices.Any( pair => pair.Key > target ) ) { CurrentPrice = Prices.First( pair => pair.Key > target ).Value; } else if ( Prices.Any() ) { CurrentPrice = Prices.First().Value; } else { CurrentPrice = null; } }
public ActionResult PriceTarget(string symbol) { symbol = symbol.ToUpperInvariant(); PriceTargets priceTarget = repository.GetPriceTargets(symbol); if (priceTarget is not null && !priceTarget.IsStale(1440)) { return(Ok(priceTarget)); } var parameters = $"https://finnhub.io/api/v1/stock/price-target?symbol={symbol}"; HttpResponseMessage response = finnhubClient.GetAsync(parameters).Result; if (!response.IsSuccessStatusCode) { return(BadRequest($"Status code: {response.StatusCode}")); } PriceTarget target = response.Content.ReadFromJsonAsync <PriceTarget>(serializerOptions).Result; if (target is null) { return(BadRequest("Price target was empty.")); } bool shouldAdd = priceTarget is null; priceTarget = mapper.Map <PriceTargets>(target); priceTarget.LastUpdated = DateTimeOffset.UtcNow; if (shouldAdd) { repository.AddEntity(priceTarget); } repository.SaveAll(); return(Ok(priceTarget)); }
private void buttonSave_Click(object sender, EventArgs e) { stock.Ticker = textBoxTicker.Text; if (string.IsNullOrEmpty(stock.Ticker)) { MessageBox.Show("Must Enter a Valid Ticker."); return; } //stock.PriceTarget.Value = PriceTarget.numericUpDownValue.Value; //stock.PriceTarget.TrailPrcntg = PriceTarget.trailPrcntgNumericUpDown.Value; //stock.PriceTarget.Type = (PricePointControl.OrderType)PriceTarget.comboBoxOrderType.SelectedValue; //stock.PriceTarget.Execution = (PricePointControl.Execution)PriceTarget.comboBoxExecution.SelectedValue; //stock.PriceTarget.Trigger = (TriggerType)PriceTarget.triggerComboBox.SelectedValue; //stock.PriceTarget.FollowPrice = (PricePointControl.FollowPrice)PriceTarget.toFollowComboBox.SelectedValue; //stock.PriceTarget.NoOfShares = (int)PriceTarget.numericUpDownNoOfShares.Value; stock.PriceTarget = PriceTarget.Get(); //if (stock.PriceTarget.Value > 0 && stock.PriceTarget.NoOfShares == 0) //{ // MessageBox.Show("Enter No of Shares to sell when Price reaches Price Target."); // return; //} //stock.Entry.Type = (PricePointControl.OrderType)Entry.comboBoxOrderType.SelectedValue; //stock.Entry.Execution = (PricePointControl.Execution)Entry.comboBoxExecution.SelectedValue; //stock.Entry.Trigger = (TriggerType)Entry.triggerComboBox.SelectedValue; //stock.Entry.FollowPrice = (PricePointControl.FollowPrice)Entry.toFollowComboBox.SelectedValue; //stock.Entry.NoOfShares = (int)Entry.numericUpDownNoOfShares.Value; //stock.Entry.Value = Entry.numericUpDownValue.Value; //stock.Entry.TrailPrcntg = Entry.trailPrcntgNumericUpDown.Value; stock.Entry = Entry.Get(); //if (stock.Entry.Value > 0 && stock.Entry.NoOfShares == 0) //{ // MessageBox.Show("Enter No of Shares to but when Price reaches Entry Price."); // return; //} //stock.StopLoss.Value = Stop.numericUpDownValue.Value; //stock.StopLoss.TrailPrcntg = Stop.trailPrcntgNumericUpDown.Value; //stock.StopLoss.Type = (PricePointControl.OrderType)Stop.comboBoxOrderType.SelectedValue; //stock.StopLoss.Execution = (PricePointControl.Execution)Stop.comboBoxExecution.SelectedValue; //stock.StopLoss.Trigger = (TriggerType)Stop.triggerComboBox.SelectedValue; //stock.StopLoss.FollowPrice = (PricePointControl.FollowPrice)Stop.toFollowComboBox.SelectedValue; //stock.StopLoss.NoOfShares = (int)Stop.numericUpDownNoOfShares.Value; stock.StopLoss = Stop.Get(); //if (stock.StopLoss.Value > 0) //{ // if (stock.StopLoss.NoOfShares == 0) // { // MessageBox.Show("Enter No of Shares to sell when Price reaches Stop Loss Price."); // return; // } // ////Set Stop loss if not already set // //if (setStopLoss) // //{ // // //Robinhood.Init(); // // //Robinhood.PlaceOrder(stock.Ticker, stock.StopLoss, TimeInForce.GoodTillCancel); // // stock.StopLoss.NoOfShares *= -1; // // if(stock.Trade) // // ThreadPool.QueueUserWorkItem(PlaceStop,stock); // // //MainForm.PlaceOrder(stock.Ticker, stock.StopLoss, TimeInForce.GoodTillCancel); // //} //} stock.DayTrade = checkBoxDayTrade.Checked; stock.ManageTrade = checkManageTrade.Checked; stock.NoOfShares = (int)NoOfShares.Value; stock.CostBasis = CostBasis.Value; stock.Volatility = Volatility.Value; stock.MaxLoss = MaxLossAmnt.Value; stock.MaxPrctgLoss = Math.Round(MaxLossPrcntg.Value, 2); save = true; this.Close(); }
public HoldingForm(int refreshTime, Stock stock = null) { try { InitializeComponent(); this.Opacity = 0.99; timer1.Interval = 10; timer1.Enabled = true; timer1.Tick += timer1_Tick; Entry.ExecutionSpreadSelected += pricePointControlEntry_ExecutionSpreadSelected; Entry.numericUpDownNoOfShares.ValueChanged += numericUpDownNoOfShares_ValueChanged; Entry.PlaceOrder += Entry_PlaceOrder; Entry.TriggerSelected += Entry_TriggerSelected; PriceTarget.ExecutionSpreadSelected += pricePointControlPriceTarget_ExecutionSpreadSelected; PriceTarget.PlaceOrder += PriceTarget_PlaceOrder; PriceTarget.TriggerSelected += PriceTarget_TriggerSelected; Stop.ExecutionSpreadSelected += pricePointControlStop_ExecutionSpreadSelected; Stop.PlaceOrder += Stop_PlaceOrder; Stop.TriggerSelected += Stop_TriggerSelected; Entry.FollowSelected += Entry_FollowSelected; PriceTarget.FollowSelected += PriceTarget_FollowSelected; Stop.FollowSelected += Stop_FollowSelected; this.refreshTime = refreshTime; textBoxTicker.DelayedTextChangedTimeout = 1000; textBoxTicker.DelayedTextChanged += textBoxTicker_DelayedTextChanged; if (stock == null) { textBoxTicker.Enabled = true; this.stock = new Stock(""); } else { textBoxTicker.Enabled = false; this.stock = stock; } textBoxTicker.Text = this.stock.Ticker; //Temp remove if (this.stock.PriceTarget == null) { this.stock.PriceTarget = new PricePoint(); } PriceTarget.Set(this.stock.PriceTarget); //Temp if (this.stock.Entry == null) { this.stock.Entry = new PricePoint(); } Entry.Set(this.stock.Entry); if (this.stock.StopLoss == null) { this.stock.StopLoss = new PricePoint(); } Stop.Set(this.stock.StopLoss); if (this.stock.StopLoss.NoOfShares < 0) { this.stock.StopLoss.NoOfShares *= -1; } Stop.numericUpDownNoOfShares.Value = this.stock.StopLoss.NoOfShares; checkBoxDayTrade.Checked = this.stock.DayTrade; CostBasis.Value = this.stock.CostBasis; NoOfShares.Value = this.stock.NoOfShares; Volatility.Value = this.stock.Volatility; MaxLossAmnt.Value = this.stock.MaxLoss; MaxLossPrcntg.Value = this.stock.MaxPrctgLoss; bidAskRationLabel.Text = this.stock.BidAskSpread.ToString(); checkManageTrade.Checked = this.stock.ManageTrade; UpdatePendingOrder(); if (MaxLossPrcntg.Value == 0) { MaxLossPrcntg.Value = 1.96m; } shown = true; } catch (Exception e) { } }
/// <summary> /// Gets the price of the meal for the specified price target. /// </summary> public double? GetPrice( PriceTarget target ) { if ( Prices.ContainsKey( target ) ) { return Prices[target]; } if ( Prices.Any( pair => pair.Key > target ) ) { return Prices.First( pair => pair.Key > target ).Value; } if ( Prices.Any() ) { return Prices.First().Value; } return null; }
public Task SetPriceTargetAsync(DateTime date, string ticker, PriceTarget priceTarget) { throw new NotImplementedException(); }