public bool TryExecute(IOrderBookBestBidAsk bestBidAsk)
        {
            if (TriggerAction == null)
                throw new InvalidOperationException("BestPriceTrigger cannot execute as action is null.");

            if (TriggerHasFired)
                return false;

            switch (Way)
            {
                case WayEnum.Buy:

                    if ((bestBidAsk.BestBidPrice.HasValue && bestBidAsk.BestBidPrice.Value >= TriggerPrice) ||
                        (bestBidAsk.BestAskPrice.HasValue && bestBidAsk.BestAskPrice.Value >= TriggerPrice))
                    {
                        Execute();
                        return true;
                    }

                    break;

                case WayEnum.Sell:

                    if ((bestBidAsk.BestAskPrice.HasValue && bestBidAsk.BestAskPrice.Value <= TriggerPrice) ||
                        (bestBidAsk.BestBidPrice.HasValue && bestBidAsk.BestBidPrice.Value <= TriggerPrice))
                    {
                        Execute();
                        return true;
                    }
                    break;
            }

            return false;
        }
Beispiel #2
0
 public void EnqueueLevel1Update(IOrderBookBestBidAsk orderBookBestBidAsk)
 {
     serverToClientMessage.Reset();
     serverToClientMessage.MessageType      = ServerToClientMessageTypeEnum.Level1;
     serverToClientMessage.ReceiverClientId = 0;
     serverToClientMessage.Level1.Update(orderBookBestBidAsk.ToDto());
     Enqueue();
 }
 public OrderBook(string symbol, ILimitOrderMatchingAlgorithm limitOrderMatchingAlgorithm, IMarketOrderMatchingAlgorithm marketOrderMatchingAlgorithm, IOrderBookBestBidAsk orderBookBestBidAsk)
 {
     this.limitOrderMatchingAlgorithm = limitOrderMatchingAlgorithm;
     this.marketOrderMatchingAlgorithm = marketOrderMatchingAlgorithm;
     this.orderBookBestBidAsk = orderBookBestBidAsk;
     Symbol = symbol;
     PriceSlots = new Dictionary<double, IPriceSlot>();
     BuySideStopLimitOrders = new List<IStopLimitOrder>();
     SellSideStopLimitOrders = new List<IStopLimitOrder>();
 }
Beispiel #4
0
 public OrderBook(string symbol, ILimitOrderMatchingAlgorithm limitOrderMatchingAlgorithm, IMarketOrderMatchingAlgorithm marketOrderMatchingAlgorithm, IOrderBookBestBidAsk orderBookBestBidAsk)
 {
     this.limitOrderMatchingAlgorithm  = limitOrderMatchingAlgorithm;
     this.marketOrderMatchingAlgorithm = marketOrderMatchingAlgorithm;
     this.orderBookBestBidAsk          = orderBookBestBidAsk;
     Symbol                  = symbol;
     PriceSlots              = new Dictionary <double, IPriceSlot>();
     BuySideStopLimitOrders  = new List <IStopLimitOrder>();
     SellSideStopLimitOrders = new List <IStopLimitOrder>();
 }
Beispiel #5
0
        public bool TryExecute(IOrderBookBestBidAsk bestBidAsk)
        {
            if (TriggerAction == null)
            {
                throw new InvalidOperationException("BestPriceTrigger cannot execute as action is null.");
            }

            if (TriggerHasFired)
            {
                return(false);
            }

            switch (Way)
            {
            case WayEnum.Buy:

                if ((bestBidAsk.BestBidPrice.HasValue && bestBidAsk.BestBidPrice.Value >= TriggerPrice) ||
                    (bestBidAsk.BestAskPrice.HasValue && bestBidAsk.BestAskPrice.Value >= TriggerPrice))
                {
                    Execute();
                    return(true);
                }


                break;

            case WayEnum.Sell:

                if ((bestBidAsk.BestAskPrice.HasValue && bestBidAsk.BestAskPrice.Value <= TriggerPrice) ||
                    (bestBidAsk.BestBidPrice.HasValue && bestBidAsk.BestBidPrice.Value <= TriggerPrice))
                {
                    Execute();
                    return(true);
                }
                break;
            }

            return(false);
        }
 public void EnqueueLevel1Update(IOrderBookBestBidAsk orderBookBestBidAsk)
 {
     serverToClientMessage.Reset();
     serverToClientMessage.MessageType = ServerToClientMessageTypeEnum.Level1;
     serverToClientMessage.ReceiverClientId = 0;
     serverToClientMessage.Level1.Update(orderBookBestBidAsk.ToDto());
     Enqueue();
 }