コード例 #1
0
        /// <summary>
        /// Add an order to collection and return the unique order id or negative if an error.
        /// </summary>
        /// <param name="request">A request detailing the order to be submitted</param>
        /// <returns>New unique, increasing orderid</returns>
        public OrderTicket AddOrder(SubmitOrderRequest request)
        {
            var response = !_algorithm.IsWarmingUp
                ? OrderResponse.Success(request)
                : OrderResponse.WarmingUp(request);

            request.SetResponse(response);
            var ticket = new OrderTicket(_algorithm.Transactions, request);

            _orderTickets.TryAdd(ticket.OrderId, ticket);

            // send the order to be processed after creating the ticket
            if (response.IsSuccess)
            {
                _orderRequestQueue.Add(request);
            }
            else
            {
                // add it to the orders collection for recall later
                var order = Order.CreateOrder(request);

                // ensure the order is tagged with a currency
                var security = _algorithm.Securities[order.Symbol];
                order.PriceCurrency = security.SymbolProperties.QuoteCurrency;

                order.Status = OrderStatus.Invalid;
                order.Tag    = "Algorithm warming up.";
                ticket.SetOrder(order);
                _orders.TryAdd(request.OrderId, order);
            }
            return(ticket);
        }
コード例 #2
0
        /// <summary>
        /// Add an order to collection and return the unique order id or negative if an error.
        /// </summary>
        /// <param name="request">A request detailing the order to be submitted</param>
        /// <returns>New unique, increasing orderid</returns>
        public OrderTicket AddOrder(SubmitOrderRequest request)
        {
            var response = !_algorithm.IsWarmingUp
                ? OrderResponse.Success(request)
                : OrderResponse.WarmingUp(request);

            request.SetResponse(response);
            var ticket = new OrderTicket(_algorithm.Transactions, request);

            _orderTickets.TryAdd(ticket.OrderId, ticket);

            // send the order to be processed after creating the ticket
            if (response.IsSuccess)
            {
                _orderRequestQueue.Add(request);
            }
            else
            {
                // add it to the orders collection for recall later
                var order = Order.CreateOrder(request);
                order.Status = OrderStatus.Invalid;
                order.Tag    = "Algorithm warming up.";
                ticket.SetOrder(order);
                _orders.TryAdd(request.OrderId, order);
            }
            return(ticket);
        }
コード例 #3
0
 public void GetConsumingEnumerableReturnsItemsInOrder()
 {
     var collection = new BusyBlockingCollection<int>();
     collection.Add(1);
     collection.Add(2);
     collection.Add(3);
     collection.CompleteAdding();
     CollectionAssert.AreEquivalent(new[]{1,2,3}, collection.GetConsumingEnumerable());
 }
コード例 #4
0
        public void GetConsumingEnumerableReturnsItemsInOrder()
        {
            var collection = new BusyBlockingCollection <int>();

            collection.Add(1);
            collection.Add(2);
            collection.Add(3);
            collection.CompleteAdding();
            CollectionAssert.AreEquivalent(new[] { 1, 2, 3 }, collection.GetConsumingEnumerable());
        }
コード例 #5
0
 public void WaitForProcessingCompletedDuringGetConsumingEnumerable()
 {
     var collection = new BusyBlockingCollection<int>();
     collection.Add(1);
     collection.Add(2);
     collection.Add(3);
     collection.CompleteAdding();
     Assert.IsFalse(collection.WaitHandle.WaitOne(0));
     foreach (var item in collection.GetConsumingEnumerable())
     {
         Assert.IsFalse(collection.WaitHandle.WaitOne(0));
     }
     Assert.IsTrue(collection.WaitHandle.WaitOne(0));
 }
コード例 #6
0
        public void WaitForProcessingCompletedDuringGetConsumingEnumerable()
        {
            var collection = new BusyBlockingCollection <int>();

            collection.Add(1);
            collection.Add(2);
            collection.Add(3);
            collection.CompleteAdding();
            Assert.IsFalse(collection.WaitHandle.WaitOne(0));
            foreach (var item in collection.GetConsumingEnumerable())
            {
                Assert.IsFalse(collection.WaitHandle.WaitOne(0));
            }
            Assert.IsTrue(collection.WaitHandle.WaitOne(0));
        }
コード例 #7
0
        public void IsBusyWithItemsWaiting()
        {
            var collection = new BusyBlockingCollection <int>();

            collection.Add(1);
            Assert.IsFalse(collection.WaitHandle.WaitOne(0));
        }
コード例 #8
0
        public void IsBusyWithItemsWaiting()
        {
            var collection = new BusyBlockingCollection <int>();

            collection.Add(1);
            Assert.IsTrue(collection.IsBusy);
        }
コード例 #9
0
        /// <summary>
        /// Cancels the order ticket.
        /// </summary>
        /// <param name="ticket">The ticket.</param>
        /// <param name="quantfund">Ticket associated quant fund</param>
        /// <returns></returns>
        private OrderTicket ProcessCancelTicket(CancelOrderTicket ticket, IQuantFund quantfund)
        {
            //Try and get current order ticket
            if (!OrderTracker.TryGetOrder(ticket.OrderId, out PendingOrder pendingorder))
            {
                ticket.SetResponse(OrderTicketResponse.Error(ticket.OrderId, OrderTicketResponseErrorCode.UnableToFindOrder));
                return(ticket);
            }

            try
            {
                //Try and process cancel ticket
                if (pendingorder.OrderState.IsDone())
                {
                    _log.Error($"Order is already of state {pendingorder.OrderState} while trying to cancel this order");
                    ticket.SetResponse(OrderTicketResponse.Error(pendingorder.OrderId, OrderTicketResponseErrorCode.InvalidOrderStatus));
                }
                else if (quantfund != null && quantfund.IsBackfilling)
                {
                    ticket.SetResponse(OrderTicketResponse.Error(pendingorder.OrderId, OrderTicketResponseErrorCode.QuantFundBackfilling));
                }
                else
                {
                    // update the order status
                    var order = pendingorder.Order as OrderImpl;
                    order.State = OrderState.CancelPending;
                    pendingorder.UpdateOrder(order);

                    // notify the portfolio with an order event
                    HandleOrderTicketEvent(OrderTicketEvent.Cancelled(pendingorder.OrderId));

                    // send the request to be processed
                    ticket.SetResponse(OrderTicketResponse.Processed(ticket.OrderId), OrderTicketState.Processing);
                    _orderTicketQueue.Add(ticket);
                }
            }
            catch (Exception exc)
            {
                _log.Error(exc);
                ticket.SetResponse(OrderTicketResponse.Error(pendingorder.OrderId, OrderTicketResponseErrorCode.ProcessingError, exc.Message));
            }

            //return result
            return(ticket);
        }
コード例 #10
0
 public void IsBusyWithItemsWaiting()
 {
     var collection = new BusyBlockingCollection<int>();
     collection.Add(1);
     Assert.IsTrue(collection.IsBusy);
 }
コード例 #11
0
 public void IsBusyWithItemsWaiting()
 {
     var collection = new BusyBlockingCollection<int>();
     collection.Add(1);
     Assert.IsFalse(collection.WaitHandle.WaitOne(0));
 }