public OrderProcessor(OrderAgent agent, Order order, Logger logger)
 {
     _agent    = agent;
     _order    = order;
     _position = agent.GetPosition(order);
     _record   = new OrderRecord(order);
     _info     = OrderExtensions.GetOrderInfo(order);
     _logger   = logger;
     listNode  = agent.AddProcessor(this);
     InitRules();
 }
Ejemplo n.º 2
0
        public DualPosition GetPosition(Instrument instrument)
        {
            var record = _positions[instrument.Id];

            if (record == null)
            {
                record                    = new DualPosition();
                record.Instrument         = instrument;
                _positions[instrument.Id] = record;
            }
            return(record);
        }
Ejemplo n.º 3
0
        public void InitPosition(Portfolio portfolio)
        {
            foreach (var position in portfolio.Positions)
            {
                var dualPosition = new DualPosition {
                    Instrument = position.Instrument,
                    Long       = { Qty = position.LongPositionQty },
                    Short      = { Qty = position.ShortPositionQty }
                };
                foreach (var fill in position.Fills)
                {
                    if (FillInToday(fill.DateTime))
                    {
                        if (fill.Side == OrderSide.Buy)
                        {
                            switch (fill.SubSide)
                            {
                            case SubSide.BuyCover:
                                dualPosition.Short.QtyToday -= fill.Qty;
                                break;

                            case SubSide.SellShort:
                            case SubSide.Undefined:
                                dualPosition.Long.QtyToday += fill.Qty;
                                break;
                            }
                        }
                        else
                        {
                            switch (fill.SubSide)
                            {
                            case SubSide.BuyCover:
                            case SubSide.Undefined:
                                dualPosition.Long.QtyToday -= fill.Qty;
                                break;

                            case SubSide.SellShort:
                                dualPosition.Short.QtyToday += fill.Qty;
                                break;
                            }
                        }
                    }
                }
                _positions[position.InstrumentId] = dualPosition;
            }
        }