Beispiel #1
0
        public void TestFalsePrice()
        {
            MarketClientClass client = new MarketClientClass();

            MarketBuySell sellreq1 = client.SendSellRequest(2000000, 2, 1);  //no such price : 2,000,000

            Assert.IsNotNull(sellreq1.Error);

            MarketBuySell sellreq2 = client.SendSellRequest(-25, 5, 3);   //no such price : -25

            Assert.IsNotNull(sellreq2.Error);

            //Errors expected (not null)
        }
Beispiel #2
0
        }//AMAbuy

        public static void AMA_Sell(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;
            }

            foreach (int cmdty in userData.Commodities.Keys)    //passing on all commodities
            {
                if (cmdty == commodity && userData.Commodities[cmdty] > 0)           //check if we own that commodity
                {
                    //if item is the right commodity & we own it
                    if (amount > userData.Commodities[cmdty] || amount == -1)                //we cant sell more than we have OR -1 is our sign to sell ALL
                        amount = userData.Commodities[cmdty];

                    MarketBuySell sellreq = client.SendSellRequest(desiredPrice, commodity, amount);
                    NotOverLoadServer();

                    if (sellreq.Error == null)        //the sell req is successfuly passed to the server
                        HistoryLogger.WriteHistory(sellreq.Id, "Sell", commodity, desiredPrice, amount);
                }
            }
            FLAG_isRunning = false;
            return;
        }//AMAsell
Beispiel #3
0
        //this function activate - buy/sell request. it collect info from user - send it to Logic layer and prints an answer
        private static void CollectingInfoBUYSELL(string a)
        {
            //write more legallity checks
            int Commodity, Amount, Price;

            do
            {
                Console.WriteLine("Please enter Commodity");
                Commodity = Myconvert(Console.ReadLine());
                Console.WriteLine("Please enter Amount");
                Amount = Myconvert(Console.ReadLine());
                Console.WriteLine("Please enter Price");
                Price = Myconvert(Console.ReadLine());
            } while (Commodity == -1 | Amount == -1 | Price == -1);

            MarketBuySell IDbuysell;

            if (a.Equals("1"))                                               //'1' means buy
            {
                IDbuysell = client.SendBuyRequest(Price, Commodity, Amount); //call to Logic layer func
                Console.WriteLine(IDbuysell.ToString());
            }
            else                                                              //means sell
            {
                IDbuysell = client.SendSellRequest(Price, Commodity, Amount); //call to Logic layer func
                Console.WriteLine(IDbuysell.ToString());
            }

            return;
        }//collect info buy-sell request
Beispiel #4
0
        public void TestFalseAmount()
        {
            MarketClientClass client = new MarketClientClass();

            MarketBuySell sellreq1 = client.SendSellRequest(1, 2, -8);   //no such amount : -8

            Assert.IsNotNull(sellreq1.Error);


            MarketBuySell sellreq2 = client.SendSellRequest(4, 4, -3);   //no such amount : -3

            Assert.IsNotNull(sellreq2.Error);


            MarketBuySell sellreq3 = client.SendSellRequest(2, 7, -100);   //no such amount : -100

            Assert.IsNotNull(sellreq3.Error);

            //Errors expected (not null)
        }
Beispiel #5
0
        public void TestFalseCommodity()
        {
            MarketClientClass client = new MarketClientClass();

            MarketBuySell buyreq1 = client.SendBuyRequest(5, -2, 3);   //no such commodies : -2

            Assert.IsNotNull(buyreq1.Error);

            MarketBuySell buyreq2 = client.SendBuyRequest(1, 10, 3);    //no such commodies : 10

            Assert.IsNotNull(buyreq2.Error);

            MarketBuySell sellreq3 = client.SendSellRequest(7, 24, 3);   //no such commodies : 24

            Assert.IsNotNull(sellreq3.Error);

            //Errors expected (not null)
        }
Beispiel #6
0
        }//AMAbuy

        public static void AMA_Sell(int commodity, int desiredPrice, int amount)
        {
            FLAG_isRunning = true;
            notOverLoadServer();


            MarketClientClass client = new MarketClientClass();
            AllMarketRequest  all    = client.QueryAllMarketRequest();

            counter++;

            MarketUserData userData = client.SendQueryUserRequest();

            counter++;

            foreach (int cmdty in userData.Commodities.Keys)      //check if we own that commodity
            {
                if (cmdty == commodity & userData.Commodities[cmdty] > 0)
                {
                    //passing on commodities list, until arriving the wished one
                    foreach (ItemAskBid item in all.MarketInfo)
                    {
                        if (item.Id == commodity && item.Info.Bid >= desiredPrice)
                        {                                                            //if item is the right commodity & right price
                            if (amount > userData.Commodities[cmdty] | amount == -1) //we cant sell more than we have OR -1 is our sign to sell ALL
                            {
                                amount = userData.Commodities[cmdty];
                            }

                            //Note: ask roey about error
                            int ID = client.SendSellRequest(item.Info.Bid - 1, commodity, amount).Id;
                            HistoryLogger.WriteHistory("Sell," + commodity + "," + (item.Info.Bid - 1) + "," + amount + "," + ID);
                            counter++;
                        }
                    }
                }
            }

            FLAG_isRunning = false;
            return;
        }//AMAsell