private void ButtonAllCoffer_Click(object sender, RoutedEventArgs e)
        {
            myLogger.Info("All Commodities Offers button was pressed");
            AllMarketCommodityOffer MACO   = new AllMarketCommodityOffer();
            List <ComInfo>          output = MACO.SendQueryAllMarketRequest();

            MessageBox.Show(MACO.ToStringA());
            myLogger.Info("the request to know about all commodities offers is done");
        }
Exemple #2
0
        private void onTimedEvent(Object source, ElapsedEventArgs e)
        {
            sql.close();
            sql.connect();
            MarketUserData          MYUSER  = new MarketUserData();
            MarketUserData          myUser  = MYUSER.SendQueryUserRequest();
            AllMarketCommodityOffer MACO    = new AllMarketCommodityOffer();
            List <ComInfo>          cominfo = MACO.SendQueryAllMarketRequest();
            SqlDataReader           rdr     = sql.sendCommand("SELECT top 100 commodity, AVG(price) as 'average' FROM (SELECT commodity, price, timestamp FROM items where buyer = 20) commodity group by commodity order by commodity");
            int    counterS = 0;
            string Scom     = "";

            while (counterS < 10 && rdr.Read())
            {
                Scom = "" + rdr["commodity"];
                if (Convert.ToInt32(Scom) > 3 && myUser.commodities[Scom] > 1)
                {
                    SellRequest SR        = new SellRequest();
                    int         price     = Math.Max(Convert.ToInt32(rdr["average"]) + Convert.ToInt32(rdr["average"]) * 20 / 100, cominfo[Convert.ToInt32(rdr["commodity"])].info.bid);
                    int         amount    = Convert.ToInt32(myUser.commodities[Scom] / 20) + 1;
                    int         commodity = Convert.ToInt32(rdr["commodity"]);
                    int         response  = SR.SendSellRequest(price, commodity, amount);
                    if (response != -1)
                    {
                        DateTime    date  = DateTime.Now;
                        string      sdate = date.ToString();
                        HistoryItem h     = new HistoryItem("Sell", response, Convert.ToInt32(myUser.commodities[Scom] / 20) + 1, price, Convert.ToInt32(rdr["commodity"]), true, sdate);
                        // MessageBox.Show("SellDone");//for test
                        App.Current.Dispatcher.Invoke((Action) delegate
                        {
                            mainWin.History.Insert(0, h);
                        });
                        string path = "..\\History.txt";
                        using (StreamWriter wr = File.AppendText(path))
                        {
                            wr.WriteLine("Request");
                            wr.WriteLine("sell");
                            wr.WriteLine(response);
                            wr.WriteLine(Convert.ToInt32(myUser.commodities[Scom] / 20) + 1);
                            wr.WriteLine(price);
                            wr.WriteLine(Convert.ToInt32(rdr["commodity"]));
                            wr.WriteLine("true");
                            wr.WriteLine(sdate.ToString());
                        }
                    }
                    counterS++;
                }
            }
            rdr.Close();

            SqlDataReader rdr2     = sql.sendCommand("SELECT top 100 commodity, AVG(price) as 'average' FROM (SELECT commodity, price, timestamp FROM items where seller = 20) commodity group by commodity order by commodity");
            int           counterB = 0;

            while (counterB < 10 && rdr2.Read())
            {
                Scom = "" + rdr2["commodity"];
                if (Convert.ToInt32(Scom) > 3 && myUser.funds > 5000)
                {
                    BuyRequest SB       = new BuyRequest();
                    int        price    = Math.Min(Convert.ToInt32(rdr2["average"]) - Convert.ToInt32(rdr2["average"]) * 20 / 100, cominfo[Convert.ToInt32(rdr2["commodity"])].info.ask);
                    int        response = SB.sendBuyRequest(price, Convert.ToInt32(rdr2["commodity"]), Convert.ToInt32(myUser.commodities[Scom] / 20) + 1);
                    if (response != -1)
                    {
                        DateTime    date  = DateTime.Now;
                        string      sdate = date.ToString();
                        HistoryItem h     = new HistoryItem("Buy", response, Convert.ToInt32(myUser.commodities[Scom] / 20) + 1, price, Convert.ToInt32(rdr2["commodity"]), true, sdate);
                        //MessageBox.Show("BuyDone");//for test
                        App.Current.Dispatcher.Invoke((Action) delegate
                        {
                            mainWin.History.Insert(0, h);
                        });
                        string path = "..\\History.txt";
                        using (StreamWriter wr = File.AppendText(path))
                        {
                            wr.WriteLine("Request");
                            wr.WriteLine("buy");
                            wr.WriteLine(response);
                            wr.WriteLine(Convert.ToInt32(myUser.commodities[Scom] / 10) + 1);
                            wr.WriteLine(price);
                            wr.WriteLine(Convert.ToInt32(rdr2["commodity"]));
                            wr.WriteLine("true");
                            wr.WriteLine(sdate.ToString());
                        }
                    }
                }
                counterB++;
            }
            rdr2.Close();
            sql.close();
        }
Exemple #3
0
        private void ShowColumnChart()
        {
            SqlData sql = new SqlData();

            sql.connect();
            //Graph of avarage of each commodity
            double[] valueAv = sql.averangeOnly();
            List <KeyValuePair <string, double> > Avg = new List <KeyValuePair <string, double> >();

            Avg.Add(new KeyValuePair <string, double>("C-0", valueAv[0]));
            Avg.Add(new KeyValuePair <string, double>("C-1", valueAv[1]));
            Avg.Add(new KeyValuePair <string, double>("C-2", valueAv[2]));
            Avg.Add(new KeyValuePair <string, double>("C-3", valueAv[3]));
            Avg.Add(new KeyValuePair <string, double>("C-4", valueAv[4]));
            Avg.Add(new KeyValuePair <string, double>("C-5", valueAv[5]));
            Avg.Add(new KeyValuePair <string, double>("C-6", valueAv[6]));
            Avg.Add(new KeyValuePair <string, double>("C-7", valueAv[7]));
            Avg.Add(new KeyValuePair <string, double>("C-8", valueAv[8]));
            Avg.Add(new KeyValuePair <string, double>("C-9", valueAv[9]));

            //Graph of Hot commodties
            double[] valueHo = sql.hotCommodities();
            List <KeyValuePair <string, double> > HotCo = new List <KeyValuePair <string, double> >();

            HotCo.Add(new KeyValuePair <string, double>("C-0", valueHo[0]));
            HotCo.Add(new KeyValuePair <string, double>("C-1", valueHo[1]));
            HotCo.Add(new KeyValuePair <string, double>("C-2", valueHo[2]));
            HotCo.Add(new KeyValuePair <string, double>("C-3", valueHo[3]));
            HotCo.Add(new KeyValuePair <string, double>("C-4", valueHo[4]));
            HotCo.Add(new KeyValuePair <string, double>("C-5", valueHo[5]));
            HotCo.Add(new KeyValuePair <string, double>("C-6", valueHo[6]));
            HotCo.Add(new KeyValuePair <string, double>("C-7", valueHo[7]));
            HotCo.Add(new KeyValuePair <string, double>("C-8", valueHo[8]));
            HotCo.Add(new KeyValuePair <string, double>("C-9", valueHo[9]));

            //Graph of each commodity with her ask price and bid price
            AllMarketCommodityOffer MACO   = new AllMarketCommodityOffer();
            List <ComInfo>          AskBid = MACO.SendQueryAllMarketRequest();
            List <KeyValuePair <string, double> > bidColumn = new List <KeyValuePair <string, double> >();
            List <KeyValuePair <string, double> > askColumn = new List <KeyValuePair <string, double> >();

            for (int i = 0; i < 10; i++)
            {
                bidColumn.Add(new KeyValuePair <string, double>("C-" + AskBid[i].Id + " ", AskBid[i].info.bid));
                askColumn.Add(new KeyValuePair <string, double>("C-" + AskBid[i].Id + " ", AskBid[i].info.ask));
            }
            this.AskBidGraph = new List <List <KeyValuePair <string, double> > >();
            AskBidGraph.Add(bidColumn);
            AskBidGraph.Add(askColumn);

            //Graph of each commodity with her amount
            MarketUserData MUD       = new MarketUserData();
            MarketUserData ComAmount = MUD.SendQueryUserRequest();
            List <KeyValuePair <string, double> > COfUser = new List <KeyValuePair <string, double> >();

            COfUser.Add(new KeyValuePair <string, double>("C-0", ComAmount.commodities["0"]));
            COfUser.Add(new KeyValuePair <string, double>("C-1", ComAmount.commodities["1"]));
            COfUser.Add(new KeyValuePair <string, double>("C-2", ComAmount.commodities["2"]));
            COfUser.Add(new KeyValuePair <string, double>("C-3", ComAmount.commodities["3"]));
            COfUser.Add(new KeyValuePair <string, double>("C-4", ComAmount.commodities["4"]));
            COfUser.Add(new KeyValuePair <string, double>("C-5", ComAmount.commodities["5"]));
            COfUser.Add(new KeyValuePair <string, double>("C-6", ComAmount.commodities["6"]));
            COfUser.Add(new KeyValuePair <string, double>("C-7", ComAmount.commodities["7"]));
            COfUser.Add(new KeyValuePair <string, double>("C-8", ComAmount.commodities["8"]));
            COfUser.Add(new KeyValuePair <string, double>("C-9", ComAmount.commodities["9"]));

            //Setting data for column chart
            columnChartG.DataContext = AskBidGraph;

            //Setting data for pie chart
            columnChartA.DataContext = Avg;

            //Setting data for pie chart
            Hot.DataContext = HotCo;

            //Setting data for column chart
            Cou.DataContext = COfUser;
        }