예제 #1
0
        public TTInstrument CreateInstrument(string marketName, string productTypeName, string productName, string contractName)
        {
            string tag = TTHelper.GetUniqueTag();

            EventInstruments.Instance.CreateInstrument(marketName, productTypeName, productName, contractName, tag);

            /*InstrumentDescriptor descriptor = new InstrumentDescriptor(marketName, productTypeName, productName, contractName);
             * string tag = TTHelper.GetUniqueTag();
             * SubscribeToInstrument(descriptor, tag);*/

            TTInstrument tti = null;
            // Loop here to wait for the order to be returned via the API callbacks
            const int TIMEOUT_COUNT = 100;

            for (int i = 0; i < TIMEOUT_COUNT; i++)
            {
                if (sentInstrumentRequests.ContainsKey(tag))
                {
                    tti = sentInstrumentRequests[tag];
                    sentInstrumentRequests.Remove(tag);
                    for (int j = 0; j < TIMEOUT_COUNT; j++)
                    {
                        if (tti.Last.IsValid == true)
                        {
                            break;
                        }
                        Thread.Sleep(50);
                    }
                    break;
                }
                Thread.Sleep(100);
            }
            return(tti);
        }
예제 #2
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);
        }