Beispiel #1
0
        public PositionImpl(string positionEncoded, MT4 utils)
        {
            var bp = new DDParser(positionEncoded, MT4.ArgStartC, MT4.ArgEndC);
            var p  = new SDParser(bp.pop(), '|');

            _tCount = int.Parse(p.pop(), CultureInfo.InvariantCulture);
            _hCount = int.Parse(p.pop(), CultureInfo.InvariantCulture);
            _str    = AsString();
            //
            var sz = int.Parse(bp.pop(), CultureInfo.InvariantCulture);

            LiveOrders = new Dictionary <long, IOrderInfo>((int)(sz * 1.2));
            for (var i = 0; i < sz; i++)
            {
                var oi = new OrderImpl(bp.pop(), utils);
                LiveOrders.Add(oi.TicketNumber, oi);
            }
            sz = int.Parse(bp.pop(), CultureInfo.InvariantCulture);
            HistoricalOrders = new Dictionary <long, IOrderInfo>((int)(sz * 1.2));
            for (var i = 0; i < sz; i++)
            {
                var oi = new OrderImpl(bp.pop(), utils);
                HistoricalOrders.Add(oi.TicketNumber, oi);
            }
        }
Beispiel #2
0
 public bool Equals(OrderImpl other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(other.TicketNumber == TicketNumber);
 }
Beispiel #3
0
            public List <IOrderInfo> Adjust()
            {
                bool hedgesFound;

                do
                {
                    hedgesFound = false;
                    var bIx = 0;
                    while (bIx < _buySide.Count)
                    {
                        if (CheckHedges(_buySide[bIx]))
                        {
                            hedgesFound = true;
                            continue; // continue walking BUY side
                        }
                        //
                        bIx++;
                    }
                } while (hedgesFound);
                //
                // flatten buy&sell sides
                var history = _buySide.SelectMany(infos => infos.ToArray()).ToList();

                history.AddRange(_sellSide.SelectMany(infos => infos.ToArray()));
                history.Sort((o1, o2) => o1.Ticket() > o2.Ticket() ? 1 : -1);
                //
                // process from#/to# orders
                foreach (var orderInfo in history)
                {
                    var        prevTicket = PrevTicketFromComment(orderInfo);
                    var        nextTicket = NextTicketFromComment(orderInfo);
                    IOrderInfo prev, next;
                    _orders.TryGetValue(prevTicket, out prev);
                    _orders.TryGetValue(nextTicket, out next);
                    if (prev != null)
                    {
                        orderInfo.SetPrev(prev);
                    }
                    if (next != null)
                    {
                        orderInfo.SetNext(next);
                    }
                    if (prevTicket != 0 && prev == null ||
                        nextTicket != 0 && next == null)
                    {
                        OrderImpl oi = orderInfo as OrderImpl;
                        if (oi != null)
                        {
                            if (oi._prev == 0 && prevTicket != 0)
                            {
                                oi._prev = prevTicket;
                            }
                            if (oi._next == 0 && nextTicket != 0)
                            {
                                oi._next = nextTicket;
                            }
                        }
                    }
                }
                _toResolve.AddRange(history.Where(
                                        order => order.GetComment().Equals(@"partial close") && order.GetPrev() == 0));
                _history.AddRange(history.Where(
                                      order => !order.GetComment().Equals(@"partial close") || order.GetPrev() != 0));
                //
                foreach (var orderInfo in _live)
                {
                    OrderImpl oi = orderInfo as OrderImpl;
                    if (oi != null && oi._prev == 0)
                    {
                        oi._prev = PrevTicketFromComment(orderInfo);
                    }
                }
                //
                foreach (var order in _history)
                {
                    order.LotsBeforeClose = order.LotsClosed = Lots(order);
                    var        o = order;
                    IOrderInfo next;
                    while (_orders.TryGetValue(o.GetNext(), out next))
                    {
                        order.LotsBeforeClose += Lots(next);
                        o = next;
                    }
                }
                //
                return(_toResolve);
            }