Пример #1
0
        /// <summary>
        /// must send new positions here (eg from GotPosition on Response)
        /// </summary>
        /// <param name="p"></param>
        public void Adjust(Position p)
        {
            // did position exist?
            bool exists = !_pt[p.FullSymbol].isFlat;

            if (exists)
            {
                debug(p.FullSymbol + " re-initialization of existing position");
            }
            if (exists && ShutdownOnReinit)
            {
                // get offset
                OffsetInfo oi = GetOffset(p.FullSymbol);
                // disable it
                oi.ProfitPercent = 0;
                oi.StopPercent   = 0;
                // save it
                SetOffset(p.FullSymbol, oi);
                // cancel existing orders
                CancelAll(p.FullSymbol);
                // stop processing
                return;
            }
            // update position
            _pt.Adjust(p);
            // if we're flat, nothing to do
            if (_pt[p.FullSymbol].isFlat)
            {
                debug(p.FullSymbol + " initialized to flat.");
                // cancel pending offsets
                CancelAll(p.FullSymbol);
                // reset offset state but not configuration
                SetOffset(p.FullSymbol, new OffsetInfo(this[p.FullSymbol]));
                return;
            }
            // do we have events?
            if (!HasEvents())
            {
                return;
            }
            // do update
            doupdate(p.FullSymbol);
        }
Пример #2
0
 public void GotFill(Trade t)
 {
     _pt.Adjust(t);
 }
Пример #3
0
 /// <summary>
 /// this must be called once per position tracker, for each position update.
 /// if you are using your own position tracker with this trailing stop(eg from offset tracker, or somewhere else)
 /// you only need to adjust it once, so if you adjust it directly you don't need to call again here.
 /// </summary>
 /// <param name="p"></param>
 public void Adjust(Position p)
 {
     _pt.Adjust(p);
 }