Example #1
0
        public DualPosition GetPosition(Instrument instrument, bool createNew = true)
        {
            var record = _positions[instrument.Id];

            if (createNew && record == null)
            {
                record = new DualPosition {
                    Instrument = instrument
                };
                _positions[instrument.Id] = record;
            }
            return(record);
        }
Example #2
0
        private void InitPosition(Portfolio portfolio, DateTime lastMarketCloseTime)
        {
            foreach (var position in portfolio.Positions)
            {
                (double hisLongQty, double hisShortQty) = GetHistoryQty(position, lastMarketCloseTime);

                var dualPosition = new DualPosition {
                    Instrument = position.Instrument,
                    Long       =
                    {
                        Qty      = position.LongPositionQty,
                        QtyToday = position.LongPositionQty - hisLongQty
                    },
                    Short =
                    {
                        Qty      = position.ShortPositionQty,
                        QtyToday = position.ShortPositionQty - hisShortQty
                    }
                };

                _positions[position.InstrumentId] = dualPosition;
            }
        }