Esempio n. 1
0
        /// <summary>
        /// track and correct oversells (either by splitting into two orders, or dropping oversell)
        /// </summary>
        /// <param name="o"></param>
        public void sendorder(Order o)
        {
            // get original size
            int osize  = o.OrderSize;
            int uosize = o.UnsignedSize;
            // get existing size
            int size   = _pt[o.FullSymbol].Size;
            int upsize = _pt[o.FullSymbol].UnsignedSize;
            // check for overfill/overbuy
            bool over = (o.OrderSize * size < -1) && (o.UnsignedSize > Math.Abs(size)) && (upsize >= MinLotSize);

            // detect
            if (over)
            {
                // determine correct size
                int oksize = _pt[o.FullSymbol].FlatSize;
                // adjust
                o.OrderSize = Calc.Norm2Min(oksize, MinLotSize);
                // send
                sonow(o);
                // count
                osa++;
                // notify
                debug(o.FullSymbol + " oversell detected on pos: " + size + " order adjustment: " + osize + "->" + size + " " + o.ToString());
                // see if we're splitting
                if (Split)
                {
                    // calculate new size
                    int nsize = Calc.Norm2Min(Math.Abs(uosize - Math.Abs(oksize)), MinLotSize);
                    // adjust side
                    nsize *= (o.Side ? 1 : -1);
                    // create order
                    Order newo = new Order(o);
                    newo.OrderSize = nsize;
                    newo.Id        = _idt.NextOrderId;
                    if (_orgid2splitid.ContainsKey(o.Id))
                    {
                        _orgid2splitid[o.Id] = newo.Id;
                    }
                    else
                    {
                        _orgid2splitid.Add(o.Id, newo.Id);
                    }
                    // send
                    if (nsize != 0)
                    {
                        sonow(newo);
                    }
                    // notify
                    debug(o.FullSymbol + " splitting oversell/overcover: " + o.ToString() + " to 2nd order: " + newo);
                }
            }
            else
            {
                sonow(o);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Generate a stop order for a position, at a specified per-share/contract price
        /// </summary>
        /// <param name="p">your position</param>
        /// <param name="offset">how far away stop is</param>
        /// <param name="percent">what percent of position to close</param>
        /// <param name="normalizesize">whether to normalize size to even-lots</param>
        /// <param name="MINSIZE">size of an even lot</param>
        /// <returns></returns>
        public static Order PositionStop(Position p, decimal offset, decimal percent, bool normalizesize, int MINSIZE)
        {
            Order o = new Order();

            if (!p.isValid || p.isFlat)
            {
                return(o);
            }
            decimal price = Calc.OffsetPrice(p, offset * -1);
            int     size  = percent == 0 ? 0 : (!normalizesize ? (int)(p.FlatSize * percent) : Calc.Norm2Min(p.FlatSize * percent, MINSIZE));

            o = new StopOrder(p.FullSymbol, p.isLong ? -size : size, price);
            return(o);
        }
Esempio n. 3
0
 public MarketOrderFlat(Position p, decimal percent, bool normalizeSize, int MinimumLotSize, long id) :
     base(p.FullSymbol, normalizeSize ? Calc.Norm2Min((decimal)percent * p.FlatSize, MinimumLotSize) : (int)(percent * p.FlatSize), id)
 {
 }