예제 #1
0
        public void CreateSellOfferings()
        {
            Random rnd = new Random();

            foreach (SharePacket cmp in CompaniesList.List)
            {
                decimal coeff = CheckReferences(cmp);
                if (coeff > 4)
                {
                    coeff = 4;
                }
                if (coeff < 0.25m)
                {
                    coeff = 0.25m;
                }
                decimal border = 20 * coeff;
                // Console.WriteLine("{0} {1} ", cmp.CompanyName, border);
                decimal chance = rnd.Next(1, 101);
                while (chance <= border)
                {
                    int amount = -1;
                    if (cmp.CurrentQuantity > 0)
                    {
                        if (cmp.CurrentQuantity > 1)
                        {
                            int currentQuantity = cmp.CurrentQuantity - 1;
                            int quantity        = cmp.Quantity / 4;
                            if (currentQuantity < quantity)
                            {
                                amount = rnd.Next(1, currentQuantity);
                            }
                            else
                            {
                                amount = rnd.Next(1, quantity);
                            }
                        }
                        else
                        {
                            amount = 1;
                        }
                        if (SellList.FindNumber(cmp.CompanyName) > 0)
                        {
                            decimal price = SellList.List[SellList.FindNumber(cmp.CompanyName)].Price * rnd.Next(80, 105) / 100m;
                            GenerateSellOffering(cmp.CompanyName, Math.Round(price, 2), amount, null);
                        }
                        else
                        {
                            GenerateSellOffering(cmp.CompanyName, Math.Round(cmp.Price * rnd.Next(900, 1100) / 1000m, 2), amount, null);
                        }
                        cmp.CurrentQuantity = cmp.CurrentQuantity - amount;
                        Thread.Sleep(3);
                        chance = rnd.Next(1, 101);
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
예제 #2
0
        public void MakeDeals(List <SharePacket> buy, List <SharePacket> sell)// DODELAT
        {
            int i = 0;
            int j = 0;

            while (i < buy.Count && j < sell.Count)
            {
                if (buy[i].Owner != null && buy[i].Owner == sell[j].Owner)
                {
                    i++;
                    continue;
                }
                if (buy[i].Price < sell[j].Price)
                {
                    break;
                }
                var qty = Math.Min(buy[i].CurrentQuantity, sell[j].CurrentQuantity);

                buy[i].CurrentQuantity  -= qty;
                sell[j].CurrentQuantity -= qty;
                if (buy[i].Owner == Player.Current.Name)
                {
                    var price = Math.Min(buy[i].Price, sell[j].Price);
                    OnBuy(buy[i], qty, price);
                }
                else if (sell[j].Owner == Player.Current.Name)
                {
                    var price = Math.Min(buy[i].Price, sell[j].Price);
                    OnSell(sell[j], qty, price);
                }
                else
                {
                    CompaniesList.List[CompaniesList.FindNumber(sell[j].CompanyName)].CurrentQuantity += qty;
                }
                if (buy[i].CurrentQuantity == 0)
                {
                    i++;
                    continue;
                }
                if (sell[j].CurrentQuantity == 0)
                {
                    j++;
                    continue;
                }
            }
            foreach (var packet in buy)
            {
                BuyList.List.Add(packet);
            }
            BuyList.RemoveEmptyEntries();
            foreach (var packet in sell)
            {
                SellList.List.Add(packet);
            }
            SellList.RemoveEmptyEntries();
        }
예제 #3
0
 public void SyncLists()
 {
     if (SellList.List.Count != 0 && BuyList.List.Count != 0)
     {
         List <string> companies = SellList.ReturnAllCompanies();
         foreach (var companyName in companies)
         {
             var buy  = BuyList.GetPackets(companyName);
             var sell = SellList.GetPackets(companyName);
             MakeDeals(buy, sell);
         }
     }
 }
예제 #4
0
 //constructor
 public Trader(string uName, string pWord, string fName, string lName, string eMail, int traderid = -1) : base(uName, pWord, fName, lName, eMail, traderid)
 {
     this.class_schedule = new ClassSchedule();
     this.watch_list     = new WatchList();
     this.sell_list      = new SellList();
 }
예제 #5
0
 public Trader(string uName, string pWord) : base(uName, pWord)
 {
     this.class_schedule = new ClassSchedule();
     this.watch_list     = new WatchList();
     this.sell_list      = new SellList();
 }