コード例 #1
0
        public async Task Pickup(OrderRoute order)
        {
            await this.carrierOrdersApi.PickupOrder(order.Id);

            order.PickUpTime = DateTime.Now;
            order.Status     = OrderStatus.InDelivery;
        }
コード例 #2
0
        public async Task Delivered(OrderRoute order)
        {
            await this.carrierOrdersApi.DeliverOrder(order.Id);

            order.DeliveredTime = DateTime.Now;
            order.Status        = OrderStatus.Delivered;
        }
コード例 #3
0
        public TTOrder SendOrder(TTInstrument instrument, BuySell buySell, OrderType orderType, Quantity quantity, Price price)
        {
            TTOrder tto = null;

            OrderRoute orderRoute = instrument.OrderRoute;

            // If the order route has not been set for this instrument, see if there is
            // an OrderRouteInfo for this market (user sets using SetOrderRouteInfo method)
            if (instrument.OrderRoute == null && orderRouteInfo.ContainsKey(instrument.Market.Name))
            {
                OrderRouteInfo info          = orderRouteInfo[instrument.Market.Name];
                string         orderFeedName = info.OrderFeedName;
                AccountType    accountType   = (AccountType)Enum.Parse(typeof(AccountType), info.AccountTypeName);
                string         accountName   = info.AccountName;
                OrderFeed      feedToUse     = null;
                foreach (OrderFeed feed in instrument.EnabledOrderFeeds)
                {
                    if (feed.Name.Equals(orderFeedName))
                    {
                        feedToUse = feed;
                        break;
                    }
                }
                orderRoute = new OrderRoute(feedToUse, accountType, accountName);
            }

            OrderProfile prof = new OrderProfile(orderRoute.OrderFeed, instrument.TTAPI_Instrument);

            prof.BuySell       = buySell;
            prof.OrderType     = orderType;
            prof.OrderQuantity = quantity;
            prof.LimitPrice    = price;
            prof.AccountType   = orderRoute.AccountType;
            prof.AccountName   = orderRoute.AccountName;
            string tag = TTHelper.GetUniqueTag();

            prof.OrderTag = tag;
            instrument.TTAPI_Instrument.Session.SendOrder(prof);

            // Loop here to wait for the order to be returned via the API callbacks
            const int TIMEOUT_COUNT = 300;

            for (int i = 0; i < TIMEOUT_COUNT; i++)
            {
                if (sentOrders.ContainsKey(tag))
                {
                    tto = sentOrders[tag];
                    sentOrders.Remove(tag);
                    break;
                }
                Thread.Sleep(10);
            }

            return(tto);
        }
コード例 #4
0
        public OrderRouteDto AddOrderRoute(int orderId, int senderId, OrderRouteFormDto orderRouteFormDto)
        {
            if (orderRouteFormDto.RecipientId.Value == senderId)
            {
                return(null);
            }

            var order = _orderRepository.GetById(orderId);

            if (order == null)
            {
                return(null);
            }

            var oldOrderStatus = order.OrderStatus;

            var recipientId = orderRouteFormDto.RecipientId.Value;
            var orderRoute  = new OrderRoute(recipientId, senderId, orderId, orderRouteFormDto.Comment);

            order.Send(orderRoute);

            if (order.OrderStatus == OrderStatus.OnEditing)
            {
                var users = _userRepository
                            .GetUsersInRoles(new[] { Roles.Stockkeeper })
                            .ToImmutableList();

                if (users.Any(u => u.Id == orderRouteFormDto.RecipientId.Value))
                {
                    order.ChangeStatus(OrderStatus.Active);
                }
            }

            _unitOfWork.Complete();

            orderRoute = _orderRouteRepository.GetById(orderRoute.Id);
            var orderRouteDto = _mapper.Map <OrderRouteDto>(orderRoute);

            orderRouteDto.OldOrderStatus = oldOrderStatus;
            orderRouteDto.NewOrderStatus = order.OrderStatus;

            return(orderRouteDto);
        }
コード例 #5
0
        TTInstrument processInstrumentFound(Instrument instrument)
        {
            Dispatcher dispatcher = Dispatcher.Current;
            //Dispatcher dispatcher = _dispatcher;

            PriceSubscription priceSub = new PriceSubscription(instrument, dispatcher);

            if (SubscribeMarketDepth == true)
            {
                priceSub.Settings = new PriceSubscriptionSettings(PriceSubscriptionType.MarketDepth);
            }
            else
            {
                priceSub.Settings = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
            }
            priceSub.FieldsUpdated += new FieldsUpdatedEventHandler(priceSub_FieldsUpdated);
            priceSub.Start();

            InstrumentTradeSubscription its = new InstrumentTradeSubscription(_apiSession, dispatcher, instrument);

            its.EnablePNL          = true;
            its.ProfitLossChanged += new EventHandler <ProfitLossChangedEventArgs>(its_ProfitLossChanged);
            its.Start();

            if (SubscribeTimeAndSales == true)
            {
                TimeAndSalesSubscription tsSub = new TimeAndSalesSubscription(instrument, dispatcher);
                tsSub.Update += new EventHandler <TimeAndSalesEventArgs>(tsSub_Update);
                tsSub.Start();
            }

            TTInstrument tti = NewTTInstrument(instrument);

            tti.TradeSubscription = its;
            its.Tag = tti;

            tti.OrderRoute = OrderRoute.GetOrderRoute(tti, instrument.Product.Market.Name);

            return(tti);
        }
コード例 #6
0
        TTSpread processSpreadFound(Instrument instrument)
        {
            PriceSubscription priceSub = new PriceSubscription(instrument, Dispatcher.Current);

            priceSub.Settings       = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
            priceSub.FieldsUpdated += new FieldsUpdatedEventHandler(priceSub_FieldsUpdated);
            priceSub.Start();

            ASInstrumentTradeSubscription its = new ASInstrumentTradeSubscription(_apiSession, Dispatcher.Current, instrument as AutospreaderInstrument);

            its.EnablePNL          = true;
            its.ProfitLossChanged += new EventHandler <ProfitLossChangedEventArgs>(its_ProfitLossChanged);
            its.Start();

            TTSpread tts = NewTTSpread(instrument);

            tts.TradeSubscription = its;

            tts.OrderRoute = OrderRoute.GetOrderRoute(tts, instrument.Product.Market.Name);

            return(tts);
        }