void ManageHedgedOrders(Order order) { if (!tsitemEnableHedging.Checked) { return; } // See if this order's instrument is in our managed hedges list foreach (InstrumentKey key in managedHedges.Keys) { InstrumentInfo info = managedHedges[key]; if (order.InstrumentKey == info.InstrumentKey) { //listOrders.Items.Insert(0, OrderToString(order)); if (order.IsChild && !order.IsSynthetic) { Instrument instrument = info.Instrument; OrderProfile profile = CreateOrderCopy(order, instrument); // try to delete the order and re-insert it if (order.Delete()) { DisplayOrderSuccess(instrument.Session.SendOrder(profile)); } } break; } } }
/// <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); }
/// <summary> /// Event notification for order added /// </summary> void m_ts_OrderAdded(object sender, OrderAddedEventArgs e) { if (e.Order.SiteOrderKey == m_orderKey) { // Our parent order has been added Console.WriteLine("Our parent order has been added: {0}", e.Message); } else if (e.Order.SyntheticOrderKey == m_orderKey) { // A child order of our parent order has been added Console.WriteLine("A child order of our parent order has been added: {0}", e.Message); // When half of the order quantity has been disclosed, reduce the price of all // subsequent child orders by 1 tick by reducing the parent order by 1 tick SseSyntheticOrder sseOrder = m_ts.Orders[m_orderKey] as SseSyntheticOrder; if (m_changed == false && sseOrder.UndisclosedQuantity <= (sseOrder.OrderQuantity / 2)) { OrderProfile op = sseOrder.GetOrderProfile() as OrderProfile; op.LimitPrice--; 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."); m_changed = true; } } } }
/// <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); } }
void StartAlgo() { while (!m_price.IsValid || m_algo == null) { mre.WaitOne(); } // To retrieve the list of parameters valid for the Algo you can call algo.AlgoParameters; // Construct a dictionary of the parameters and the values to send out Dictionary <string, object> algo_userparams = new Dictionary <string, object> { { "Ignore Market State", true }, }; var lines = algo_userparams.Select(kvp => kvp.Key + ": " + kvp.Value.ToString()); Console.WriteLine(string.Join(Environment.NewLine, lines)); OrderProfile algo_op = m_algo.GetOrderProfile(m_instrument); algo_op.LimitPrice = m_price; algo_op.OrderQuantity = Quantity.FromDecimal(m_instrument, 5);; algo_op.Side = OrderSide.Buy; algo_op.OrderType = OrderType.Limit; algo_op.Account = m_accounts.ElementAt(0); algo_op.UserParameters = algo_userparams; m_algoTradeSubscription.SendOrder(algo_op); }
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> /// 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(TTOrder tto, ZOrder o) { ZOrderSide orderSide = o.Side; string qtyStr = o.Qty.ToString(); string priceStr = GetPriceString(o); ZOrderType orderType = o.Type; string stopPriceStr = o.StopPrice.ToString(); // TODO: WE NEED TO DEAL WITH STOP ORDERS!!! TTInstrument ttinstr = _instruments[o.Iid]; cout("TengineTT::SendOrder: {0}", o.ToString()); try { //OrderProfile op = new OrderProfile(ttinstr.DefaultOrderFeed, ttinstr.Instrument, this.DefaultCustomer); OrderProfile op = tto.Profile; op.BuySell = TranslateSide(orderSide); // Set for Buy or Sell. op.QuantityToWork = Quantity.FromString(ttinstr.Instrument, qtyStr); // Set the quantity. if (orderType == ZOrderType.Market) // Market Order { op.OrderType = OrderType.Market; } else if (orderType == ZOrderType.Limit) // Limit Order { // Set the limit order price. op.LimitPrice = Price.FromString(ttinstr.Instrument, priceStr); } else if (orderType == ZOrderType.StopMarket) // Stop Market Order { op.OrderType = OrderType.Market; // Set the order type to "Market" for a market order. op.Modifiers = OrderModifiers.Stop; // Set the order modifiers to "Stop" for a stop order. op.StopPrice = Price.FromString(ttinstr.Instrument, stopPriceStr); // Set the stop price. } else if (orderType == ZOrderType.StopLimit) // Stop Limit Order { op.OrderType = OrderType.Limit; // Set the order type to "Limit" for a limit order. op.Modifiers = OrderModifiers.Stop; // Set the order modifiers to "Stop" for a stop order. op.LimitPrice = Price.FromString(ttinstr.Instrument, priceStr); // Set the limit order price. op.StopPrice = Price.FromString(ttinstr.Instrument, stopPriceStr); // Set the stop price. } //_orders[op.SiteOrderKey] m_dtrd[ttinstr.InstrumentKey].SendOrder(op); // Send the order. cout("TengineTT::SendOrder: TT Order Send {0} {1}|{2}@{3}", op.SiteOrderKey, op.BuySell.ToString(), op.QuantityToWork.ToString(), LimitOrMarketPrice(op)); /*// 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 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> 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> /// 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, 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!!! cout("TeTTApi::SendOrder: {0}", o.ToString()); try { CustomerDefaultEntry m_defaultCustomer = null; OrderProfile orderProfile = new OrderProfile(ttinstr.DefaultOrderFeed, ttinstr.Instrument, m_defaultCustomer.Customer); orderProfile.BuySell = TranslateSide(orderSide); // Set for Buy or Sell. orderProfile.QuantityToWork = Quantity.FromString(ttinstr.Instrument, qtyStr); // Set the quantity. if (orderType == ZOrderType.Market) // Market Order { orderProfile.OrderType = OrderType.Market; } else if (orderType == ZOrderType.Limit) // Limit Order { // Set the limit order price. orderProfile.LimitPrice = Price.FromString(ttinstr.Instrument, priceStr); } else if (orderType == ZOrderType.StopMarket) // Stop Market Order { orderProfile.OrderType = OrderType.Market; // Set the order type to "Market" for a market order. orderProfile.Modifiers = OrderModifiers.Stop; // Set the order modifiers to "Stop" for a stop order. orderProfile.StopPrice = Price.FromString(ttinstr.Instrument, stopPriceStr); // Set the stop price. } else if (orderType == ZOrderType.StopLimit) // Stop Limit Order { orderProfile.OrderType = OrderType.Limit; // Set the order type to "Limit" for a limit order. orderProfile.Modifiers = OrderModifiers.Stop; // Set the order modifiers to "Stop" for a stop order. orderProfile.LimitPrice = Price.FromString(ttinstr.Instrument, priceStr); // Set the limit order price. orderProfile.StopPrice = 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 void 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."); } }
public void priceSub_FieldsUpdated(object sender, FieldsUpdatedEventArgs e) { if (e.Error == null) { if (orderKey == null) { // In this example, the order is routed to the first order feed in the list of valid order feeds. // You should use the order feed that is appropriate for your purposes. OrderProfile prof = new OrderProfile(e.Fields.Instrument.GetValidOrderFeeds()[0], e.Fields.Instrument); prof.BuySell = BuySell.Buy; prof.AccountType = AccountType.Agent1; prof.AccountName = "fg006001"; prof.OrderQuantity = Quantity.FromInt(e.Fields.Instrument, 1); prof.OrderType = OrderType.Limit; prof.LimitPrice = e.Fields.GetBestBidPriceField().Value; if (!ts.SendOrder(prof)) { Console.WriteLine("Send Order failed : {0}", prof.RoutingStatus.Message); Dispose(); } else { orderKey = prof.SiteOrderKey; Console.WriteLine("Order sent with price = {0}", prof.LimitPrice); } } else if (ts.Orders.Keys.Contains(orderKey) && e.Fields.GetBestBidPriceField().HasValueChanged && e.Fields.GetBestBidPriceField().HasValidValue) { OrderProfileBase prof = ts.Orders[orderKey].GetOrderProfile(); prof.LimitPrice = e.Fields.GetBestBidPriceField().Value; prof.Action = OrderAction.Change; if (!ts.SendOrder(prof)) { Console.WriteLine("Send Order failed : {0}", prof.RoutingStatus.Message); Dispose(); } else { Console.WriteLine("Order Re-priced to {0}", prof.LimitPrice); } } } else { if (e.Error.IsRecoverableError == false) { Console.WriteLine("Unrecoverable price subscription error: " + e.Error.Message); Dispose(); } } }
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 void SendOrder(BuySell buySell, OrderType orderType, int qty, double price) { //OrderRoute.GetOrderRoute(this, this.Market.Name); OrderProfile prof = new OrderProfile(OrderRoute.OrderFeed, TTAPI_Instrument); prof.BuySell = buySell; prof.OrderType = orderType; prof.OrderQuantity = Quantity.FromInt(TTAPI_Instrument, qty); prof.LimitPrice = Price.FromDouble(TTAPI_Instrument, price); prof.AccountType = OrderRoute.AccountType; prof.AccountName = OrderRoute.AccountName; TTAPI_Instrument.Session.SendOrder(prof); }
/// <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 override uint CreateOrder(uint iid, ZOrderSide side, int price, uint qty, ZOrderType type, ZOrderTimeInForce tif) { uint oid = GenerateOrderId(); var o = new ZOrder(oid, iid, side, price, qty, type, tif); orders[oid] = o; // Add this to the OrderMap which will allow us to convert to/from TTAPI orders var ttinstr = _instruments[iid]; OrderProfile op = new OrderProfile(ttinstr.DefaultOrderFeed, ttinstr.Instrument, this.DefaultCustomer); var tto = new TTOrder(op); _orders.Add(tto.Key, tto, oid); return(oid); }
public void priceSub_FieldsUpdated(object sender, FieldsUpdatedEventArgs e) { if (e.Error == null) { if (orderKey == null) { // This is a time-slicer order // In this example, the order is routed to the first order feed in the list of valid order feeds. // You should use the order feed that is appropriate for your purposes. OrderProfile prof = new OrderProfile(e.Fields.Instrument.GetValidOrderFeeds()[0], e.Fields.Instrument); prof.BuySell = BuySell.Buy; prof.AccountType = AccountType.Agent1; prof.AccountName = "123"; prof.OrderQuantity = Quantity.FromInt(e.Fields.Instrument, 100); prof.OrderType = OrderType.Limit; prof.LimitPrice = e.Fields.GetBestBidPriceField().Value; prof.SlicerType = SlicerType.TimeSliced; prof.DisclosedQuantity = Quantity.FromInt(e.Fields.Instrument, 10); prof.DisclosedQuantityMode = QuantityMode.Quantity; prof.InterSliceDelay = 10; prof.InterSliceDelayTimeUnits = TimeUnits.Sec; prof.LeftoverAction = LeftoverAction.Leave; prof.LeftoverActionTime = LeftoverActionTime.AtEnd; prof.PriceMode = PriceMode.Absolute; if (!ts.SendOrder(prof)) { Console.WriteLine("Send Order failed : " + prof.RoutingStatus.Message); Dispose(); } else { orderKey = prof.SiteOrderKey; Console.WriteLine("Order sent with price = " + prof.LimitPrice); } } } else { if (e.Error.IsRecoverableError == false) { Console.WriteLine("Unrecoverable price subscription error: " + e.Error.Message); Dispose(); } } }
public async Task GetOrdersReturnsAllOrders() { var options = new DbContextOptionsBuilder <OrdersDbContext>() .UseSqlServer("Data Source=LAPTOP-U3V1724K;Initial Catalog=Microservices.Orders.Database;Integrated Security=True") .Options; var dbContext = new OrdersDbContext(options); var orderProfile = new OrderProfile(); var configuration = new MapperConfiguration(cfg => cfg.AddProfile(orderProfile)); var mapper = new Mapper(configuration); var ordersProvider = new OrdersProvider(dbContext, null, mapper, configuration, null); var order = await ordersProvider.GetAllOrdersAsync(); Assert.True(order.IsSuccess); Assert.True(order.Orders.Any()); Assert.Null(order.ErrorMessage); }
public async Task GetAllOrdersAsyncTest() { var options = new DbContextOptionsBuilder <OrdersDbContext>() .UseInMemoryDatabase(nameof(GetAllOrdersAsyncTest)) .Options; var dbContext = new OrdersDbContext(options); CreateOrders(dbContext); var orderProfile = new OrderProfile(); var configuration = new MapperConfiguration(config => config.AddProfile(orderProfile)); var mapper = new Mapper(configuration); var ordersProvider = new OrdersProvider(dbContext, null, mapper); var orders = await ordersProvider.GetOrdersAsync(1); Assert.IsNotNull(orders.Orders); Assert.IsTrue(orders.IsSuccess); Assert.IsNull(orders.ErrorMessage); }
public async Task GetAllOrdersWdInvalidId() { var options = new DbContextOptionsBuilder <OrdersDbContext>() .UseInMemoryDatabase(nameof(GetAllOrdersWdValidId)) .Options; var dbContext = new OrdersDbContext(options); SeedData(dbContext); var ordersProfile = new OrderProfile(); var configuration = new MapperConfiguration(cfg => cfg.AddProfile(ordersProfile)); var mapper = new Mapper(configuration); var ordersProvider = new OrdersProvider(dbContext, null, mapper); var results = await ordersProvider.GetOrdersAsync(-1); Assert.False(results.IsSuccess); Assert.Null(results.Orders); Assert.NotNull(results.ErrorMessage); }
public async Task GetOrdersReturnsAllOrdersByCustomerId() { var options = new DbContextOptionsBuilder <OrderDbContext>() .UseInMemoryDatabase(nameof(GetOrdersReturnsAllOrdersByCustomerId)) .Options; var dbContext = new OrderDbContext(options); //Mock Object for the mapper var orderProfile = new OrderProfile(); var configuration = new MapperConfiguration(cfg => cfg.AddProfile(orderProfile)); var mapper = new Mapper(configuration); var ordersProvider = new OrdersProvider(dbContext, null, mapper); var order = await ordersProvider.GetOrdersAsync(1); Assert.True(order.IsSuccess); Assert.True(order.Orders.Any()); Assert.Null(order.ErrorMessage); }
/// <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); } }
public TTOrder(OrderProfile op) { //m_orderKey = op.SiteOrderKey; m_orderProfile = op; m_order = null; }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Event notification for order book download complete. </summary> //////////////////////////////////////////////////////////////////////////////////////////////////// void m_algoTradeSubscription_OrderBookDownload(object sender, OrderBookDownloadEventArgs e) { Console.WriteLine("Orderbook downloaded..."); //To retrieve the list of parameters valid for the Algo you can call //algo.AlgoParameters; //For an Iceberg Synthetic order here is the list of parameters you can set. /*************************************************************************** * Strategy: TT_Iceberg *************************************************************************** * ---------------------------------------------------------------------------------------------- * ORDER PROFILE PROPERTIES * Name Type Required Updateable * ---------------------------------------------------------------------------------------------- * OrderInstrumentID true false * OrderQty true true * OrderSide true false * OrderAccount true false * OrderType true false * LimitPrice true true * * * ---------------------------------------------------------------------------------------------------------------------- * USER PARAMETER PROPERTIES * Name Type Required Updateable Algo Specific Enum * ----------------------------------------------------------------------------------------------------------------------- * ChildTIF Int_t true false * ParentTIF Int_t true false tt_net_sdk.tt_iceberg.ParentTIF * DiscVal Qty_t true true * DiscValType Int_t true true tt_net_sdk.tt_iceberg.DiscValType * Variance Int_t false false * LimitTicksAway Int_t false true * LimitPriceType Int_t false false tt_net_sdk.tt_iceberg.LimitPriceType * TriggerType Int_t false false tt_net_sdk.tt_iceberg.TriggerType * TriggerPriceType Int_t false false tt_net_sdk.tt_iceberg.TriggerPriceType * IsTrlTrg Boolean_t false false * TriggerTicksAway Int_t false true * WithATickType Int_t false false tt_net_sdk.tt_iceberg.WithATickType * WithATick Qty_t false true * STime UTCTimestamp_t false true * ETime UTCTimestamp_t false true * ETimeAct Int_t false false tt_net_sdk.tt_iceberg.ETimeAct * AutoResubExpiredGTD Boolean_t false false * ----------------------------------------------------------------------------------------------------------------------- */ // Get the accounts m_accounts = m_api.Accounts; //Construct a dictionary of the parameters and the values to send out Dictionary <string, object> iceberg_userparams = new Dictionary <string, object> { { "DiscVal", 5 }, { "DiscValType", tt_net_sdk.tt_iceberg.DiscValType.Qty }, { "ChildTIF", tt_net_sdk.TimeInForce.Day }, { "ParentTIF", tt_net_sdk.tt_iceberg.ParentTIF.Day }, { "ETimeAct", tt_net_sdk.tt_iceberg.ETimeAct.Cancel }, { "STime", EpochTimeUtc(30) }, { "ETime", EpochTimeUtc(60) }, }; var lines = iceberg_userparams.Select(kvp => kvp.Key + ": " + kvp.Value.ToString()); Console.WriteLine(string.Join(Environment.NewLine, lines)); OrderProfile iceberg_op = m_algo.GetOrderProfile(m_instrument); iceberg_op.LimitPrice = m_price; if (m_accounts.Count > 0) { iceberg_op.Account = m_accounts.ElementAt(0); } iceberg_op.Side = OrderSide.Buy; iceberg_op.OrderType = OrderType.Limit; iceberg_op.OrderQuantity = Quantity.FromDecimal(m_instrument, 10); iceberg_op.TimeInForce = TimeInForce.Day; iceberg_op.UserParameters = iceberg_userparams; iceberg_op.UserTag = "IcebergAlgoUsertag"; iceberg_op.OrderTag = "IcebergAlgoOrderTag"; m_algoTradeSubscription.SendOrder(iceberg_op); }
/// <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> /// 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(); } } }
private string LimitOrMarketPrice(OrderProfile orderProfile) { return(orderProfile.OrderType == OrderType.Limit ? orderProfile.LimitPrice.ToString() : "Market Price"); }
/// <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); } }