Contains() public method

public Contains ( BarType barType, long barSize ) : bool
barType BarType
barSize long
return bool
        public void OnBar(Bar bar)
        {
            var orders = GetOrdersBy(bar.InstrumentId);

            if (orders == null)
            {
                return;
            }

            if (FillOnBar && (BarFilter.Count == 0 || BarFilter.Contains(bar.Type, bar.Size)))
            {
                foreach (var order in orders)
                {
                    FillWithBar(order, bar);
                }
                ClearOrders();
            }
        }
        private bool FillLimitOrder(Order order)
        {
            if (order.Type != OrderType.Limit)
            {
                return(false);
            }

            int iId = order.InstrumentId;

            if (FillOnQuote)
            {
                var ask = this.framework.DataManager.GetAsk(iId);
                if (ask != null && this.FillWithAsk(order, ask))
                {
                    return(true);
                }
                var bid = this.framework.DataManager.GetBid(iId);
                if (bid != null && this.FillWithBid(order, bid))
                {
                    return(true);
                }
            }
            if (FillOnTrade)
            {
                Trade trade = this.framework.DataManager.GetTrade(iId);
                if (trade != null && this.FillWithTrade(order, trade))
                {
                    return(true);
                }
            }
            if (FillOnBar)
            {
                var bar = this.framework.DataManager.GetBar(iId);
                if (BarFilter.Count != 0 && !BarFilter.Contains(bar.Type, bar.Size))
                {
                    return(false);
                }
                if (bar != null && this.FillWithBar(order, bar))
                {
                    return(true);
                }
            }
            return(false);
        }
        public void OnBarOpen(Bar bar)
        {
            if (this.ordersByInstrumentId[bar.InstrumentId] == null)
            {
                return;
            }
            if (FillOnBarOpen)
            {
                if (BarFilter.Count != 0 && !BarFilter.Contains(bar.Type, bar.Size))
                {
                    return;
                }
                int i = 0;
                while (i < this.ordersByInstrumentId[bar.InstrumentId].Count)
                {
                    Order order = this.ordersByInstrumentId[bar.InstrumentId][i];
                    while (true)
                    {
                        switch (order.Type)
                        {
                        case OrderType.Market:
                        case OrderType.Pegged:
                            goto IL_215;

                        case OrderType.Stop:
                            switch (order.Side)
                            {
                            case OrderSide.Buy:
                                if (bar.Open >= order.StopPx)
                                {
                                    if (!FillAtStopPrice)
                                    {
                                        order.Type = OrderType.Market;
                                        continue;
                                    }
                                    goto IL_142;
                                }
                                break;

                            case OrderSide.Sell:
                                if (bar.Open <= order.StopPx)
                                {
                                    if (!FillAtStopPrice)
                                    {
                                        order.Type = OrderType.Market;
                                        continue;
                                    }
                                    goto IL_15B;
                                }
                                break;
                            }
                            break;

                        case OrderType.Limit:
                            goto IL_174;

                        case OrderType.StopLimit:
                            switch (order.Side)
                            {
                            case OrderSide.Buy:
                                if (bar.Open >= order.StopPx)
                                {
                                    order.Type = OrderType.Limit;
                                    continue;
                                }
                                break;

                            case OrderSide.Sell:
                                if (bar.Open <= order.StopPx)
                                {
                                    order.Type = OrderType.Limit;
                                    continue;
                                }
                                break;
                            }
                            break;
                        }
                        break;
                    }
IL_229:
                    i++;
                    continue;
                    goto IL_229;
IL_142:
                    this.Fill(order, order.StopPx, (int)bar.Volume);
                    goto IL_229;
IL_15B:
                    this.Fill(order, order.StopPx, (int)bar.Volume);
                    goto IL_229;
IL_174:
                    switch (order.Side)
                    {
                    case OrderSide.Buy:
                        if (bar.Open > order.Price)
                        {
                            goto IL_229;
                        }
                        if (FillAtLimitPrice)
                        {
                            this.Fill(order, order.Price, (int)bar.Volume);
                            goto IL_229;
                        }
                        this.Fill(order, bar.Open, (int)bar.Volume);
                        goto IL_229;

                    case OrderSide.Sell:
                        if (bar.Open < order.Price)
                        {
                            goto IL_229;
                        }
                        if (FillAtLimitPrice)
                        {
                            this.Fill(order, order.Price, (int)bar.Volume);
                            goto IL_229;
                        }
                        this.Fill(order, bar.Open, (int)bar.Volume);
                        goto IL_229;

                    default:
                        goto IL_229;
                    }
IL_215:
                    this.Fill(order, bar.Open, (int)bar.Volume);
                    goto IL_229;
                }
                this.ClearOrders();
            }
        }
        private void HandleSend(Order order)
        {
            if (order.Qty == 0.0)
            {
                this.ExecOrderRejected(order, "Order amount can not be zero");
                return;
            }
            var report = new ExecutionReport
            {
                DateTime     = this.framework.Clock.DateTime,
                Order        = order,
                OrderId      = order.Id,
                Instrument   = order.Instrument,
                InstrumentId = order.InstrumentId,
                ExecType     = ExecType.ExecNew,
                OrdStatus    = OrderStatus.New,
                CurrencyId   = order.Instrument.CurrencyId,
                OrdType      = order.Type,
                Side         = order.Side,
                OrdQty       = order.Qty,
                Price        = order.Price,
                StopPx       = order.StopPx,
                TimeInForce  = order.TimeInForce,
                CumQty       = 0,
                LastQty      = 0,
                LeavesQty    = order.Qty,
                LastPx       = 0,
                AvgPx        = 0,
                Text         = order.Text
            };

            order.LeavesQty = report.LeavesQty;
            this.summariesByOrderId[order.Id] = new ReportSummary(report);
            EmitExecutionReport(report, Queued);
            if (order.TimeInForce == TimeInForce.AUC)
            {
                this.stops.Add(order);
                if (this.stops.Count == 1)
                {
                    this.framework.Clock.AddReminder(OnAuction1, this.framework.Clock.DateTime.Date.Add(Auction1));
                    this.framework.Clock.AddReminder(OnAuction2, this.framework.Clock.DateTime.Date.Add(Auction2));
                }
                return;
            }
            int int_ = order.InstrumentId;

            GetOrdersBy(int_, true).Add(order);
            if (((order.Type == OrderType.Market || order.Type == OrderType.Pegged) && !FillMarketOnNext) || (order.Type == OrderType.Limit && !FillLimitOnNext) || (order.Type == OrderType.Stop && !FillStopOnNext) || (order.Type == OrderType.StopLimit && !FillStopLimitOnNext))
            {
                if (FillOnQuote)
                {
                    Ask ask = this.framework.DataManager.GetAsk(int_);
                    if (ask != null && FillWithAsk(order, ask))
                    {
                        this.ClearOrders();
                        return;
                    }
                    Bid bid = this.framework.DataManager.GetBid(int_);
                    if (bid != null && this.FillWithBid(order, bid))
                    {
                        this.ClearOrders();
                        return;
                    }
                }
                if (FillOnTrade)
                {
                    var trade = this.framework.DataManager.GetTrade(int_);
                    if (trade != null && this.FillWithTrade(order, trade))
                    {
                        this.ClearOrders();
                        return;
                    }
                }
                if (FillOnBar)
                {
                    var bar = this.framework.DataManager.GetBar(int_);
                    if (BarFilter.Count != 0 && !BarFilter.Contains(bar.Type, bar.Size))
                    {
                        return;
                    }
                    if (bar != null && this.FillWithBar(order, bar))
                    {
                        ClearOrders();
                    }
                }
            }
        }
示例#5
0
        private void Subscribe(Instrument instrument, DateTime dateTime1, DateTime dateTime2)
        {
            Console.WriteLine($"{DateTime.Now} DataSimulator::Subscribe {instrument.Symbol}");
            var list = new List <DataSeries>();

            if (SubscribeTrade)
            {
                var series = this.framework.DataManager.GetDataSeries(instrument, DataObjectType.Trade, BarType.Time, 60);
                if (series != null)
                {
                    list.Add(series);
                }
            }
            if (SubscribeBid)
            {
                var series = this.framework.DataManager.GetDataSeries(instrument, DataObjectType.Bid, BarType.Time, 60);
                if (series != null)
                {
                    list.Add(series);
                }
            }
            if (SubscribeAsk)
            {
                var series = this.framework.DataManager.GetDataSeries(instrument, DataObjectType.Ask, BarType.Time, 60);
                if (series != null)
                {
                    list.Add(series);
                }
            }
            if (SubscribeQuote)
            {
                var series = this.framework.DataManager.GetDataSeries(instrument, DataObjectType.Quote, BarType.Time, 60);
                if (series != null)
                {
                    list.Add(series);
                }
            }
            if (SubscribeBar)
            {
                var dataSeriesList = this.framework.DataManager.GetDataSeriesList(instrument, "Bar");
                foreach (DataSeries series in dataSeriesList)
                {
                    if (BarFilter.Count != 0)
                    {
                        BarType barType;
                        long    barSize;
                        DataSeriesNameHelper.TryGetBarTypeSize(series, out barType, out barSize);
                        if (!BarFilter.Contains(barType, barSize))
                        {
                            continue;
                        }
                    }
                    list.Add(series);
                }
            }
            if (SubscribeLevelII)
            {
                var series = this.framework.DataManager.GetDataSeries(instrument, DataObjectType.Level2, BarType.Time, 60);
                if (series != null)
                {
                    list.Add(series);
                }
            }
            if (SubscribeFundamental)
            {
                var series = this.framework.DataManager.GetDataSeries(instrument, DataObjectType.Fundamental, BarType.Time, 60);
                if (series != null)
                {
                    list.Add(series);
                }
            }
            if (SubscribeNews)
            {
                var series = this.framework.DataManager.GetDataSeries(instrument, DataObjectType.News, BarType.Time, 60);
                if (series != null)
                {
                    list.Add(series);
                }
            }

            foreach (var s in list)
            {
                this.emitters.Add(CreateDataSeriesEmitter(s, dateTime1, dateTime2));
            }
        }