Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Subscribe to a Autospreader instrument with the specified instrument key
        /// </summary>
        /// <param name="key">InstrumentKey of the AS instrument to which we are subscribing</param>

/*        public void SubscribeToSpread(InstrumentKey key)
 *      {
 *          SpreadDetails details = autospreaderManager.GetSpreadDetails(key);
 *
 *          CreateAutospreaderInstrumentRequest casReq = new CreateAutospreaderInstrumentRequest(apiSession, Dispatcher.Current, details);
 *          casReq.Completed += new EventHandler<CreateAutospreaderInstrumentRequestEventArgs>(autospreaderLookupRequest_Completed);
 *          casReq.Submit();
 *      }
 */

        #region SEND ORDERS
        public void SetOrderRouteInfo(string marketName, string orderFeedName, string accountTypeName, string accountName)
        {
            OrderRouteInfo info = new OrderRouteInfo();

            info.MarketName      = marketName;
            info.OrderFeedName   = orderFeedName;
            info.AccountTypeName = accountTypeName;
            info.AccountName     = accountName;

            orderRouteInfo[marketName] = info;
        }