private static string PopulateDetailStockPring(IntraDayQuotes latestPrice) { var str = new StringBuilder(); str.Append($"<p>Time : {DateTime.Parse(latestPrice.Date).ToString("HH:mm:ss")}</p>"); str.Append($"<p>Price : {latestPrice.Price}</p>"); str.Append($"<p>Volume : {latestPrice.Volume}</p>"); str.Append($"<p>Side : {latestPrice.Side}</p>"); str.Append($"<p>TotalVolume : {latestPrice.TotalVolume}</p>"); return(str.ToString()); }
private void timer1_Tick(object sender, EventArgs e) { var cache = new JsonSerializer(); var fireAntClient = new FireAntClient(cache, new ErrorLogger()); string symbol = txtSymbol.Text; var intradayItems = fireAntClient.GetIntraday(symbol); intradayItems.Reverse(); var pricing = intradayItems.Select(current => new { Date = DateTime.Parse(current.Date).ToString("HH:mm:ss"), Price = current.Price, Volumne = current.Volume, Side = GetSideText(current.Side) }).ToList(); dataGridView1.DataSource = pricing; if (!pricing.Any()) { return; } IntraDayQuotes latestPrice = intradayItems.First(); var currentPrice = latestPrice.Price; txtLogging.AppendText($"{DateTime.Now.ToString()} - Total Volume : {latestPrice.TotalVolume}" + Environment.NewLine); var jsonBody = PopulateDetailStockPring(latestPrice); // check price to BUY if (currentPrice <= float.Parse(txtPriceToBuy.Text)) { string subject = $"BUY {symbol} - {currentPrice}"; if (chkSendNotification.Checked) { SendNotification(subject, $"BUY {symbol} for NOW. <br/>" + jsonBody); } txtLogging.AppendText($"{DateTime.Now.ToString()} - {subject}" + Environment.NewLine); DisableTimer(); } // check price to SELL if (currentPrice >= float.Parse(txtPriceToSell.Text)) { string subject = $"SELL {symbol} - {currentPrice}"; if (chkSendNotification.Checked) { SendNotification($"SELL {symbol} - {currentPrice}", $"SELL {symbol} for NOW. <br/>" + jsonBody); } txtLogging.AppendText($"{DateTime.Now.ToString()} - {subject}" + Environment.NewLine); DisableTimer(); } }