/// <summary> /// Event notification for AutospreaderInstrument creation /// </summary> public void m_casReq_Completed(object sender, CreateAutospreaderInstrumentRequestEventArgs e) { if (e.Error == null) { if (e.Instrument != null) { // In this example, the AutospreaderInstrument is launched to ASE-A. // You should use the order feed that is appropriate for your purposes. OrderFeed oFeed = this.GetOrderFeedByName(e.Instrument, m_ASEGateway); if (oFeed.IsTradingEnabled) { // deploy the Autospreader Instrument to the specified ASE e.Instrument.TradableStatusChanged += new EventHandler <TradableStatusChangedEventArgs>(Instrument_TradableStatusChanged); LaunchReturnCode lrc = e.Instrument.LaunchToOrderFeed(oFeed); if (lrc != LaunchReturnCode.Success) { Console.WriteLine("Launch request was unsuccessful"); } } } } else { // AutospreaderInstrument creation failed Console.WriteLine("AutospreaderInstrument creation failed: " + e.Error.Message); } }
/// <summary> /// This function sets up the OrderProfile and submits /// the order using the InstrumentTradeSubscription SendOrder method. /// </summary> /// <param name="buySell">The side of the market to place the order on.</param> private void SendOrder(BuySell buySell) { try { OrderFeed orderFeed = comboBoxOrderFeed.SelectedItem as OrderFeed; CustomerDefaultEntry customer = cboCustomer.SelectedItem as CustomerDefaultEntry; OrderProfile orderProfile = new OrderProfile(orderFeed, m_instrumentTradeSubscription.Instrument, customer.Customer); // Set for Buy or Sell. orderProfile.BuySell = buySell; // Set the quantity. orderProfile.QuantityToWork = Quantity.FromString(m_instrumentTradeSubscription.Instrument, txtQuantity.Text); // Set the order type to "Limit" for a limit order. orderProfile.OrderType = OrderType.Limit; // Set the limit order price. orderProfile.LimitPrice = Price.FromString(m_instrumentTradeSubscription.Instrument, txtPrice.Text); // Send the order. m_instrumentTradeSubscription.SendOrder(orderProfile); m_LastOrderSiteOrderKey = orderProfile.SiteOrderKey; } catch (Exception err) { MessageBox.Show(err.Message); } }
OrderProfile CreateOrderCopy(Order order, Instrument instrument) { ReadOnlyCollection <OrderFeed> feeds = instrument.GetValidOrderFeeds(); OrderFeed feed = feeds[1]; OrderProfile profile = new OrderProfile(feed, instrument); profile.AccountName = order.AccountName; profile.AccountType = order.AccountType; profile.BuySell = order.BuySell; profile.Destination = order.Destination; profile.FFT2 = order.FFT2; profile.FFT3 = order.FFT3; profile.GiveUp = order.GiveUp; profile.IsAutomated = order.IsAutomated; profile.LimitPrice = order.LimitPrice; profile.MinimumQuantity = order.MinimumQuantity; profile.Modifiers = order.Modifiers; profile.OpenClose = order.OpenClose; profile.OrderQuantity = order.OrderQuantity; profile.OrderTag = order.OrderTag; profile.OrderType = order.OrderType; profile.PriceCheck = order.PriceCheck; profile.Restriction = order.Restriction; profile.StopPrice = order.StopPrice; profile.StopTriggerQuantity = order.StopTriggerQuantity; profile.SubUserId = order.SubUserId; profile.TimeInForce = order.TimeInForce; profile.UserName = order.UserName; profile.UserTag = order.UserTag; return(profile); }
/// <summary> /// Create an OrderProfile from this existing order /// </summary> /// <returns>A TTAPI OrderProfile object</returns> /// <remarks>There is a problem with using the TTAPI method to create a copy of an order</remarks> public OrderProfile CloneProfile() { ReadOnlyCollection <OrderFeed> feeds = Instrument.TTAPI_Instrument.GetValidOrderFeeds(); OrderFeed feed = feeds[1]; OrderRoute.GetOrderRoute(Instrument, Market.Name); OrderProfile profile = new OrderProfile(feed, Instrument.TTAPI_Instrument); profile.AccountName = TTAPI_Order.AccountName; profile.AccountType = TTAPI_Order.AccountType; profile.BuySell = TTAPI_Order.BuySell; profile.Destination = TTAPI_Order.Destination; profile.FFT2 = TTAPI_Order.FFT2; profile.FFT3 = TTAPI_Order.FFT3; profile.GiveUp = TTAPI_Order.GiveUp; profile.IsAutomated = TTAPI_Order.IsAutomated; profile.LimitPrice = TTAPI_Order.LimitPrice; profile.MinimumQuantity = TTAPI_Order.MinimumQuantity; profile.Modifiers = TTAPI_Order.Modifiers; profile.OpenClose = TTAPI_Order.OpenClose; profile.OrderQuantity = TTAPI_Order.OrderQuantity; profile.OrderTag = TTAPI_Order.OrderTag; profile.OrderType = TTAPI_Order.OrderType; profile.PriceCheck = TTAPI_Order.PriceCheck; profile.Restriction = TTAPI_Order.Restriction; profile.StopPrice = TTAPI_Order.StopPrice; profile.StopTriggerQuantity = TTAPI_Order.StopTriggerQuantity; profile.SubUserId = TTAPI_Order.SubUserId; profile.TimeInForce = TTAPI_Order.TimeInForce; profile.UserName = TTAPI_Order.UserName; profile.UserTag = TTAPI_Order.UserTag; return(profile); }
public TTInstrument(ProductKey productKey, string contract) { this.ProductKey = productKey; this.Contract = contract; m_instrument = null; m_orderFeeds = null; this.DefaultOrderFeed = null; }
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); }
private OrderFeed GetOrderFeed() { OrderFeed feed = null; foreach (OrderFeed f in SpreadInstrument.GetValidOrderFeeds()) { if (f.Name.Equals(ServerName) && f.IsTradingEnabled) { feed = f; } } return(feed); }
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { if (typeof(string) == destinationType) { OrderFeed orderFeed = value as OrderFeed; if (orderFeed != null) { return(orderFeed.Name); } } return("(none)"); }
public void FoundInstrument(Instrument instrument) { //dout("FOUND: {0}", instrument.Name); m_instrument = instrument; m_orderFeeds = new List <OrderFeed>(); foreach (OrderFeed orderFeed in instrument.GetValidOrderFeeds()) { m_orderFeeds.Add(orderFeed); } if (m_orderFeeds.Count > 0) { this.DefaultOrderFeed = m_orderFeeds[0]; } }
public void CreateMarketSubscription() { if (_dispatcher.InvokeRequired()) { _dispatcher.BeginInvoke(() => { CreateMarketSubscription(); }); return; } Dispatcher dispatcher = Dispatcher.Current; Console.WriteLine("Creating MarketSubscription..."); // Find each market and subscribe to products for that market foreach (MarketKey key in _apiSession.MarketCatalog.Markets.Keys) { Market market = _apiSession.MarketCatalog.Markets[key]; currentMarkets.Add(key, market); ProductCatalogSubscription pcs = market.CreateProductCatalogSubscription(Dispatcher.Current); pcs.ProductsUpdated += new EventHandler <ProductCatalogUpdatedEventArgs>(pcs_ProductsUpdated); pcs.Start(); } // Find all the fill feeds, order feeds, price feeds and localAutospreader order feed foreach (FillFeed feed in _apiSession.MarketCatalog.FillFeeds) { currentFillFeeds.Add(feed); } localAutospreaderOrderFeed = _apiSession.MarketCatalog.LocalAutospreaderEngineOrderFeed; foreach (OrderFeed feed in _apiSession.MarketCatalog.OrderFeeds) { currentOrderFeeds.Add(feed); } foreach (PriceFeed feed in _apiSession.MarketCatalog.PriceFeeds) { currentPriceFeeds.Add(feed); } // Subscribe to some events related to markets _apiSession.MarketCatalog.FeedStatusChanged += new EventHandler <FeedStatusChangedEventArgs>(MarketCatalog_FeedStatusChanged); _apiSession.MarketCatalog.MarketsUpdated += new EventHandler <MarketCatalogUpdatedEventArgs>(MarketCatalog_MarketsUpdated); _apiSession.MarketCatalog.TradingEnabledChanged += new EventHandler <TradingEnabledChangedEventArgs>(MarketCatalog_TradingEnabledChanged); Console.WriteLine("MarketSubscription created."); }
private void SendLimitOrder(BuySell buySell, int qty, double price) { OrderFeed feed = GetOrderFeed(); LaunchReturnCode lrc = SpreadInstrument.LaunchToOrderFeed(feed); if (lrc == LaunchReturnCode.Success) { AutospreaderSyntheticOrderProfile prof = new AutospreaderSyntheticOrderProfile(feed, SpreadInstrument); prof.BuySell = buySell; prof.OrderQuantity = Quantity.FromInt(SpreadInstrument, qty); prof.OrderType = OrderType.Limit; prof.LimitPrice = Price.FromDouble(SpreadInstrument, price); if (!SpreadInstrument.Session.SendOrder(prof)) { Console.WriteLine("send order failed: {0}", prof.RoutingStatus.Message); } } }
/// <summary> /// This function sets up the OrderProfile and submits /// the order using the InstrumentTradeSubscription SendOrder method. /// </summary> /// <param name="buySell">The side of the market to place the order on.</param> private void SendOrder(BuySell buySell) { // make sure the user has dragged a contract before we continue if (m_instrumentTradeSubscription == null) { return; } try { OrderFeed orderFeed = this.cboOrderFeed.SelectedItem as OrderFeed; CustomerDefaultEntry customer = this.cboCustomer.SelectedItem as CustomerDefaultEntry; OrderProfile orderProfile = new OrderProfile(orderFeed, m_instrumentTradeSubscription.Instrument, customer.Customer); // Set for Buy or Sell. orderProfile.BuySell = buySell; // Set the quantity. orderProfile.QuantityToWork = Quantity.FromString(m_instrumentTradeSubscription.Instrument, txtQuantity.Text); // Set the order type to "Limit" for a limit order. orderProfile.OrderType = OrderType.Limit; // Set the limit order price. orderProfile.LimitPrice = Price.FromString(m_instrumentTradeSubscription.Instrument, txtPrice.Text); // Send the order. if (m_instrumentTradeSubscription.SendOrder(orderProfile)) { // log the order send Console.WriteLine("Order Sent"); } } catch (Exception err) { MessageBox.Show(err.Message); } }
/// <summary> /// Fires when the feed status changes. /// Update the GUI comboBoxServerList drop down. /// </summary> void market_FeedStatusChanged(object sender, FeedStatusChangedEventArgs e) { OrderFeed feed = e.Feed as OrderFeed; // Only add feeds that are Up and Autospreader. if (feed != null && feed.Status.Availability == FeedAvailability.Up && feed.Market.Key == MarketKey.Autospreader) { if (!m_feedDictionary.ContainsKey(feed.Name)) { m_feedDictionary.Add(feed.Name, feed); comboBoxServerList.Items.Add(feed.Name); // If this is the first entry seed the combo box selection. if (String.IsNullOrEmpty(comboBoxServerList.Text)) { comboBoxServerList.Text = feed.Name; } } } else if (feed != null) { if (m_feedDictionary.ContainsKey(feed.Name)) { m_feedDictionary.Remove(feed.Name); comboBoxServerList.Items.Remove(feed.Name); // If this is the last entry removed fromt he combo box clear out the selection. if (comboBoxServerList.Items.Count == 0) { comboBoxServerList.Text = ""; } } } }
/// <summary> /// This function sets up the OrderProfile and submits /// the order using the InstrumentTradeSubscription SendOrder method. /// </summary> /// <param name="buySell">The side of the market to place the order on.</param> private void SendOrder(BuySell buySell) { try { OrderFeed orderFeed = comboBoxOrderFeed.SelectedItem as OrderFeed; CustomerDefaultEntry customer = cboCustomer.SelectedItem as CustomerDefaultEntry; OrderProfile orderProfile = new OrderProfile(orderFeed, m_instrumentTradeSubscription.Instrument, customer.Customer); // Set for Buy or Sell. orderProfile.BuySell = buySell; // Set the quantity. orderProfile.QuantityToWork = Quantity.FromString(m_instrumentTradeSubscription.Instrument, txtQuantity.Text); // Determine which Order Type is selected. if (cboOrderType.SelectedIndex == 0) // Market Order { // Set the order type to "Market" for a market order. orderProfile.OrderType = OrderType.Market; } else if (cboOrderType.SelectedIndex == 1) // Limit Order { // Set the order type to "Limit" for a limit order. orderProfile.OrderType = OrderType.Limit; // Set the limit order price. orderProfile.LimitPrice = Price.FromString(m_instrumentTradeSubscription.Instrument, txtPrice.Text); } else if (cboOrderType.SelectedIndex == 2) // Stop Market Order { // Set the order type to "Market" for a market order. orderProfile.OrderType = OrderType.Market; // Set the order modifiers to "Stop" for a stop order. orderProfile.Modifiers = OrderModifiers.Stop; // Set the stop price. orderProfile.StopPrice = Price.FromString(m_instrumentTradeSubscription.Instrument, txtStopPrice.Text); } else if (cboOrderType.SelectedIndex == 3) // Stop Limit Order { // Set the order type to "Limit" for a limit order. orderProfile.OrderType = OrderType.Limit; // Set the order modifiers to "Stop" for a stop order. orderProfile.Modifiers = OrderModifiers.Stop; // Set the limit order price. orderProfile.LimitPrice = Price.FromString(m_instrumentTradeSubscription.Instrument, txtPrice.Text); // Set the stop price. orderProfile.StopPrice = Price.FromString(m_instrumentTradeSubscription.Instrument, txtStopPrice.Text); } // Send the order. m_instrumentTradeSubscription.SendOrder(orderProfile); // Update the GUI. txtOrderBook.Text += String.Format("Send {0} {1}|{2}@{3}{4}", orderProfile.SiteOrderKey, orderProfile.BuySell.ToString(), orderProfile.QuantityToWork.ToString(), orderProfile.OrderType == OrderType.Limit ? orderProfile.LimitPrice.ToString() : "Market Price", System.Environment.NewLine); } catch (Exception err) { MessageBox.Show(err.Message); } }
/// <summary> /// Move the column information about the legs into the SpreadDetails object. /// </summary> /// <returns></returns> private bool moveColumnToSpreadDetails() { m_spreadDetails.Legs.Clear(); m_spreadDetails.Name = textBoxSpreadName.Text.ToString(); m_spreadDetails.PricingModel = (PricingModel)System.Enum.Parse(typeof(PricingModel), comboBoxBasedOn.Text, true); m_spreadDetails.SlopType = (SlopType)System.Enum.Parse(typeof(SlopType), comboBoxSlopSettings.Text, true); m_spreadDetails.LTPModel = (LTPModel)System.Enum.Parse(typeof(LTPModel), comboBoxSpreadLTP.Text, true); m_spreadDetails.Color = comboBoxLegColor.BackColor; for (int i = 1; i < dataGridViewSpreadDetails.Columns.Count; i++) { //get the instrument which is a hidden row InstrumentKey instrKey = (InstrumentKey)dataGridViewSpreadDetails.Rows[(int)FieldType.HiddenObject].Cells[i].Value; if (m_spreadLegs.ContainsKey(instrKey)) { Instrument instrument = (Instrument)m_spreadLegs[instrKey]; string orderFeedName = dataGridViewSpreadDetails.Rows[(int)FieldType.OrderFeedCombo].Cells[i].Value.ToString(); OrderFeed of = instrument.GetValidOrderFeeds().FirstOrDefault(f => f.ConnectionKey.GatewayKey.Name == orderFeedName); if (of == null) { MessageBox.Show("OrderFeed must be selected!"); return(false); } if (m_isNewSpread) { SpreadLegDetails spreadLeg = new SpreadLegDetails(instrKey, of.ConnectionKey); m_spreadDetails.Legs.Append(spreadLeg); } m_spreadDetails.Legs[i - 1].CustomerName = dataGridViewSpreadDetails.Rows[(int)FieldType.CustomerAccount].Cells[i].Value.ToString(); m_spreadDetails.Legs[i - 1].ActiveQuoting = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.ActiveQuoting].Cells[i].Value); m_spreadDetails.Legs[i - 1].ConsiderOwnOrders = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.ConsiderOwnOrders].Cells[i].Value); m_spreadDetails.Legs[i - 1].OffsetHedgeType = (HedgeType)System.Enum.Parse(typeof(HedgeType), dataGridViewSpreadDetails.Rows[(int)FieldType.OffsetHedge].Cells[i].Value.ToString(), true); m_spreadDetails.Legs[i - 1].PayupTicks = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.PayupTicks].Cells[i].Value); m_spreadDetails.Legs[i - 1].SpreadRatio = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.SpreadRatio].Cells[i].Value); m_spreadDetails.Legs[i - 1].PriceMultiplier = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.SpreadMultiplier].Cells[i].Value); m_spreadDetails.Legs[i - 1].QuantityMultiplier = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.QuantityMultiplier].Cells[i].Value); m_spreadDetails.Legs[i - 1].BaseVolumeLean = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.BasicVolumeLean].Cells[i].Value); m_spreadDetails.Legs[i - 1].UseCancelReplace = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.UserCancelReplace].Cells[i].Value); m_spreadDetails.Legs[i - 1].QueueHolderOrders = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.QueueHolderOrders].Cells[i].Value); m_spreadDetails.Legs[i - 1].InsideSmartQuote = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.InsideSmartQuote].Cells[i].Value); m_spreadDetails.Legs[i - 1].SmartQuoteLimit = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.SmartQuoteLimit].Cells[i].Value); m_spreadDetails.Legs[i - 1].ConsiderImplied = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.ConsiderImplied].Cells[i].Value); m_spreadDetails.Legs[i - 1].HedgeRound = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.HedgeRound].Cells[i].Value); m_spreadDetails.Legs[i - 1].MaxPriceMove = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.MaxPriceMove].Cells[i].Value); m_spreadDetails.Legs[i - 1].MaxOrderMove = System.Convert.ToInt32(dataGridViewSpreadDetails.Rows[(int)FieldType.MaxOrderMove].Cells[i].Value); m_spreadDetails.Legs[i - 1].UseCancelReplaceForQtyReduction = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.CancelReplaceForQuantity].Cells[i].Value); m_spreadDetails.Legs[i - 1].OneOverPrice = System.Convert.ToBoolean(dataGridViewSpreadDetails.Rows[(int)FieldType.OneOverPrice].Cells[i].Value); } else { MessageBox.Show("could not find insturment in the map for instrument key" + instrKey.SeriesKey); return(false); } } return(true); }
/// <summary> /// Construct an OrderRoute object populated with the necessary route information /// </summary> /// <param name="feed">OrderFeed to use with this order route</param> /// <param name="accountType">AccountType to use with this order route</param> /// <param name="accountName">AccountName to use with this order route</param> public OrderRoute(OrderFeed feed, AccountType accountType, string accountName) { OrderFeed = feed; AccountType = accountType; AccountName = accountName; }