Exemplo n.º 1
0
        static void RunBid(Job job)
        {
            //Grab the total stocks the market maker owns of this stock
            int NumberOfStocksOwned = DataBaseHandler.GetCount("SELECT SUM(Quantity) FROM Inventories WHERE UserID = " + clientID + " AND StockName = '" + job.bidAndOffer.StockName + "'");
            //Count how many of these the market maker is already selling
            int AlreadySelling = DataBaseHandler.GetCount("SELECT COUNT(Quantity) FROM Pool WHERE Type = 1 AND User = "******" AND StockName = '" + job.bidAndOffer.StockName + "'");
            //Calculate the total stock available for the market maker to sell
            int StocksAvailable = NumberOfStocksOwned - AlreadySelling;

            //If it has more stock available than needed to complete the job
            if (job.Quanity <= StocksAvailable)
            {
                BidsAndOffers offer = new BidsAndOffers(true, DateTime.Now, job.bidAndOffer.Price, clientID, job.bidAndOffer.StockName, job.Quanity, 0);
                //Complete the trade by selling the market makers stock to this user
                TradeManager.CreateTrade(ref offer, ref job.bidAndOffer, job.Quanity, threadDataBaseHandler);
                //Remove job as it now complete
                Queue.Remove(job);
            }
            else
            {
                //Market maker does not have enough stock to currently complete this trade so it sells to job as much as it can and puts in a bid into the market to buy more
                //of the stock so that it can fully complete the job
                double Price = DataBaseHandler.GetCountDouble("SELECT SUM(CurrentPrice) FROM Stock WHERE StockName = '" + job.bidAndOffer.StockName + "'");
                DataBaseHandler.SetData(string.Format("INSERT INTO Pool (Type, Price, User, StockName, Quantity) VALUES ({0}, {1}, {2}, '{3}', {4})", (int)BidOffer.bid, Math.Round(Price, 2) + 1.5, clientID, job.bidAndOffer.StockName, job.Quanity - StocksAvailable));
                //Console.WriteLine(job.Quanity - StocksAvailable);
                BidsAndOffers offer = new BidsAndOffers(true, DateTime.Now, job.bidAndOffer.Price, clientID, job.bidAndOffer.StockName, StocksAvailable, 0);
                TradeManager.CreateTrade(ref offer, ref job.bidAndOffer, job.Quanity - StocksAvailable, threadDataBaseHandler);
            }
        }
Exemplo n.º 2
0
 void FIFO(ref BidsAndOffers Bid, ref List <BidsAndOffers> Offers)
 {
     //FIFO round simple assigns all remain bids and offers in a First in First Out approach
     Offers.OrderBy((o) => o.TimePlaced);
     for (int i = 0; i < Offers.Count; i++)
     {
         if (Bid.Quantity == 0)
         {
             break;
         }
         if (Offers[i].Quantity == 0)
         {
             continue;
         }
         if (Offers[i].Quantity > Bid.Quantity)
         {
             BidsAndOffers Offer = Offers[i];
             TradeManager.CreateTrade(ref Bid, ref Offer, Bid.Quantity, threadDataBaseHandler);
             Offers[i] = Offer;
         }
         else
         {
             BidsAndOffers Offer = Offers[i];
             TradeManager.CreateTrade(ref Bid, ref Offer, Offer.Quantity, threadDataBaseHandler);
             Offers[i] = Offer;
         }
     }
 }
Exemplo n.º 3
0
 private void LMMRound(ref BidsAndOffers Bid, ref List <BidsAndOffers> Offers)
 {
     //In the LLM round we assign a selection of all bids at the price level to lead market makers, this help market makers complete orders faster
     for (int i = 0; i < Offers.Count; i++)
     {
         //Select their LMM percentage from DB
         MySqlDataReader r             = threadDataBaseHandler.GetData("SELECT LMM FROM Users WHERE ID = " + Offers[i].User);
         double          LMMPercentage = 0;
         while (r.Read())
         {
             LMMPercentage = (double)r["LMM"];
         }
         //Check if they have a percentage
         if (LMMPercentage > 0f)
         {
             int LMMAmount = (int)(Bid.Quantity * LMMPercentage);
             if (LMMAmount > 0)
             {
                 //If there percentage is more than avilable we clamp it to max
                 if (LMMAmount > Offers[i].Quantity)
                 {
                     BidsAndOffers Offer = Offers[i];
                     TradeManager.CreateTrade(ref Bid, ref Offer, Offer.Quantity, threadDataBaseHandler);
                     Offers[i] = Offer;
                 }
                 else
                 {
                     BidsAndOffers Offer = Offers[i];
                     TradeManager.CreateTrade(ref Bid, ref Offer, LMMAmount, threadDataBaseHandler);
                     Offers[i] = Offer;
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
        static void RunOfffer(Job job)
        {
            //Purchase the stocks that this job is selling to complete the job
            BidsAndOffers bid = new BidsAndOffers(false, DateTime.Now, job.bidAndOffer.Price, clientID, job.bidAndOffer.StockName, job.Quanity, 0);

            TradeManager.CreateTrade(ref job.bidAndOffer, ref bid, job.Quanity, threadDataBaseHandler);
            //Remove job from queue as it is now complete
            Queue.Remove(job);
        }
Exemplo n.º 5
0
        void ProRataWithLMM(ref BidsAndOffers Bid, ref List <BidsAndOffers> Offers, int ProRataMinimumAllocation)
        {
            //This round assigns offer quantities in relation to the size of the pool
            int TotalQuanityOfOffers = 0;
            int BidQuanity           = Bid.Quantity;

            foreach (BidsAndOffers o in Offers)
            {
                TotalQuanityOfOffers += o.Quantity;
            }
            for (int i = 0; i < Offers.Count; i++)
            {
                double ProRata = 0;
                if (Offers[i].Quantity != 0)
                {
                    //This equation gives us the percentage of the total quantity of offer this offer is
                    ProRata = (double)Offers[i].Quantity / (double)TotalQuanityOfOffers;
                }
                int ProRataAmount = (int)(ProRata * BidQuanity);
                //This stop there being a lower amount of stock moved if small value
                //Could increase this value to stop small trades of only 1 stock ect being assigned
                if (ProRataAmount >= ProRataMinimumAllocation)
                {
                    if (ProRataAmount > Offers[i].Quantity)
                    {
                        BidsAndOffers Offer = Offers[i];
                        TradeManager.CreateTrade(ref Bid, ref Offer, Offer.Quantity, threadDataBaseHandler);
                        Offers[i] = Offer;
                    }
                    else
                    {
                        BidsAndOffers Offer = Offers[i];
                        TradeManager.CreateTrade(ref Bid, ref Offer, ProRataAmount, threadDataBaseHandler);
                        Offers[i] = Offer;
                    }
                }
            }
        }