Inheritance: Tick
Ejemplo n.º 1
0
 public Level2Snapshot(DateTime dateTime, byte providerId, int instrumentId, Bid[] bids, Ask[] asks)
     : base(dateTime)
 {
     ProviderId = providerId;
     InstrumentId = instrumentId;
     Bids = bids;
     Asks = asks;
 }
Ejemplo n.º 2
0
 public Quote GetQuote(int level)
 {
     var bid = new Bid();
     var ask = new Ask();
     Tick tick;
     if (Bids.Count < level)
     {
         tick = Bids[level];
         bid = new Bid(tick.DateTime, tick.ProviderId, tick.InstrumentId, tick.Price, tick.Size);
     }
     if (Asks.Count < level)
     {
         tick = Asks[level];
         ask = new Ask(tick.DateTime, tick.ProviderId, tick.InstrumentId, tick.Price, tick.Size);
     }
     return new Quote(bid, ask);
 }
Ejemplo n.º 3
0
 internal void OnAsk(Ask ask)
 {
     if (TraceOnQuote && Side == PositionSide.Short)
     {
         this.fillPrice = this.trailPrice = this.currPrice = GetPrice(ask.Price);
         this.method_1();
     }
 }
Ejemplo n.º 4
0
 public Level2Snapshot(DateTime dateTime, DateTime exchangeDateTime, byte providerId, int instrumentId, Bid[] bids, Ask[] asks) : this(dateTime, providerId, instrumentId, bids, asks)
 {
     ExchangeDateTime = exchangeDateTime;
 }
Ejemplo n.º 5
0
        protected override void OnAsk(Instrument instrument, Ask ask)
        {
            if (instrument == spread)
                return;

            if (!isAskBidReady)
            {
                isAskBidReady = true;

                foreach (Leg leg in spread.Legs)
                {
                    if (leg.Instrument.Ask == null || leg.Instrument.Bid == null)
                    {
                        isAskBidReady = false;

                        return;
                    }
                }
            }

            //
            double askPrice = 0;
            int askSize = Int32.MaxValue;

            foreach (Leg leg in spread.Legs)
            {
                if (leg.Weight > 0)
                {
                    askPrice += leg.Instrument.Ask.Price * leg.Weight;
                    askSize = Math.Min(askSize, leg.Instrument.Ask.Size);
                }
                else if (leg.Weight < 0)
                {
                    askPrice += leg.Instrument.Bid.Price * leg.Weight;
                    askSize = Math.Min(askSize, leg.Instrument.Bid.Size);
                }
            }

            // Create new ask for spread instrument.
            EmitAsk(new Ask(ask.DateTime, 0, spread.Id, askPrice, askSize));
        }
Ejemplo n.º 6
0
 public override void EmitAsk(Ask ask)
 {
     EventManager.OnEvent(new Ask(ask){providerId = IsInstance ? (byte)Parent.Id : (byte)Id});
 }
Ejemplo n.º 7
0
 protected virtual void OnAsk(Ask ask)
 {
 }
Ejemplo n.º 8
0
 internal void OnAsk(Ask ask)
 {
     if (Strategy?.Status == StrategyStatus.Running)
         Strategy.EmitAsk(ask);
 }
Ejemplo n.º 9
0
 protected virtual void OnAsk(Ask Ask)
 {
     // noop
 }
Ejemplo n.º 10
0
 public Quote(Bid bid, Ask ask)
 {
     Bid      = bid;
     Ask      = ask;
     DateTime = bid.DateTime > ask.DateTime ? bid.DateTime : ask.DateTime;
 }
Ejemplo n.º 11
0
 public Ask(Ask ask) : base(ask)
 {
 }
Ejemplo n.º 12
0
        public void OnAsk(Ask ask)
        {
            var orders = GetOrdersBy(ask.InstrumentId);
            if (orders == null)
                return;

            if (FillOnQuote)
            {
                foreach (var order in orders)
                    FillWithAsk(order, ask);
                ClearOrders();
            }
        }
Ejemplo n.º 13
0
        private bool FillWithAsk(Order order, Ask ask)
        {
            if (order.Side != OrderSide.Buy)
                return false;

            while (true)
            {
                switch (order.Type)
                {
                    case OrderType.Market:
                    case OrderType.Pegged:
                        Fill(order, ask.Price, ask.Size);
                        return true;
                    case OrderType.Stop:
                        if (ask.Price >= order.StopPx)
                        {
                            if (!FillAtStopPrice)
                            {
                                order.Type = OrderType.Market;
                                continue;
                            }
                            Fill(order, order.StopPx, ask.Size);
                            return true;
                        }
                        break;
                    case OrderType.Limit:
                        if (ask.Price <= order.Price)
                        {
                            Fill(order, FillAtLimitPrice ? order.Price : ask.Price, ask.Size);
                            return true;
                        }
                        return false;
                    case OrderType.StopLimit:
                        if (ask.Price >= order.StopPx)
                        {
                            order.Type = OrderType.Limit;
                            continue;
                        }
                        break;
                }
                break;
            }
            return false;
        }
Ejemplo n.º 14
0
 public Level2(Ask ask, Level2UpdateAction action, int position) : base(ask)
 {
     Side     = Level2Side.Ask;
     Action   = action;
     Position = position;
 }
Ejemplo n.º 15
0
 public void OnAsk(Ask ask)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 16
0
 private void method_8(Order order_0, Bid bid_0, Ask ask_0)
 {
 }
Ejemplo n.º 17
0
        //public Level2Snapshot GetLevel2Snapshot()
        //{
        //    lock (this.lck)
        //    {
        //        if (!this.bool_0)
        //            this.method_3();

        //        var bids = new List<Bid>();
        //        var asks = new List<Ask>();
        //        foreach (var tick in this.bids)
        //            if (tick is Bid)
        //                bids.Add(tick as Bid);

        //        foreach (var tick in this.asks)
        //            if (tick is Ask)
        //                asks.Add(tick as Ask);

        //        return new Level2Snapshot(this.dateTime_0, 0, this.instrumentId, bids.ToArray(), asks.ToArray());
        //    }
        //}

        public Quote GetQuote(int level)
        {
            lock (this.lck)
            {
                if (!this.bool_0)
                    this.method_3();

                var bid = new Bid();
                var ask = new Ask();
                if (this.bids.Count > level)
                {
                    var tick = this.bids[level];
                    bid = new Bid(tick.dateTime, tick.ProviderId, tick.InstrumentId, tick.Price, tick.Size);
                }
                if (this.asks.Count > level)
                {
                    var tick = this.asks[level];
                    ask = new Ask(tick.dateTime, tick.ProviderId, tick.InstrumentId, tick.Price, tick.Size);
                }
                return new Quote(bid, ask);
            }
        }
Ejemplo n.º 18
0
        private void method_7(List <byte> providers = null)
        {
            SortedList <double, Tick> sortedList  = new SortedList <double, Tick>(new PriceComparer(PriceSortOrder.Descending));
            SortedList <double, Tick> sortedList2 = new SortedList <double, Tick>(new PriceComparer(PriceSortOrder.Ascending));
            List <Tuple <DateTime, List <Tick>, List <Tick> > > list;

            if (providers == null)
            {
                list = new List <Tuple <DateTime, List <Tick>, List <Tick> > >(this.GonEpGhAb.Values);
            }
            else
            {
                list = new List <Tuple <DateTime, List <Tick>, List <Tick> > >();
                foreach (byte current in providers)
                {
                    if (this.GonEpGhAb.ContainsKey((int)current))
                    {
                        list.Add(this.GonEpGhAb[(int)current]);
                    }
                }
            }
            this.dateTime_0 = default(DateTime);
            foreach (Tuple <DateTime, List <Tick>, List <Tick> > current2 in list)
            {
                if (current2.Item1 > this.dateTime_0)
                {
                    this.dateTime_0 = current2.Item1;
                }
            }
            List <Tuple <DateTime, List <Tick>, List <Tick> > > list2 = new List <Tuple <DateTime, List <Tick>, List <Tick> > >();

            foreach (Tuple <DateTime, List <Tick>, List <Tick> > current3 in list)
            {
                if (current3.Item1 + this.Timeout >= this.dateTime_0)
                {
                    list2.Add(current3);
                }
            }
            foreach (Tuple <DateTime, List <Tick>, List <Tick> > current4 in list2)
            {
                foreach (Tick current5 in current4.Item2)
                {
                    if (!sortedList.ContainsKey(current5.Price))
                    {
                        Bid bid = new Bid(current5);
                        if (this.Mode == OrderBookAggr.AggregationMode.TotalValue)
                        {
                            bid.ProviderId = 0;
                        }
                        sortedList.Add(current5.Price, bid);
                    }
                    else if (this.Mode == OrderBookAggr.AggregationMode.TotalValue)
                    {
                        sortedList[current5.Price].Size += current5.Size;
                    }
                    else if (this.Mode == OrderBookAggr.AggregationMode.MaxValue && current5.Size > sortedList[current5.Price].Size)
                    {
                        sortedList[current5.Price] = new Bid(current5);
                    }
                }
                foreach (Tick current6 in current4.Item3)
                {
                    if (!sortedList2.ContainsKey(current6.Price))
                    {
                        Ask ask = new Ask(current6);
                        if (this.Mode == OrderBookAggr.AggregationMode.TotalValue)
                        {
                            ask.ProviderId = 0;
                        }
                        sortedList2.Add(current6.Price, ask);
                    }
                    else if (this.Mode == OrderBookAggr.AggregationMode.TotalValue)
                    {
                        sortedList2[current6.Price].Size += current6.Size;
                    }
                    else if (this.Mode == OrderBookAggr.AggregationMode.MaxValue && current6.Size > sortedList2[current6.Price].Size)
                    {
                        sortedList2[current6.Price] = new Ask(current6);
                    }
                }
            }
            this.bids   = new List <Tick>(sortedList.Values);
            this.asks   = new List <Tick>(sortedList2.Values);
            this.bool_0 = true;
        }
Ejemplo n.º 19
0
 private void method_7(List<byte> providers = null)
 {
     SortedList<double, Tick> sortedList = new SortedList<double, Tick>(new PriceComparer(PriceSortOrder.Descending));
     SortedList<double, Tick> sortedList2 = new SortedList<double, Tick>(new PriceComparer(PriceSortOrder.Ascending));
     List<Tuple<DateTime, List<Tick>, List<Tick>>> list;
     if (providers == null)
     {
         list = new List<Tuple<DateTime, List<Tick>, List<Tick>>>(this.GonEpGhAb.Values);
     }
     else
     {
         list = new List<Tuple<DateTime, List<Tick>, List<Tick>>>();
         foreach (byte current in providers)
         {
             if (this.GonEpGhAb.ContainsKey((int)current))
             {
                 list.Add(this.GonEpGhAb[(int)current]);
             }
         }
     }
     this.dateTime_0 = default(DateTime);
     foreach (Tuple<DateTime, List<Tick>, List<Tick>> current2 in list)
     {
         if (current2.Item1 > this.dateTime_0)
         {
             this.dateTime_0 = current2.Item1;
         }
     }
     List<Tuple<DateTime, List<Tick>, List<Tick>>> list2 = new List<Tuple<DateTime, List<Tick>, List<Tick>>>();
     foreach (Tuple<DateTime, List<Tick>, List<Tick>> current3 in list)
     {
         if (current3.Item1 + this.Timeout >= this.dateTime_0)
         {
             list2.Add(current3);
         }
     }
     foreach (Tuple<DateTime, List<Tick>, List<Tick>> current4 in list2)
     {
         foreach (Tick current5 in current4.Item2)
         {
             if (!sortedList.ContainsKey(current5.Price))
             {
                 Bid bid = new Bid(current5);
                 if (this.Mode == OrderBookAggr.AggregationMode.TotalValue)
                 {
                     bid.ProviderId = 0;
                 }
                 sortedList.Add(current5.Price, bid);
             }
             else if (this.Mode == OrderBookAggr.AggregationMode.TotalValue)
             {
                 sortedList[current5.Price].Size += current5.Size;
             }
             else if (this.Mode == OrderBookAggr.AggregationMode.MaxValue && current5.Size > sortedList[current5.Price].Size)
             {
                 sortedList[current5.Price] = new Bid(current5);
             }
         }
         foreach (Tick current6 in current4.Item3)
         {
             if (!sortedList2.ContainsKey(current6.Price))
             {
                 Ask ask = new Ask(current6);
                 if (this.Mode == OrderBookAggr.AggregationMode.TotalValue)
                 {
                     ask.ProviderId = 0;
                 }
                 sortedList2.Add(current6.Price, ask);
             }
             else if (this.Mode == OrderBookAggr.AggregationMode.TotalValue)
             {
                 sortedList2[current6.Price].Size += current6.Size;
             }
             else if (this.Mode == OrderBookAggr.AggregationMode.MaxValue && current6.Size > sortedList2[current6.Price].Size)
             {
                 sortedList2[current6.Price] = new Ask(current6);
             }
         }
     }
     this.bids = new List<Tick>(sortedList.Values);
     this.asks = new List<Tick>(sortedList2.Values);
     this.bool_0 = true;
 }
Ejemplo n.º 20
0
 internal virtual void vmethod_11(Ask ask)
 {
     if (this.IsInstance)
     {
         this.OnAsk(ask);
         List<Stop> list = this.idArray_0[ask.instrumentId];
         if (list != null)
         {
             for (int i = 0; i < list.Count; i++)
             {
                 Stop stop_ = list[i];
                 if (stop_.Connected)
                 {
                     stop_.method_7(ask);
                 }
             }
         }
     }
 }
Ejemplo n.º 21
0
        protected override void OnAsk(Instrument instrument, Ask ask)
        {
            if (instrument.Id == currentFuturesContract.Id)
            {
                Ask rootAsk = new Ask(ask.DateTime, 0, rootInstrument.Id, ask.Price, ask.Size);

                // Emit ask to to BuySide strategy.
                EmitAsk(rootAsk);
            }
        }
Ejemplo n.º 22
0
 public virtual void EmitAsk(Ask ask)
 {
     EventManager.OnEvent(new Ask(ask){providerId = (byte)Id});
 }
Ejemplo n.º 23
0
 public Quote(Bid bid, Ask ask)
 {
     Bid = bid;
     Ask = ask;
     DateTime = bid.DateTime > ask.DateTime ? bid.DateTime : ask.DateTime;
 }
Ejemplo n.º 24
0
        public void OnAsk(Ask ask)
        {
            // Check conditions for send leg orders.
            if (order.Side == OrderSide.Buy)
            {
                switch (order.Type)
                {
                    case OrderType.Limit:
                        if (ask.Price <= order.Price)
                            SendLegOrders();
                        break;

                    case OrderType.Stop:
                        if (ask.Price >= order.StopPx)
                            SendLegOrders();
                        break;
                }
            }
        }
Ejemplo n.º 25
0
 public Ask(Ask ask) : base(ask)
 {
 }
Ejemplo n.º 26
0
        public override void EmitAsk(Ask ask)
        {
            // Emit ask to BuySide strategy.
            base.EmitAsk(ask);

            System.Collections.Generic.LinkedListNode<OrderProcessor> processorNode = processors.First;

            // Send ask to order processors.
            while (processorNode != null)
            {
                OrderProcessor processor = processorNode.Value;
                processor.OnAsk(ask);
                processorNode = processorNode.Next;
            }
        }
Ejemplo n.º 27
0
 public new virtual void EmitAsk(Ask ask)
 {
     this.framework.EventManager.OnEvent(new Ask(ask) { ProviderId = (byte)Id });
 }
Ejemplo n.º 28
0
 public Level2(Ask ask, Level2UpdateAction action, int position): base(ask)
 {
     Side = Level2Side.Ask;
     Action = action;
     Position = position;
 }
Ejemplo n.º 29
0
 public override void EmitAsk(Ask ask)
 {
     var providerId = GetProviderId();
     this.framework.EventManager.OnEvent(new Ask(ask) { ProviderId = providerId });
 }
Ejemplo n.º 30
0
 private void method_8(Order order_0, Bid bid_0, Ask ask_0)
 {
 }
Ejemplo n.º 31
0
 internal void OnAsk(Ask ask)
 {
     var iId = ask.InstrumentId;
     var pId = ask.ProviderId + 1;
     this.latestAsk[iId] = ask;
     this.askByIIdAndPId[pId] = this.askByIIdAndPId[pId] ?? new IdArray<Ask>(10240);
     this.askByIIdAndPId[pId][iId] = ask;
 }
Ejemplo n.º 32
0
 protected virtual void OnAsk(Ask Ask)
 {
     // noop
 }
Ejemplo n.º 33
0
 public void OnAsk(Ask ask)
 {
     throw new NotImplementedException();
 }