private void PopulateChart() { global::Program.MarketClient marketClient = new global::Program.MarketClient(); Commodity[] commodities = marketClient.SendQueryAllMarketRequest(); this.CommodityRateCollection = new SeriesCollection(); ChartValues <double> askPrices = new ChartValues <double>(); ChartValues <double> bidPrices = new ChartValues <double>(); foreach (Commodity commodity in commodities) { askPrices.Add(commodity.info.ask); bidPrices.Add(commodity.info.bid); } ColumnSeries askColumnSeries = new ColumnSeries(); ColumnSeries bidColumnSeries = new ColumnSeries(); askColumnSeries.Title = "Ask"; bidColumnSeries.Title = "Bid"; askColumnSeries.Values = askPrices; bidColumnSeries.Values = bidPrices; askColumnSeries.DataLabels = true; bidColumnSeries.DataLabels = true; askColumnSeries.LabelPoint = point => point.Y.ToString(); bidColumnSeries.LabelPoint = point => point.Y.ToString(); CommodityRateCollection.Add(askColumnSeries); CommodityRateCollection.Add(bidColumnSeries); CommodityRates = d => d.ToString("N"); DataContext = this; }
private void PopulateGrid() { try { global::Program.MarketClient marketClient = new global::Program.MarketClient(); QueryUserRequest[] resp = marketClient.SendQueryUserRequestsRequest(); this.dataGridData.Items.Clear(); foreach (var curr in resp) { this.dataGridData.Items.Add(new GridItem() { id = curr.id, type = curr.request.type, price = curr.request.price, amount = curr.request.amount, commodity = curr.request.commodity }); } this.labelHeader.Content = "Active requests as of " + DateTime.Now.ToLongTimeString(); this.dataGridData.Visibility = Visibility.Visible; } catch { this.labelHeader.Content = "Could not fetch data. Refreshed: " + DateTime.Now.ToLongTimeString(); this.dataGridData.Visibility = Visibility.Hidden; } finally { } }
private void PopulateGrid() { try { global::Program.MarketClient marketClient = new global::Program.MarketClient(); Commodity[] commodities = marketClient.SendQueryAllMarketRequest(); this.dataGridData.Items.Clear(); foreach (var comm in commodities) { this.dataGridData.Items.Add(new GridItem() { id = comm.id, ask = comm.info.ask, bid = comm.info.bid }); } this.labelHeader.Content = "Market status as of " + DateTime.Now.ToLongTimeString(); this.dataGridData.Visibility = Visibility.Visible; } catch { this.labelHeader.Content = "Could not fetch data. Refreshed: " + DateTime.Now.ToLongTimeString(); this.dataGridData.Visibility = Visibility.Hidden; } }
private void CancelRequest(object sender, RoutedEventArgs e) { try { if (sender != null) { DataGridRow row = GetParent <DataGridRow>((Button)sender); DataGridCell RowColumn = this.dataGridData.Columns[1].GetCellContent(row)?.Parent as DataGridCell; string CellValue = ((TextBlock)RowColumn.Content).Text; int id = Convert.ToInt32(CellValue); // cancel request #id global::Program.MarketClient marketClient = new global::Program.MarketClient(); marketClient.SendCancelBuySellRequest(id); // MessageBoxResult popup = MessageBox.Show("Successfuly cancelled request #" + id, "Success"); } } catch { // MessageBoxResult popup = MessageBox.Show("Could not cancel the request", "Error"); } finally { PopulateGrid(); } }
private void buttonSearch_Click(object sender, RoutedEventArgs e) { try { global::Program.MarketClient marketClient = new global::Program.MarketClient(); int input = Convert.ToInt32(this.textBoxInput.Text); switch (((ComboBoxItem)this.comboBoxType.SelectedItem).Content.ToString()) { case "Buy Request": case "Sell Request": BuySell(input); break; case "Commodity": Commodity(input); break; default: MessageBoxResult popup = MessageBox.Show("Please make sure your form is valid", "Confirmation"); return; } } catch { MessageBoxResult popup = MessageBox.Show("Please enter a valid number", "Confirmation"); this.textBoxInput.Text = ""; } }
private void PresentData() { global::Program.MarketClient marketClient = new global::Program.MarketClient(); MarketUserData marketUserData = (MarketUserData)marketClient.SendQueryUserRequest(); try { // Set all to visible this.DataGridCommodities.Visibility = Visibility.Visible; this.DataGridRequests.Visibility = Visibility.Visible; this.LabelCommodities.Visibility = Visibility.Visible; this.LabelRequests.Visibility = Visibility.Visible; this.LabelFunds.Visibility = Visibility.Visible; // Set the commodities section this.DataGridCommodities.ItemsSource = marketUserData.commodities; if (DataGridCommodities.Columns.Count > 1) { this.DataGridCommodities.Columns[0].Header = "Commodity"; this.DataGridCommodities.Columns[1].Header = "Quantity"; } // Set the requests section this.LabelRequests.Content = "Requests"; if (marketUserData.requests.Length > 0) { this.DataGridRequests.Visibility = Visibility.Visible; this.DataGridRequests.ItemsSource = marketUserData.requests .Select((x, index) => new { Number = index + 1, Request = x }) .ToList(); } else { this.DataGridRequests.Visibility = Visibility.Hidden; this.LabelRequests.Content += "\n\n No requests."; } this.LabelHeader.Content = "Refreshed: " + DateTime.Now.ToLongTimeString(); // Set the funds section this.LabelFunds.Content = "Funds: " + marketUserData.funds + " $"; } catch { // Set all to hidden this.DataGridCommodities.Visibility = Visibility.Hidden; this.DataGridRequests.Visibility = Visibility.Hidden; this.LabelCommodities.Visibility = Visibility.Hidden; this.LabelRequests.Visibility = Visibility.Hidden; this.LabelFunds.Visibility = Visibility.Hidden; this.LabelHeader.Content = "No connection to server. Refreshed: " + DateTime.Now.ToLongTimeString(); } }
private void Commodity(int input) { global::Program.MarketClient marketClient = new global::Program.MarketClient(); try { MarketCommodityOffer respCommodityOffer = (MarketCommodityOffer)marketClient.SendQueryMarketRequest(input); this.textBoxOutput.Text = respCommodityOffer.ToString(); this.textBoxOutput.Visibility = Visibility.Visible; } catch { MessageBoxResult popup = MessageBox.Show("Could not fetch info about commodity #" + input, "Confirmation"); } }
private void BuySell(int input) { global::Program.MarketClient marketClient = new global::Program.MarketClient(); try { MarketItemQuery resp = (MarketItemQuery)marketClient.SendQueryBuySellRequest(input); this.textBoxOutput.Text = resp.ToString(); this.textBoxOutput.Visibility = Visibility.Visible; } catch { MessageBoxResult popup = MessageBox.Show("Could not fetch info about trade #" + input, "Confirmation"); } }
private void buttonBuy_Click(object sender, RoutedEventArgs e) { int commodityId; int quantity; int price; // Harvest data and make sure it's legal try { commodityId = this.comboBoxCommodity.SelectedIndex; if (commodityId == -1) { MessageBoxResult popup = MessageBox.Show("Please select the commodity ID", "Confirmation"); return; } } catch { MessageBoxResult popup = MessageBox.Show("Please select the commodity ID", "Confirmation"); return; } try { quantity = Convert.ToInt32(this.textBoxQuantity.Text); if (quantity <= 0) { MessageBoxResult popup = MessageBox.Show("Please enter a positive quantity number", "Confirmation"); return; } } catch { MessageBoxResult popup = MessageBox.Show("Please enter a valid quantity number", "Confirmation"); return; } try { price = Convert.ToInt32(this.textBoxPrice.Text); if (price <= 0) { MessageBoxResult popup = MessageBox.Show("Please enter a positive price number", "Confirmation"); return; } } catch { MessageBoxResult popup = MessageBox.Show("Please enter a valid price number", "Confirmation"); return; } // If we got here, all the data is okay and we can send the request global::Program.MarketClient marketClient = new global::Program.MarketClient(); int id = -1; if (this.isBuy) { id = marketClient.SendBuyRequest(price, commodityId, quantity); if (id != -1) { Program.Logger.InfoLog("The user performed a buy request of " + quantity + " from commodity " + commodityId + " for a price of " + price + " each"); } } else { id = marketClient.SendSellRequest(price, commodityId, quantity); if (id != -1) { Program.Logger.InfoLog("The user performed a sell request of " + quantity + " from commodity " + commodityId + " for a price of " + price + " each"); } } if (id == -1) { StackFrame sf = new StackFrame(1); Program.Logger.ErrorLog(sf.GetMethod(), sf.GetFileLineNumber(), "The user performed an illegal buy/sell request"); MessageBoxResult popup = MessageBox.Show("An error occured while processing the request", "Confirmation"); } else { MessageBoxResult popup = MessageBox.Show("Request sent! ID: " + id, "Confirmation"); } this.comboBoxCommodity.SelectedIndex = -1; this.textBoxQuantity.Text = ""; this.textBoxPrice.Text = ""; }
private void buttonSell_Click(object sender, RoutedEventArgs e) { int commodityId; int quantity; int price; // Harvest data and make sure it's legal try { commodityId = this.comboBoxCommodity.SelectedIndex; if (commodityId == -1) { MessageBoxResult popup = MessageBox.Show("Please select the commodity ID", "Confirmation"); return; } } catch { MessageBoxResult popup = MessageBox.Show("Please select the commodity ID", "Confirmation"); return; } try { quantity = Convert.ToInt32(this.textBoxQuantity.Text); if (quantity <= 0) { MessageBoxResult popup = MessageBox.Show("Please enter a positive quantity number", "Confirmation"); return; } } catch { MessageBoxResult popup = MessageBox.Show("Please enter a valid quantity number", "Confirmation"); return; } try { price = Convert.ToInt32(this.textBoxPrice.Text); if (price <= 0) { MessageBoxResult popup = MessageBox.Show("Please enter a positive price number", "Confirmation"); return; } } catch { MessageBoxResult popup = MessageBox.Show("Please enter a valid price number", "Confirmation"); return; } // If we got here, all the data is okay and we can send the request global::Program.MarketClient marketClient = new global::Program.MarketClient(); int id = marketClient.SendSellRequest(price, commodityId, quantity); if (id == -1) { MessageBoxResult popup = MessageBox.Show("An error occured while processing the request", "Confirmation"); } else { MessageBoxResult popup = MessageBox.Show("Request sent! ID: " + id, "Confirmation"); } this.comboBoxCommodity.SelectedIndex = -1; this.textBoxQuantity.Text = ""; this.textBoxPrice.Text = ""; }