/// <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); } }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Event notification for price update. </summary> /// <param name="sender"> Source of the event. </param> /// <param name="e"> Fields updated event information. </param> //////////////////////////////////////////////////////////////////////////////////////////////////// void m_priceSubscription_FieldsUpdated(object sender, FieldsUpdatedEventArgs e) { if (e.Error == null) { // Make sure that there is a valid bid if (e.Fields.GetBestBidPriceField().Value != null && m_isOrderBookDownloaded) { if (m_orderKey == "") { // If there is no order working, submit one . OrderProfile op = new OrderProfile(e.Fields.Instrument); op.BuySell = BuySell.Buy; op.Account = m_accounts.ElementAt(0); op.OrderQuantity = Quantity.FromDecimal(e.Fields.Instrument, 10); op.OrderType = OrderType.Limit; op.LimitPrice = e.Fields.GetBestBidPriceField().Value - 1; if (!m_instrumentTradeSubscription.SendOrder(op)) { Console.WriteLine("Send new order Failed.!!"); Dispose(); } else { m_orderKey = op.SiteOrderKey; Console.WriteLine("\nSent new order: " + e.Fields.Instrument.Name + " " + op.BuySell + " " + op.OrderQuantity.ToString() + "@" + op.LimitPrice.ToString() + " SOK=" + op.SiteOrderKey); } } else if (m_instrumentTradeSubscription.Orders.ContainsKey(m_orderKey) && m_instrumentTradeSubscription.Orders[m_orderKey].LimitPrice != (e.Fields.GetBestBidPriceField().Value - 1)) { // If there is a working order, reprice it OrderProfile op = m_instrumentTradeSubscription.Orders[m_orderKey].GetOrderProfile(); op.LimitPrice = e.Fields.GetBestBidPriceField().Value - 1; op.Action = OrderAction.Change; Console.WriteLine("Change price from {0} to {1}", m_instrumentTradeSubscription.Orders[m_orderKey].LimitPrice, op.LimitPrice); if (!m_instrumentTradeSubscription.SendOrder(op)) { Console.WriteLine("Sent order update: " + e.Fields.Instrument.Name + " " + op.OrderQuantity.ToString() + "@" + op.LimitPrice.ToString() + " SOK=" + op.SiteOrderKey); } else { Console.WriteLine("Send change order succeeded."); } } } } else { if (e.Error != null) { Console.WriteLine("Unrecoverable price subscription error: {0}", e.Error.Message); Dispose(); } } }
/// <summary> /// Event notification for price update /// </summary> void m_ps_FieldsUpdated(object sender, FieldsUpdatedEventArgs e) { if (e.Error == null) { // Make sure that there is a valid bid if (e.Fields.GetBestBidPriceField().HasValidValue) { if (m_orderKey == "") { // If there is no order working, submit one through the first valid order feed. // You should use the order feed that is valid for your purposes. OrderProfile op = new OrderProfile(e.Fields.Instrument.GetValidOrderFeeds()[0], e.Fields.Instrument); op.BuySell = BuySell.Buy; op.AccountName = "12345678"; op.AccountType = AccountType.A1; op.OrderQuantity = Quantity.FromInt(e.Fields.Instrument, 10); op.OrderType = OrderType.Limit; op.LimitPrice = e.Fields.GetBestBidPriceField().Value; if (!m_ts.SendOrder(op)) { Console.WriteLine("Send new order failed. {0}", op.RoutingStatus.Message); Dispose(); } else { m_orderKey = op.SiteOrderKey; Console.WriteLine("Send new order succeeded."); } } else if (m_ts.Orders.ContainsKey(m_orderKey) && m_ts.Orders[m_orderKey].LimitPrice != e.Fields.GetBestBidPriceField().Value) { // If there is a working order, reprice it if its price is not the same as the bid OrderProfileBase op = m_ts.Orders[m_orderKey].GetOrderProfile(); op.LimitPrice = e.Fields.GetBestBidPriceField().Value; op.Action = OrderAction.Change; if (!m_ts.SendOrder(op)) { Console.WriteLine("Send change order failed. {0}", op.RoutingStatus.Message); } else { Console.WriteLine("Send change order succeeded."); } } } } else { if (e.Error.IsRecoverableError == false) { Console.WriteLine("Unrecoverable price subscription error: {0}", e.Error.Message); Dispose(); } } }
/// <summary> /// Event notification for price update /// </summary> void m_ps_FieldsUpdated(object sender, FieldsUpdatedEventArgs e) { if (e.Error == null) { // Make sure that there is a valid bid if (e.Fields.GetBestBidPriceField().HasValidValue) { if (m_orderKey == "") { // If there is no order working, submit one through the first valid order feed. // You should use the order feed that is valid for your purposes. OrderProfile op = new OrderProfile(e.Fields.Instrument.GetValidOrderFeeds()[0], e.Fields.Instrument); op.BuySell = BuySell.Buy; op.AccountName = "12345678"; op.AccountType = AccountType.A1; op.OrderQuantity = Quantity.FromInt(e.Fields.Instrument, 100); op.OrderType = OrderType.Limit; op.LimitPrice = e.Fields.GetBestBidPriceField().Value; op.SlicerType = SlicerType.TimeSliced; op.DisclosedQuantity = Quantity.FromInt(e.Fields.Instrument, 10); op.DisclosedQuantityMode = QuantityMode.Quantity; op.InterSliceDelay = 10; op.InterSliceDelayTimeUnits = TimeUnits.Sec; op.LeftoverAction = LeftoverAction.Leave; op.LeftoverActionTime = LeftoverActionTime.AtEnd; op.PriceMode = PriceMode.Absolute; if (!m_ts.SendOrder(op)) { Console.WriteLine("Send new order failed. {0}", op.RoutingStatus.Message); Dispose(); } else { m_orderKey = op.SiteOrderKey; Console.WriteLine("Send new order succeeded."); } } } } else { if (e.Error.IsRecoverableError == false) { Console.WriteLine("Unrecoverable price subscription error: {0}", e.Error.Message); Dispose(); } } }
public static bool ChangeLimitOrder(string orderKey, TradingTechnologies.TTAPI.Instrument instrument, Subscription ttapisubs, double price, Logger logger) { InstrumentTradeSubscription TS = ttapisubs.TsDictionary[instrument.Key]; bool Status = true; OrderProfileBase Op = TS.Orders[orderKey].GetOrderProfile(); Price LimitPrice = Price.FromDouble(instrument.InstrumentDetails, price); if (Op.LimitPrice != LimitPrice) { Op.LimitPrice = LimitPrice; Op.Action = OrderAction.Change; if (!TS.SendOrder(Op)) { logger.Log("Send change order failed. {0}" + Op.RoutingStatus.Message); Status = false; } else { logger.Log("Send change order succeeded."); } } return(Status); }
public static string SendLimitOrder(TradingTechnologies.TTAPI.Instrument instrument, TradingTechnologies.TTAPI.Price price, int qty, Subscription ttapisubs, string orderTag = "") { BuySell Direction = BuySell.Buy; string AccountName = "H1KOC"; if (qty < 0) { Direction = BuySell.Sell; qty = -qty; } string tickerDB = TA.TickerConverters.ConvertFromTTAPIFields2DB(instrument.Product.ToString(), instrument.Name.ToString()); string[] TickerList = tickerDB.Split('-'); string TickerHead = ContractUtilities.ContractMetaInfo.GetContractSpecs(TickerList[0]).tickerHead; string ExchangeName = ContractUtilities.ContractMetaInfo.GetExchange4Tickerhead(TickerHead); AccountType AccType = AccountType.P2; OrderProfile op = new OrderProfile(instrument.GetValidOrderFeeds()[0], instrument); op.BuySell = Direction; op.AccountName = AccountName; if (ExchangeName == "ICE") { AccType = AccountType.G2; op.GiveUp = "5283"; } op.AccountType = AccType; op.OrderQuantity = Quantity.FromInt(instrument, qty); op.OrderType = OrderType.Limit; if (orderTag.Count() > 0) { op.OrderTag = orderTag; } op.LimitPrice = price; InstrumentTradeSubscription TS = ttapisubs.TsDictionary[instrument.Key]; if (!TS.SendOrder(op)) { Console.WriteLine("Send new order failed. {0}", op.RoutingStatus.Message); ttapisubs.Dispose(); } else { Console.WriteLine("Send new order succeeded."); } return(op.SiteOrderKey); }
/// <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(TTInstrument ttinstr, ZS.ZOrder o) { var orderSide = o.Side; var qtyStr = o.Qty.ToString(); var priceStr = o.Price.ToString(); var orderType = o.Type; var stopPriceStr = o.StopPrice.ToString(); // TODO: WE NEED TO DEAL WITH STOP ORDERS!!! try { TT.OrderProfile orderProfile = new TT.OrderProfile(ttinstr.DefaultOrderFeed, ttinstr.Instrument, m_defaultCustomer.Customer); orderProfile.BuySell = TranslateSide(orderSide); // Set for Buy or Sell. orderProfile.QuantityToWork = TT.Quantity.FromString(ttinstr.Instrument, qtyStr); // Set the quantity. if (orderType == ZS.ZOrderType.Market) // Market Order { orderProfile.OrderType = TT.OrderType.Market; } else if (orderType == ZS.ZOrderType.Limit) // Limit Order { // Set the limit order price. orderProfile.LimitPrice = TT.Price.FromString(ttinstr.Instrument, priceStr); } else if (orderType == ZS.ZOrderType.StopMarket) // Stop Market Order { orderProfile.OrderType = TT.OrderType.Market; // Set the order type to "Market" for a market order. orderProfile.Modifiers = TT.OrderModifiers.Stop; // Set the order modifiers to "Stop" for a stop order. orderProfile.StopPrice = TT.Price.FromString(ttinstr.Instrument, stopPriceStr); // Set the stop price. } else if (orderType == ZS.ZOrderType.StopLimit) // Stop Limit Order { orderProfile.OrderType = TT.OrderType.Limit; // Set the order type to "Limit" for a limit order. orderProfile.Modifiers = TT.OrderModifiers.Stop; // Set the order modifiers to "Stop" for a stop order. orderProfile.LimitPrice = TT.Price.FromString(ttinstr.Instrument, priceStr); // Set the limit order price. orderProfile.StopPrice = TT.Price.FromString(ttinstr.Instrument, stopPriceStr); // Set the stop price. } m_instrumentTradeSubscription.SendOrder(orderProfile); // Send the order. cout("TT Order Send {0} {1}|{2}@{3}", orderProfile.SiteOrderKey, orderProfile.BuySell.ToString(), orderProfile.QuantityToWork.ToString(), LimitOrMarketPrice(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) { ErrorMessage(err.Message); } }
public static bool CancelLimitOrder(string orderKey, TradingTechnologies.TTAPI.Instrument instrument, Subscription ttapisubs, Logger logger) { InstrumentTradeSubscription TS = ttapisubs.TsDictionary[instrument.Key]; bool Status = true; OrderProfileBase Op = TS.Orders[orderKey].GetOrderProfile(); Op.Action = OrderAction.Delete; if (!TS.SendOrder(Op)) { logger.Log("Cancal order failed. {0}" + Op.RoutingStatus.Message); Status = false; } else { logger.Log("Cancel order succeeded."); } return(Status); }
/// <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> /// 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); } }