// Prerequisites: Variable "session" of type FIXSession. // All sessions can be enumerated from FIXEngine.Sessions // First of all, to be safe, acquire the global lock (See FIXOrderManager.SyncRoot). lock (FIXOrderManager.SyncRoot) { FIXSessionOrderManager sessionOM = FIXOrderManager.GetSessionOrderManager(session); FIXMessage newOrder = session.CreateMessage(MsgTypes.NewOrderSingle); // Or MsgTypes.NewOrderMultileg // Set symbol, e.g. "IBM" newOrder.SetValue(Tags.Symbol, "IBM"); // Add fields such as "ClOrdID", "TimeInForce", "Price", "OrderQty", "Side", "TransactTime", etc ... // This example works with FIX versions from 4.1 to 5.0. It is a perfect example of version // independent order management. // Sometimes we do need to deal with some special tags. For example: "TransactTime" is usually a // required field since FIX version 4.2+. if (newOrder.MessageSchema.GetFieldByTag(Tags.TransactTime) != null) // Tag defined in message newOrder.SetValue(Tags.TransactTime, DateTime.UtcNow); try { // Note: An exception may be thrown out. // The exception may be caused by application program error (e.g. duplicated ClOrdID); // or system error (e.g. underlying FIX session connection is down; depends on // FIXSessionOrderManagerSettings.AlwaysSendNewOrder). // See FIXSessionOrderManager.AddNewRegularOrder for more details. FIXRegularOrder order = sessionOM.AddNewRegularOrder(newOrder); // Event FIXSessionOrderManager.OrderAdded will be triggered immediately before the // method <c>AddNewRegularOrder</c> returns, within the same thread context. } catch (Exception ex) { // TODO: Your own error handling logic ... } }
This operation is thread safe.
This example works with FIX versions from 4.1 to 5.0+.