private static void RandomlyUpdateASingleStock()
        {
            counter++;
            if (stockPrices.Length > 0 && counter % 3 == 0)
            {
                counter = 0;
                Random           rrd      = new Random();
                int              index    = rrd.Next(0, stockPrices.Length - 1);
                ShareInformation oldPrice = stockPrices[rrd.Next(0, stockPrices.Length - 1)];
                Console.WriteLine("UPDATE stock price {0} randomly: {1}", oldPrice.FirmName, DateTime.Now);

                double           x        = Math.Max(1, oldPrice.PricePerShare * (1 + (rrd.Next(-3, 3) / 100.0)));
                ShareInformation newPrice = new ShareInformation()
                {
                    ExchangeName  = oldPrice.ExchangeName,
                    FirmName      = oldPrice.FirmName,
                    NoOfShares    = oldPrice.NoOfShares,
                    PricePerShare = x,
                    IsFund        = oldPrice.IsFund
                };
                Console.WriteLine("Update {0} from {1} to {2}.", newPrice.FirmName, oldPrice.PricePerShare, newPrice.PricePerShare);

                stockPrices[index] = newPrice;
            }
        }
        static void UpdateStockPrices()
        {
            stockPrices = wallstreetClient.GetOverallMarketInformation();
            orders      = wallstreetClient.GetOverallOrders();

            for (int i = 0; i < stockPrices.Length; i++)
            {
                ShareInformation oldPrice          = stockPrices[i];
                long             pendingBuyOrders  = PendingOrders(oldPrice.FirmName, OrderType.BUY);
                long             pendingSellOrders = PendingOrders(oldPrice.FirmName, OrderType.SELL);
                double           x        = ComputeNewPrice(oldPrice.PricePerShare, pendingBuyOrders, pendingSellOrders);
                ShareInformation newPrice = new ShareInformation()
                {
                    ExchangeName  = oldPrice.ExchangeName,
                    FirmName      = oldPrice.FirmName,
                    NoOfShares    = oldPrice.NoOfShares,
                    IsFund        = oldPrice.IsFund,
                    PricePerShare = x
                };
                Console.WriteLine("Update {0} from {1} to {2}.", newPrice.FirmName, oldPrice.PricePerShare, newPrice.PricePerShare);

                stockPrices[i] = newPrice;
            }

            RandomlyUpdateASingleStock();

            for (int i = 0; i < stockPrices.Length; i++)
            {
                wallstreetClient.PutShareInformation(stockPrices[i], stockPrices[i].ExchangeName);
            }
        }
Beispiel #3
0
        private void UpdateOwnedShares()
        {
            var collection = new ObservableCollection <OwningShareDTO>();

            foreach (FundDepot depot in Depots)
            {
                foreach (string shareName in depot.Shares.Keys)
                {
                    var infos             = MarketInformation.Where(x => x.FirmName == shareName).ToList();
                    ShareInformation info = infos.FirstOrDefault();
                    if (info != null)
                    {
                        OwningShareDTO s = new OwningShareDTO()
                        {
                            ShareName    = shareName,
                            Amount       = depot.Shares[shareName],
                            StockPrice   = info.PricePerShare,
                            ExchangeName = info.ExchangeName
                        };
                        collection.Add(s);
                    }
                }
            }

            OwnedShares = collection;
        }
Beispiel #4
0
 private void UpdateShareInformation(ShareInformation info)
 {
     MarketInformation = new ObservableCollection <ShareInformation>(MarketInformation.Where(x => x.FirmName != info.FirmName));
     MarketInformation.Add(info);
     MarketInformation = new ObservableCollection <ShareInformation>(from i in MarketInformation orderby i.FirmName select i);
     UpdateOwnedShares();
 }
Beispiel #5
0
 public void OnNewShareInformationAvailable(ShareInformation info)
 {
     if (!info.IsFund)
     {
         ExecuteOnGUIThread(marketCallbacks, info);
     }
 }
        public FundRequestResult ProcessFundRegistration(FundRegistration request)
        {
            var fundName = request.Id;
            var depot    = new FundDepot
            {
                Id           = fundName,
                ExchangeName = exchangeId,
                Budget       = request.FundAssets,
                Shares       = new Dictionary <string, int>()
            };
            ShareInformation info  = null;
            Order            order = null;

            if (request.Shares > 0)
            {
                var exchanges = wallstreetClient.GetExchanges();
                var list      = new List <FundDepot>();
                foreach (string e in exchanges)
                {
                    var fund = wallstreetClient.GetFundDepot(fundName, e);
                    if (fund != null)
                    {
                        list.Add(fund);
                    }
                }
                var assets = list.Sum(x => x.Budget);
                assets += request.FundAssets;

                depot.Shares.Add(fundName, request.Shares);
                info = new ShareInformation
                {
                    FirmName         = fundName,
                    NoOfShares       = request.Shares,
                    PricePerShare    = assets / request.Shares,
                    PurchasingVolume = 0,
                    SalesVolume      = request.Shares,
                    IsFund           = true,
                    ExchangeName     = exchangeId
                };
                order = new Order
                {
                    Id                  = fundName + DateTime.Now.Ticks,
                    ShareName           = fundName,
                    InvestorId          = fundName,
                    Type                = OrderType.SELL,
                    TotalNoOfShares     = request.Shares,
                    NoOfOpenShares      = request.Shares,
                    NoOfProcessedShares = 0,
                    Status              = OrderStatus.OPEN,
                    Limit               = 0,
                    Prioritize          = false,
                    IsFundShare         = true
                };
            }
            return(new FundRequestResult {
                FundDepot = depot, ShareInformation = info, Order = order
            });
        }
Beispiel #7
0
 public void PutShareInformation(ShareInformation info, string exchangeId)
 {
     data.Exchanges[exchangeId].ShareInformation[info.FirmName] = info;
     NotifySubscribers(data.Exchanges[exchangeId].ShareInformationCallbacks, info);
     foreach (Order o in data.Exchanges[exchangeId].Orders.Values.Where(x => x.Status != Order.OrderStatus.DONE && x.Status != Order.OrderStatus.DELETED && x.Type == Order.OrderType.BUY))
     {
         PutOrder(o, exchangeId);
     }
 }
        private void OnNewMarketInformationAvailable(ShareInformation nu)
        {
            var tmp = MarketInformation.Where(x => x.FirmName.Equals(nu.FirmName));
            var old = tmp.Count() == 0 ? null : tmp.First();

            if (old != null)
            {
                MarketInformation.Insert(MarketInformation.IndexOf(old), nu);
                MarketInformation.Remove(old);
            }
            else
            {
                MarketInformation.Add(nu);
            }
        }
        public FirmRequestResult ProcessFirmRegistration(FirmRegistration request)
        {
            var firmName = request.Id;
            var depot    = wallstreetClient.GetFirmDepot(firmName, exchangeId);

            if (depot == null)
            {
                depot = new FirmDepot()
                {
                    FirmName = firmName, OwnedShares = 0
                };
            }

            depot.OwnedShares += request.Shares;

            var info = wallstreetClient.GetShareInformation(firmName, exchangeId);

            if (info == null)
            {
                info = new ShareInformation {
                    FirmName = firmName, NoOfShares = 0, PricePerShare = request.PricePerShare, PurchasingVolume = 0, SalesVolume = 0, ExchangeName = exchangeId
                };
            }
            info.NoOfShares  += request.Shares;
            info.SalesVolume += request.Shares;
            var order = new Order()
            {
                Id                  = firmName + DateTime.Now.Ticks,
                ShareName           = firmName,
                InvestorId          = firmName,
                Type                = OrderType.SELL,
                TotalNoOfShares     = request.Shares,
                NoOfOpenShares      = request.Shares,
                NoOfProcessedShares = 0,
                Status              = OrderStatus.OPEN,
                Limit               = 0,
                Prioritize          = false,
                IsFundShare         = false
            };

            return(new FirmRequestResult {
                FirmDepot = depot, ShareInformation = info, Order = order
            });
        }
 public void OnNewShareInformationAvailable(ShareInformation info)
 {
 }