Esempio n. 1
0
 //
 public bool TryGenerateSyntheticFill(int stratSide, out SyntheticFill newSyntheticFill)
 {
     if (CheckFillQueues(stratSide, m_FillBooks))
     {
         newSyntheticFill = GenerateSyntheticFill(stratSide);
         return(true);
     }
     else
     {
         newSyntheticFill = null;
         return(false);
     }
 }
Esempio n. 2
0
        //
        //
        public virtual SyntheticFill GenerateSyntheticFill(int stratSide)
        {
            SyntheticFill newSyntheticFill = new SyntheticFill();

            newSyntheticFill.InstrumentName = m_SyntheticInstrumentName;
            newSyntheticFill.Qty            = (int)(m_pendingFillQtys[m_SmallestLegIndex] / m_SmallestLegRatio); // just a starting point
            // First lets try and find the fill qty. Since we have our array of pendingFills we should be
            // able to divide all legs by the smallest leg, and find the smallest whole number from that
            // which will be our fillqty.
            for (int i = 0; i < m_pendingFillQtys.Length; ++i)
            {
                int possibleSyntheticQty = (int)(m_pendingFillQtys[i] / (long)m_LegRatios[i]);
                // we are looking to make sure we are going to take the largest number of COMPLETE fills
                if (Math.Abs(possibleSyntheticQty) < Math.Abs(newSyntheticFill.Qty))
                {
                    newSyntheticFill.Qty = possibleSyntheticQty;
                }
            }
            // we should theoretically now have them correct fill qty.
            // we now need to work on price, while we do this we can remove fills from our list to ensure they
            // aren't used more than once.
            for (int leg = 0; leg < m_LegRatios.Length; ++leg)
            {
                // Find which side
                int legSide = UV.Lib.Utilities.QTMath.MktSignToMktSide(UV.Lib.Utilities.QTMath.MktSideToMktSign(stratSide) * m_LegRatios[leg]);
                // find the qty we need to remove from the fill
                int qtyToRemove = (int)(m_LegRatios[leg] * newSyntheticFill.Qty);
                // find the average pricing for those fills we are removing
                double legAvgPrice = m_FillBooks[leg].m_FillPages[legSide].GetAveragePricing(qtyToRemove);
                // remove them and if false we probably have an issue so lets not report the fill.
                if (!m_FillBooks[leg].m_FillPages[legSide].DequeueQty(qtyToRemove, ref newSyntheticFill.LegFills))
                {
                    break;
                }
                // we need to multiply the average price times the leg multiplier
                legAvgPrice = m_LegPriceMultipliers[leg] * legAvgPrice;
                // assign this legs price to our spread price we will report.
                newSyntheticFill.Price += legAvgPrice;
            }
            // okay we have a synthetic fill with everything but a timestamp, lets take the current timestamp
            newSyntheticFill.LocalTime = newSyntheticFill.ExchangeTime = DateTime.Now;

            // trigger the event of synthetic fills.
            FillEventArgs e = new FillEventArgs();

            e.Fill = newSyntheticFill;
            OnSyntheticSpreadFilled(e);

            return(newSyntheticFill);
        }