Ejemplo n.º 1
0
        private void checkPrice(Object source, ElapsedEventArgs e)
        {
            MarketClientConnection pc    = new MarketClientConnection();
            MarketCommodityOffer   query = (MarketCommodityOffer)pc.SendQueryMarketRequest(commodity);

            if (buyRequest)            //buy when price of ask of commidity id is lower then extremePrice
            {
                int stockPrice = query.ask;
                if (stockPrice <= extremePrice)
                {
                    pc.SendBuyRequest(stockPrice, commodity, amount);
                    aTimer.Enabled = false;
                    keepingProcces = false;
                    return;
                    // comment
                }
            }
            else
            {
                int stockOffer = query.bid;
                if (stockOffer >= extremePrice)
                {
                    pc.SendSellRequest(stockOffer, commodity, amount);
                    aTimer.Enabled = false;
                    keepingProcces = false;
                    return;
                }
            }
        }
Ejemplo n.º 2
0
        //if the client whant to buy commodity
        private static void buyingProcces(MarketClientConnection mc)
        {
            Console.WriteLine("Which commodity would yo like to buy?");

            int commodity = checkInputValid();

            if (commodity == -1)
            {
                return;
            }
            Console.WriteLine("How many?");
            int amount = checkInputValid();

            if (amount == -1)
            {
                return;
            }
            Console.WriteLine("Enter your price");
            int price = checkInputValid();

            if (price == -1)
            {
                return;
            }
            int response = mc.SendBuyRequest(price, commodity, amount);

            if (response != -1)
            {
                Console.WriteLine(response);
            }
        }
Ejemplo n.º 3
0
        //if the client want to cancel commodity
        private static void cancelingProcces(MarketClientConnection mc)
        {
            Console.WriteLine("which transaction would you like to cancel?");
            int idNum = checkInputValid();

            if (idNum == -1)
            {
                return;
            }
            bool ans = (mc.SendCancelBuySellRequest(idNum));

            if (ans)
            {
                Console.WriteLine("transcation canceled succecfully");
            }
        }
Ejemplo n.º 4
0
        }//Main

        private static void runTrading(MarketClientConnection mc)
        {
            while (true)
            {
                Console.WriteLine("---------------------------------------------------------------\nWelcome to Algo-Trading application. to go back to main menu, you can press -1 at any point");
                Console.WriteLine("What do you wish to do?");
                Console.WriteLine("1- Buy\n2- Sell\n3- Cancel\n4- Queries\n5- delete all open requests");
                int command = checkInputValid(); // the first choose of the client

                if (command == -1)
                {
                }
                //want to buy
                else if (command == 1)
                {
                    buyingProcces(mc);
                }
                // want to sell
                else if (command == 2)
                {
                    sellingProcces(mc);
                }
                // want to cancel
                else if (command == 3)
                {
                    cancelingProcces(mc);
                }
                // want to cancel all the request
                else if (command == 5)
                {
                    if (mc.cancelAllRequests() == true)
                    {
                        Console.WriteLine("all your asks are canceled");
                    }
                }
                else if (command == 4)
                {
                    Console.WriteLine("Which query would yo like to send?");
                    Console.WriteLine("1- Buy/Sell status\n2- User status\n3- Market Status");
                    command = checkInputValid();
                    // want go back
                    if (command == -1)
                    {
                    }
                    //Buy/Sell status
                    else if (command == 1)
                    {
                        Console.WriteLine("please enter the transaction ID");
                        int id = checkInputValid();
                        if (id != -1)
                        {
                            Console.WriteLine(mc.SendQueryBuySellRequest(id));
                        }
                        //user status
                    }
                    else if (command == 2)
                    {
                        Console.WriteLine(mc.SendQueryUserRequest());
                    }
                    //Market Status
                    else if (command == 3)
                    {
                        Console.WriteLine("Please enter the stock number you wish to ask about");
                        int commodity = checkInputValid();
                        if (commodity != -1)
                        {
                            Console.WriteLine(mc.SendQueryMarketRequest(commodity));
                        }
                        else
                        {
                            Console.WriteLine("You have entered invaild number, please follow the instructions");
                        }
                    }
                }
            }//while
        }