public async Task Sell_SI_Stocks(string sym, int quantity, decimal price, string email)
        {
            ISellStock sellStock = new SellStock();

            var currentUser = await GetCurrentUser(email);

            sellStock.SellStocks_http(sym, quantity, price, currentUser.secret_accesstoken);
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            IBroker  broker          = new Broker();
            ICommand buyStockCommand = new BuyStock(broker);

            buyStockCommand.Execute();
            ICommand sellStockCommand = new SellStock(broker);

            sellStockCommand.Execute();
        }
Exemplo n.º 3
0
        public static void CommandExample()
        {
            Stock     abcStock       = new Stock();
            BuyStock  buyStockOrder  = new BuyStock(abcStock);
            SellStock sellStockOrder = new SellStock(abcStock);
            Broker    broker         = new Broker();

            broker.TakeOrder(buyStockOrder);
            broker.TakeOrder(sellStockOrder);
            broker.PlaceOrders();
        }
Exemplo n.º 4
0
        private void Command()
        {
            StockManager    stockManager    = new StockManager("iPhone", 200);
            BuyStock        buyStock        = new BuyStock(stockManager);
            SellStock       sellStock       = new SellStock(stockManager);
            StockController stockController = new StockController();

            stockController.TakeOrder(buyStock);
            stockController.TakeOrder(sellStock);
            stockController.TakeOrder(sellStock);
        }
Exemplo n.º 5
0
    public void Main()
    {
        Stock     abcStock       = new Stock();
        BuyStock  buyStockOrder  = new BuyStock(abcStock);
        SellStock sellStockOrder = new SellStock(abcStock);

        Broker broker = new Broker();

        broker.TakeOrder(buyStockOrder);
        broker.TakeOrder(sellStockOrder);

        broker.PlaceOrders();
    }
Exemplo n.º 6
0
        public void Start()
        {
            var abcStock  = new Stock("ABC", 10);
            var buyStock  = new BuyStock(abcStock);
            var sellStock = new SellStock(abcStock);

            var broker = new Broker();

            broker.TakeOrder(buyStock);
            broker.TakeOrder(sellStock);

            broker.PlaceOrder();
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            Stock stock = new Stock();

            BuyStock  buyStock  = new BuyStock(stock);
            SellStock sellStock = new SellStock(stock);

            Broker broker = new Broker();

            broker.TakeOrder(buyStock);
            broker.TakeOrder(sellStock);

            broker.PlaceOrders();
        }
Exemplo n.º 8
0
        public static void Main(string[] args)
        {
            Stock abcStock = new Stock();

            BuyStock  buyStockOrder  = new BuyStock(abcStock);
            SellStock sellStockOrder = new SellStock(abcStock);

            Broker broker = new Broker();

            broker.takeOrder(buyStockOrder);
            broker.takeOrder(sellStockOrder);

            broker.placeOrders();
        }
Exemplo n.º 9
0
        public static void Output()
        {
            var abcStock = new Stock();

            var buyStockOrder  = new BuyStock(abcStock);
            var sellStockOrder = new SellStock(abcStock);

            var broker = new Broker();

            broker.TakeOrder(buyStockOrder);
            broker.TakeOrder(sellStockOrder);

            broker.PlaceOrders();
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            Stock stock1 = new Stock("NASDAQ", 10);
            Stock stock2 = new Stock("Google", 30);
            Stock stock3 = new Stock("Apple", 20);

            BuyStock  order1 = new BuyStock(stock1);
            BuyStock  order2 = new BuyStock(stock2);
            SellStock order3 = new SellStock(stock3);

            CommandInvoker invoker = new CommandInvoker();

            invoker.TakeOrder(order1);
            invoker.TakeOrder(order2);
            invoker.TakeOrder(order3);

            invoker.ExecuteOrders();

            // Wait for user
            Console.ReadKey();
        }
Exemplo n.º 11
0
        public HttpResponseMessage SellStocks(long UserId, long SimulationStockId, int SellNumber)
        {
            User            user               = db.Users.FirstOrDefault(s => s.Id == UserId);
            StockAccount    stockAccount       = db.StockAccounts.FirstOrDefault(s => s.UserId == UserId);
            Double          Initial_ValidMoney = stockAccount.ValidMoney;
            SimulationStock simulationStock    = db.SimulationStocks.FirstOrDefault(s => s.Id == SimulationStockId);

            if (SellNumber > simulationStock.StockNumber)
            {
                return(ApiResponse.BadRequest("超过你的持股数量了"));
            }
            else
            {
                SellStock sellStock = new SellStock();
                try
                {
                    List <SimulationStock> simulationStocks = db.SimulationStocks.Where(s => s.StockAccountId == stockAccount.Id && s.Valid == true).ToList();
                    if (simulationStocks.Count > 0)
                    {
                        string[]      stockCodes     = simulationStocks.Select(s => s.StockCode).ToArray();
                        StringBuilder request_string = new StringBuilder();
                        for (int i = 0; i < stockCodes.Length; i++)
                        {
                            if (i == stockCodes.Length - 1)
                            {
                                request_string.Append(stockCodes[i]);
                            }
                            else
                            {
                                request_string.Append(stockCodes[i] + ",");
                            }
                        }
                        string res = new ShowApiRequest("http://route.showapi.com/131-46", "138438", "dd520f20268747d4bbda22ac31c9cbdf")
                                     .addTextPara("stocks", request_string.ToString())
                                     .addTextPara("needIndex", "0")
                                     .post();
                        JObject jObject = JsonConvert.DeserializeObject <JObject>(res);
                        JArray  jArray  = JArray.Parse(jObject["showapi_res_body"]["list"].ToString());
                        for (int i = 0; i < simulationStocks.Count; i++)
                        {
                            for (int j = 0; j < jArray.Count; j++)
                            {
                                if (simulationStocks[i].StockCode == jArray[j]["code"].ToString())
                                {
                                    simulationStocks[i].NowPrice        = Double.Parse(jArray[j]["nowPrice"].ToString());
                                    db.Entry(simulationStocks[i]).State = EntityState.Modified;
                                    db.SaveChanges();
                                }
                            }
                            Thread.Sleep(1);
                        }

                        sellStock.SellPrice       = simulationStock.NowPrice;
                        sellStock.SellStockNumber = SellNumber;
                        sellStock.BuyPrice        = simulationStock.BuyPrice;
                        sellStock.StockName       = simulationStock.StockName;
                        sellStock.StockCode       = simulationStock.StockCode;
                        sellStock.SellTime        = DateTime.Now;
                        sellStock.StockAccountId  = stockAccount.Id;
                        db.SellStocks.Add(sellStock);
                        if (SellNumber == simulationStock.StockNumber)
                        {
                            simulationStock.StockNumber     = 0;
                            simulationStock.Valid           = false;
                            db.Entry(simulationStock).State = EntityState.Modified;
                            db.SaveChanges();
                            Thread.Sleep(1);
                        }
                        else
                        {
                            simulationStock.StockNumber    -= SellNumber;
                            db.Entry(simulationStock).State = EntityState.Modified;
                            db.SaveChanges();
                            Thread.Sleep(1);
                        }
                        try
                        {
                            double StockValue           = 0;
                            List <SimulationStock> last = db.SimulationStocks.Where(s => s.StockAccountId == stockAccount.Id && s.Valid == true).ToList();
                            foreach (var item in last)
                            {
                                StockValue += item.NowPrice * item.StockNumber;
                            }
                            StockAccount stockAccount2 = db.StockAccounts.FirstOrDefault(s => s.UserId == UserId);
                            stockAccount2.SumStockValue   = StockValue;
                            db.Entry(stockAccount2).State = EntityState.Modified;
                            db.SaveChanges();
                            Thread.Sleep(1);
                            StockAccount stockAccount3 = db.StockAccounts.FirstOrDefault(s => s.UserId == UserId);
                            stockAccount3.Profit_or_Loss += (sellStock.SellPrice - sellStock.BuyPrice) * SellNumber;

                            stockAccount3.ValidMoney     += sellStock.SellPrice * SellNumber;
                            stockAccount3.SumMoney        = Initial_ValidMoney + sellStock.SellPrice * SellNumber;
                            db.Entry(stockAccount3).State = EntityState.Modified;
                            Thread.Sleep(1);
                            TradeHistory tradeHistory = new TradeHistory()
                            {
                                StockName         = simulationStock.StockName,
                                StockCode         = simulationStock.StockCode,
                                StockAccountId    = stockAccount.Id,
                                TransactionValue  = sellStock.SellPrice * SellNumber,
                                TransactionPrice  = sellStock.SellPrice,
                                TransactionAmount = SellNumber,
                                TransactionType   = Enums.TransactionType.卖出,
                                TradeTime         = DateTime.Now
                            };
                            db.TradeHistories.Add(tradeHistory);
                            db.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            db.Entry(simulationStock).State = EntityState.Unchanged;
                            db.Entry(stockAccount).State    = EntityState.Unchanged;
                        }
                    }
                }
                catch (Exception ex)
                {
                    return(ApiResponse.BadRequest("糟糕,网络好像出问题了"));
                }
                return(ApiResponse.Ok(new
                {
                    sellStock.SellPrice,
                    sellStock.SellStockNumber,
                    sellStock.SellTime,
                    sellStock.StockCode,
                    sellStock.StockName,
                    sellStock.BuyPrice,
                    message = "您卖出 " + sellStock.StockName + "(" + sellStock.StockCode + ") " + sellStock.SellStockNumber + "股, " + "收益为¥" + (sellStock.SellPrice - sellStock.BuyPrice) * sellStock.SellStockNumber,
                }));
            }
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            Console.WriteLine("Singleton Pattern");

            // Singleton Pattern
            SingleObject singleObject = SingleObject.Instance();

            singleObject.ShowMessage();

            Console.WriteLine("\nBuilder Pattern");

            // Builder Pattern
            MealBuilder mealBuilder = new MealBuilder();

            Meal vegMeal = mealBuilder.PrepareVegMeal();

            Console.WriteLine("Veg Meal");
            vegMeal.ShowItems();
            Console.WriteLine("Total Cost : " + vegMeal.GetCost());

            Meal nonVegMeal = mealBuilder.PrepareNonVegMeal();

            Console.WriteLine("NonVeg Meal");
            nonVegMeal.ShowItems();
            Console.WriteLine("Total Cost : " + nonVegMeal.GetCost());

            Console.WriteLine("\nAbstract Factory");

            // Abstract Factory Pattern
            AbstractFactory shapeFactory = FactoryProducer.GetFactory("shape");
            IShape          circleShape  = shapeFactory.GetShape("circle");

            circleShape.Draw();

            AbstractFactory colorFactory = FactoryProducer.GetFactory("color");
            IColor          blueColor    = colorFactory.GetColor("blue");

            blueColor.Fill();

            Console.WriteLine("\nAdapter");

            //Adapter Pattern
            AudioPlayer audioPlayer = new AudioPlayer();

            audioPlayer.Play("mp4");
            audioPlayer.Play("flac");
            audioPlayer.Play("vlc");

            Console.WriteLine("\nFacade");

            //Facade Pattern
            ShapeMaker shapeMaker = new ShapeMaker();

            shapeMaker.DrawCircle();
            shapeMaker.DrawRectangle();
            shapeMaker.DrawSquare();

            Console.WriteLine("\nDecorator doesn't work");

            //Decorator Pattern
            IDecoratorShape rectangle    = new RectangleDecorator();
            IDecoratorShape redRectangle = new RedShapeDecorator(new RectangleDecorator());

            Console.WriteLine("Rectangle with no color");
            rectangle.Draw();
            Console.WriteLine("Rectangle with color");
            redRectangle.Draw();

            Console.WriteLine("\nComposite");

            //Composite Pattern
            Employee DSI           = new Employee("employee1", "DSI", 100000);
            Employee chefDeProjet1 = new Employee("employee2", "Chef de projet", 60000);
            Employee chefDeProjet2 = new Employee("employee3", "Chef de projet", 60000);
            Employee dev1          = new Employee("employee4", "Développeur", 40000);
            Employee dev2          = new Employee("employee5", "Développeur", 40000);

            DSI.Add(chefDeProjet1);
            DSI.Add(chefDeProjet2);
            chefDeProjet1.Add(dev1);
            chefDeProjet2.Add(dev2);

            Console.WriteLine(DSI.Details());
            foreach (Employee e1 in DSI.GetSubordinates())
            {
                Console.WriteLine(e1.Details());
                foreach (Employee e2 in e1.GetSubordinates())
                {
                    Console.WriteLine(e2.Details());
                }
            }

            Console.WriteLine("\nBridge");

            //Bridge Pattern
            BridgeShape shape1 = new BridgeCircle(10, 10, 1, new GreenCircle());
            BridgeShape shape2 = new BridgeCircle(100, 100, 10, new RedCircle());

            shape1.Draw();
            shape2.Draw();

            Console.WriteLine("\nCommand");

            //Command Pattern
            Stock    stock1   = new Stock("laptop", 100);
            BuyStock buyStock = new BuyStock(stock1);

            Stock     stock2    = new Stock("screen", 30);
            SellStock sellStock = new SellStock(stock2);

            Broker broker = new Broker();

            broker.TakeOrder(buyStock);
            broker.TakeOrder(sellStock);
            broker.PlaceOrders();

            Console.WriteLine("\nInterpreter");

            //Interpreter Pattern
            IExpression isMale    = InterpreterPatternDemo.GetMaleExpression();
            IExpression isMarried = InterpreterPatternDemo.GetMarriedWomanExpression();

            Console.WriteLine("John is male ? " + isMale.Interpret("john"));
            Console.WriteLine("Barbara is male ? " + isMale.Interpret("barbara"));

            Console.WriteLine("Julie is married ? " + isMarried.Interpret("julie married"));
            Console.WriteLine("Bob is married ? " + isMarried.Interpret("bob married"));
        }