Пример #1
0
        private void ButtonBSrequest_Click(object sender, RoutedEventArgs e)
        {
            myLogger.Info("the Sell/Buy query button is pressed");
            string input = requestId.Text;

            if (input.Length != 0)
            {
                int             id  = Convert.ToInt32(input);
                MarketItemQuery MIQ = new MarketItemQuery();


                try
                {
                    MarketItemQuery output = MIQ.SendQueryBuySellRequest(id);
                    MessageBox.Show(output.ToStringA());
                    myLogger.Info("the request to know about the user's request:" + id + " is done successfuly");
                }

                /* catch (MarketException e)
                 * {
                 *
                 * }*/
                catch (Exception ex)
                {
                    MessageBox.Show("Error:" + ex.Message);
                    myLogger.Error("the request to know about the user's request:" + id + " is failed because the id of the request not found");
                }
            }
            else
            {
                MessageBox.Show("Full the field");
            }
            requestId.Text = "";
        }
Пример #2
0
        private void ButtonAllCancel_Click(object sender, RoutedEventArgs e)
        {
            myLogger.Info("Cancel All Request's button was pressed");

            try
            {
                MarketUserData MUD    = new MarketUserData();
                MarketUserData AllReq = MUD.SendQueryUserRequest();
                if (AllReq.requests.Count != 0)
                {
                    foreach (int id in AllReq.requests)
                    {
                        System.Threading.Thread.Sleep(300); // delay the function on 0.8 sec to prevent ban from the server
                        int                  IdSent  = Convert.ToInt32(id);
                        MarketItemQuery      MIQ     = new MarketItemQuery();
                        MarketItemQuery      output2 = MIQ.SendQueryBuySellRequest(IdSent);
                        CancelBuySellRequest CBSR    = new CancelBuySellRequest();
                        bool                 output  = CBSR.SendCancelBuySellRequest(IdSent);
                        if (output)
                        {
                            EnterHistory("Cancel", output2.commodity, output2.amount, output2.price, IdSent, false);
                        }
                    }
                }
                MessageBox.Show("All requests was delete");
            }
            catch (Exception e7)
            {
                Console.WriteLine(e7.ToString());
            }
        }
Пример #3
0
        }//collect info cancel request

        private static void CollectInfoQueryRequst(string a)
        {
            switch (a)
            {
            case "1":        //buysellquery
                int id;
                Console.WriteLine("Please enter the ID request\n");
                do
                {
                    id = Myconvert(Console.ReadLine());        //force the user to give legal id (only nums)
                }while (id == -1);

                MarketItemQuery data1 = client.SendQueryBuySellRequest(id); //call to Logic layer func
                Console.WriteLine(data1.ToString());                        //print data on a certain deal
                break;

            case "2":       //user query
                MarketUserData data2 = client.SendQueryUserRequest();
                Console.WriteLine(data2.ToString());
                break;

            case "3":       //market query
                int commodity;
                Console.WriteLine("Please enter the Commodity\n");
                do
                {
                    commodity = Myconvert(Console.ReadLine());       //force the user to give legal commidity (only nums)
                }while (commodity == -1);

                MarketCommodityOffer data3 = client.SendQueryMarketRequest(commodity);       //call to Logic layer func
                Console.WriteLine(data3.ToString());
                break;
            } //switch
            return;
        }     //collect info query
Пример #4
0
        public static void AMA_Buy(int commodity, int desiredPrice, int amount)
        {
            FLAG_isRunning = true;
            notOverLoadServer();
            MarketClientClass client = new MarketClientClass();
            AllMarketRequest  all    = client.QueryAllMarketRequest();

            counter++;


            foreach (ItemAskBid item in all.MarketInfo)
            {
                if (item.Id == commodity && item.Info.Ask <= desiredPrice)
                {   //if item is the right commodity & right price
                    MarketUserData userData = client.SendQueryUserRequest();
                    counter++;

                    List <int> l = userData.Requests;

                    if (l.Count != 0)                      //there are open requests in server

                    //if USER dont have enough money, we'll cancel his open buy requests- hoping after that he'll have enough
                    {
                        for (int i = l.Count; i >= 0 & userData.Funds < (item.Info.Ask * amount); i--)   //going from end so in delete won't change index of l
                        {
                            notOverLoadServer();

                            int reqID = l[i];        //saving the ID just for simplicity

                            MarketItemQuery request = client.SendQueryBuySellRequest(l[i]);
                            counter++;
                            if (request.Type.Equals("buy"))    //Note: check with roey
                            {
                                client.SendCancelBuySellRequest(reqID);
                                HistoryLogger.WriteHistory("Cancel," + request.Commodity + "," + request.Price + "," + request.Amount + "," + reqID);
                                counter++;
                            }
                        }
                    }

                    if (userData.Funds >= item.Info.Ask * amount)
                    {
                        int ID = client.SendBuyRequest(item.Info.Ask + 1, commodity, amount).Id;
                        HistoryLogger.WriteHistory("Buy," + commodity + "," + (item.Info.Ask + 1) + "," + amount + "," + ID);
                        counter++;
                    }
                }//bigIf
            }
            FLAG_isRunning = false;
            return;
        }//AMAbuy
Пример #5
0
        public void Test4QueryBuySellRequest()
        {
            MarketItemQuery s = new MarketItemQuery();
            int             i = 0;

            for (int j = 0; j < 4; j++)
            {
                if (buy[j] == -1)
                {
                    i = buy[j];
                }
            }
            Assert.AreEqual(null, s.SendQueryBuySellRequest(0));
        }
Пример #6
0
 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");
     }
 }
Пример #7
0
        public IMarketItemQuery SendQueryBuySellRequest(int id)
        {
            SimpleHTTPClient client = new SimpleHTTPClient();
            string           token  = SimpleCtyptoLibrary.CreateToken("user52", key);
            var item = new MarketItems.QueryBuySellRequest();

            item.type = "queryBuySell";
            item.id   = id;

            mainLog.Info("Send Query BuySell Request to the server. information: " + item.ToString());
            MarketItemQuery output = client.SendPostRequest <QueryBuySellRequest, MarketItemQuery>("http://ise172.ise.bgu.ac.il", "user52", token, item);

            mainLog.Info("return answere from the server after Send Query BuySell Request: " + output);
            return(output);
        }
Пример #8
0
        private void ButtonCancel_Click(object sender, RoutedEventArgs e)
        {
            myLogger.Info("Cancel Request button was pressed");
            string input = requestId.Text;

            if (input.Length != 0)
            {
                int id = Convert.ToInt32(input);
                if (id < 0)
                {
                    MessageBox.Show("Bad request id");
                    requestId.Text = "";
                    return;
                }
                try
                {
                    MarketItemQuery      MIQ     = new MarketItemQuery();
                    MarketItemQuery      output2 = MIQ.SendQueryBuySellRequest(id);
                    CancelBuySellRequest CBSR    = new CancelBuySellRequest();
                    bool output = CBSR.SendCancelBuySellRequest(id);
                    if (output)
                    {
                        MessageBox.Show("DONE");
                        EnterHistory("Cancel", output2.commodity, output2.amount, output2.price, id, false);
                    }
                    else
                    {
                        MessageBox.Show("Error  NOT DONE");
                    }
                }
                catch (Exception e3)
                {
                    MessageBox.Show("Error , NOT DONE");
                    myLogger.Error("the cancel of the request" + id + " failed because:id not found");
                }
            }
            else
            {
                MessageBox.Show("full the field");
            }
            requestId.Text = "";
        }
Пример #9
0
        public static void AMA_Buy(int commodity, int desiredPrice, int amount)
        {
            FLAG_isRunning = true;
            NotOverLoadServer();

            MarketClientClass client = new MarketClientClass();
            MarketUserData userData = client.SendQueryUserRequest();
            NotOverLoadServer();

            if (userData.Error != null)
            {
                FLAG_isRunning = false;
                return;
            }

            if (userData.Funds >= desiredPrice * amount)    //if we have enough money- just buy and finish running.
            {
                MarketBuySell buyreq = client.SendBuyRequest(desiredPrice, commodity, amount);
                NotOverLoadServer();

                if (buyreq.Error == null)          //the buy req is successfuly passed to the server
                    HistoryLogger.WriteHistory(buyreq.Id, "Buy", commodity, desiredPrice, amount);
                FLAG_isRunning = false;
                return;
            }

            //if USER dont have enough money, we'll cancel his open buy requests- hoping after that he'll have enough
            List<int> l = userData.Requests;

            if (l.Count == 0)               //there are NO open requests in server
            {
                FLAG_isRunning = false;
                return;
            }

            for (int i = l.Count - 1; i >= 0 && userData.Funds < (desiredPrice * amount); i--)   //going from end so in delete won't change index of l
            {
                int reqID = l[i];    //saving the ID just for simplicity

                MarketItemQuery request = client.SendQueryBuySellRequest(reqID);
                NotOverLoadServer();

                if (request.Error != null)
                {
                    FLAG_isRunning = false;
                    return;
                }

                //wish to cancel only buy requests. only this kind of canceling request give back money
                //func SendCancelBuySellRequest returns bool - of the action passed successfuly
                if (request.Type.Equals("buy") && client.SendCancelBuySellRequest(reqID))
                    HistoryLogger.WriteHistory(reqID, "Cancel", request.Commodity, request.Price, request.Amount);

                NotOverLoadServer();
            }

            userData = client.SendQueryUserRequest();   //refresh data
            NotOverLoadServer();

            if (userData.Error != null)
            {
                FLAG_isRunning = false;
                return;
            }

            if (userData.Funds >= desiredPrice * amount)    //if NOW we have enough money-  buy 
            {
                MarketBuySell buyreq = client.SendBuyRequest(desiredPrice, commodity, amount);
                NotOverLoadServer();

                if (buyreq.Error == null)          //the buy req is successfuly passed to the server
                    HistoryLogger.WriteHistory(buyreq.Id, "Buy", commodity, desiredPrice, amount);
            }
            FLAG_isRunning = false;
            return;
        }//AMAbuy