示例#1
0
        public void Post([FromBody] Common.Stock stock)
        {
            var newstock = stock;

            if (newstock.StockType == Common.Stock.SaleOrPurchase.Purchase)
            {
                Matcher3.BuyStock(newstock);
            }
            else if (newstock.StockType == Common.Stock.SaleOrPurchase.Sale)
            {
                Matcher3.SellStock(newstock);
            }
        }
示例#2
0
        public static void SellStock(Common.Stock stock)
        {
            // Flag to check if the matching was successful
            var foundMatch = false;

            foreach (Common.Stock stkBid in _stockBidList)
            {
                if (stkBid.StockName == stock.StockName)
                {
                    if (stkBid.Amount == stock.Amount)
                    {
                        //ServiceEventSource.Current.ServiceMessage(context, "Seller got a full match; " + stock.Username + " sold " + stock.Amount + " of " + stock.StockName + " from " + stkBid.Username);
                        _stockBidList.Remove(stkBid);

                        foundMatch = true;
                        break;
                    }
                    else if (stkBid.Amount > stock.Amount)
                    {
                        //ServiceEventSource.Current.ServiceMessage(context, "Seller got a match in a larger bid; " + stock.Username + " sold " + stock.Amount + " of " + stock.StockName + " from " + stkBid.Username);
                        _stockBidList.Remove(stkBid);
                        stkBid.Amount -= stock.Amount;
                        _stockBidList.Add(stkBid);

                        foundMatch = true;
                        break;
                    }
                    else if (stkBid.Amount < stock.Amount)
                    {
                        //ServiceEventSource.Current.ServiceMessage(context, "Seller got a partial match in a smaller bid; " + stock.Username + " sold " + stkBid.Amount + " of " + stock.StockName + " from " + stkBid.Username);
                        _stockBidList.Remove(stkBid);
                        stock.Amount -= stkBid.Amount;
                        // Recursively call same method to check if further matches can be found
                        SellStock(stock);

                        foundMatch = true;
                        break;
                    }
                }
            }

            // Add unfulfilled bids to list to be matched later
            if (foundMatch == false)
            {
                _stockSaleList.Add(stock);
            }
        }
示例#3
0
        public async System.Threading.Tasks.Task PostAsync([FromUri] string value)
        {
            var firstDelimiter = value.IndexOf(';');
            var lastDelimiter  = value.LastIndexOf(';');

            var username  = value.Substring(0, firstDelimiter);
            var stockname = value.Substring(firstDelimiter + 1, value.Length - (firstDelimiter + 1));

            stockname = stockname.Substring(0, stockname.IndexOf(';'));

            var amount = value.Substring(lastDelimiter + 1, value.Length - (lastDelimiter + 1));

            int amountInt;

            if (int.TryParse(amount, out amountInt))
            {
                var stock = new Common.Stock()
                {
                    StockName = stockname, StockType = Common.Stock.SaleOrPurchase.Sale, Username = username, Amount = amountInt
                };

                await Seller.PlaceRequestAsync(stock);
            }
        }