示例#1
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
示例#2
0
        public void TestAMAsell()
        {
            bool   e            = false;
            Random rnd          = new Random();
            int    rndCommodity = rnd.Next(0, 10);

            int EXPECTEDcommAmount = 0;
            int ACTUALcommAmount   = 0;


            MarketClientClass    client        = new MarketClientClass();
            MarketUserData       userData      = client.SendQueryUserRequest();
            MarketCommodityOffer commodityInfo = client.SendQueryMarketRequest(rndCommodity);

            if (userData.Error != null | commodityInfo.Error != null)   //is NOT successfuly passed to the server
            {
                return;
            }


            foreach (int cmdty in userData.Commodities.Keys)        //passing on all commodities  .
            {
                if (cmdty == rndCommodity)
                {
                    EXPECTEDcommAmount = userData.Commodities[cmdty];      //checking how many we own from rndCommodity
                }
            }


            //we are selling 1
            AMA.AMA_Sell(commodityInfo.Bid, rndCommodity, 1);

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

            foreach (int cmdty in userData.Commodities.Keys) //passing on all commodities
            {
                if (cmdty == rndCommodity)
                {
                    ACTUALcommAmount = userData.Commodities[cmdty];
                }
            }

            if (EXPECTEDcommAmount == ACTUALcommAmount)
            {
                e = !e;
            }



            if (e | EXPECTEDcommAmount == 0)
            {
                Assert.AreEqual <int>(EXPECTEDcommAmount, ACTUALcommAmount);
            }

            else
            {
                Assert.AreNotEqual <int>(EXPECTEDcommAmount, ACTUALcommAmount);
            }
        }
示例#3
0
        private static void OnAMAEvent(object sender, EventArgs e)
        {
            if (!FLAG_isRunning)                     //for not creating lot of AMA functions running in parallel
            {

                Trace.WriteLine("AAAAAAMMMMMMAAAAAA");
                
                using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["historyConnectionString"].ConnectionString))
                {
                    Random rnd = new Random();
                    int avgPrice=0;
                    int rndCommodity = rnd.Next(1, 10);
                    int amountToBuy = rnd.Next(4, 10);
                    int amountToSell = rnd.Next(-1, 8);           //-1 means all


                    if (amountToSell == 0)
                        amountToSell = -1;

                    myConnection.Open();
                    SqlCommand myCommand = new SqlCommand("select Avg(price) AS AveragePrice from items where commodity='" + rndCommodity + "' and timestamp>= DATEADD(mi, -30, GETUTCDATE())", myConnection);
                    SqlDataReader myDataReader = myCommand.ExecuteReader();
                    if (myDataReader.HasRows)

                    {
                        myDataReader.Read();
                        NotOverLoadServer();
                        try
                        {
                            Trace.WriteLine(myDataReader[0].ToString());
                            Trace.WriteLine(Double.Parse(myDataReader[0].ToString()));
                            Double avgPriceDouble = Double.Parse(myDataReader[0].ToString());
                            avgPrice = Convert.ToInt32(avgPriceDouble);
                        }
                        catch
                        {
                            return;
                        }
                        //want to get INFO for the commodity ASK-BID
                        MarketClientClass client = new MarketClientClass();
                        MarketCommodityOffer commodityInfo = client.SendQueryMarketRequest(rndCommodity);
                        NotOverLoadServer();

                        if (commodityInfo.Error != null)
                            return;

                        //choose alternately buy or sell. and choose randomly commodity
                        if (FLAG_buyOrSell)
                        {    //ama buy
                            if (avgPrice - 15 < 0)
                            {
                                avgPrice = rnd.Next(4, 9);
                                AMA_Buy(rndCommodity, avgPrice, amountToBuy);
                            }
                            else
                            {
                                avgPrice -= 15;
                                AMA_Buy(rndCommodity, avgPrice, amountToBuy);
                            }
                        }
                        else
                        {     //ama sell  
                            avgPrice += 4;
                            AMA_Sell(rndCommodity, avgPrice , amountToSell);
                        }
                        FLAG_buyOrSell = !FLAG_buyOrSell;
                    }
                }
            }
        }