コード例 #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;
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: sagiede/ISE_2017
        }//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
        }