public static void ReplaceOrder(OrderID orderID, ClOrdID clOrdID, decimal price, OrdType ordType, TimeInForce timeInForce, Symbol symbol,
                                        OrderQty orderQty, Side side, ExpireTime expireTime, Account account, decimal?slippage)
        {
            QuickFix44.OrderCancelReplaceRequest message = new QuickFix44.OrderCancelReplaceRequest(
                new OrigClOrdID(clOrdID.getValue()),
                clOrdID,
                side,
                new TransactTime(DateTime.UtcNow),
                ordType);

            message.set(orderID);
            message.set(new Price((double)price));
            message.set(timeInForce);
            message.set(symbol);
            message.set(orderQty);

            if (expireTime != null)
            {
                message.set(expireTime);
            }
            if (account != null)
            {
                message.set(account);
            }
            if (slippage.HasValue)
            {
                message.setDouble(7011, (double)slippage.Value);
            }

            Credential dukascopyCredential = CredentialFactory.GetCredential(Counterpart.Dukascopy);

            Session.sendToTarget(message, dukascopyCredential.TradingSenderCompID, dukascopyCredential.TradingTargetCompID);
        }
        public override string ToString()
        {
            var t = Container.NewTitleBuilder();

            t.Append(OrderQty.ToString()).Append(" x", Product);
            return(t.ToString());
        }
Beispiel #3
0
        public void OnMessage(QuickFix.FIX43.NewOrderSingle n, SessionID s)
        {
            Symbol   symbol   = n.Symbol;
            Side     side     = n.Side;
            OrdType  ordType  = n.OrdType;
            OrderQty orderQty = n.OrderQty;
            Price    price    = new Price(DEFAULT_MARKET_PRICE);
            ClOrdID  clOrdID  = n.ClOrdID;

            switch (ordType.getValue())
            {
            case OrdType.LIMIT:
                price = n.Price;
                if (price.Obj == 0)
                {
                    throw new IncorrectTagValue(price.Tag);
                }
                break;

            case OrdType.MARKET: break;

            default: throw new IncorrectTagValue(ordType.Tag);
            }

            QuickFix.FIX43.ExecutionReport exReport = new QuickFix.FIX43.ExecutionReport(
                new OrderID(GenOrderID()),
                new ExecID(GenExecID()),
                new ExecType(ExecType.FILL),
                new OrdStatus(OrdStatus.FILLED),
                symbol, // Shouldn't be here?
                side,
                new LeavesQty(0),
                new CumQty(orderQty.getValue()),
                new AvgPx(price.getValue()));

            exReport.Set(clOrdID);
            exReport.Set(symbol);
            exReport.Set(orderQty);
            exReport.Set(new LastQty(orderQty.getValue()));
            exReport.Set(new LastPx(price.getValue()));

            if (n.IsSetAccount())
            {
                exReport.SetField(n.Account);
            }

            try
            {
                Session.SendToTarget(exReport, s);
            }
            catch (SessionNotFound ex)
            {
                Console.WriteLine("==session not found exception!==");
                Console.WriteLine(ex.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Beispiel #4
0
 protected void ProcessOrder(
     Price price,
     OrderQty quantity,
     Account account)
 {
     //...
 }
 private void MinQty_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         OrderQty.Focus();
     }
 }
Beispiel #6
0
        public void OnMessage(QuickFix.FIX44.NewOrderSingle n, SessionID s)
        {
            Symbol   symbol   = n.Symbol;
            Side     side     = n.Side;
            OrdType  ordType  = n.OrdType;
            OrderQty orderQty = n.OrderQty;
            Price    price    = n.Price;
            ClOrdID  clOrdID  = n.ClOrdID;

            if (ordType.getValue() != OrdType.LIMIT)
            {
                throw new IncorrectTagValue(ordType.Tag);
            }

            QuickFix.FIX44.ExecutionReport exReport = new QuickFix.FIX44.ExecutionReport(
                new OrderID(GenOrderID()),
                new ExecID(GenExecID()),
                new ExecType(ExecType.FILL),
                new OrdStatus(OrdStatus.FILLED),
                symbol, //shouldn't be here?
                side,
                new LeavesQty(0),
                new CumQty(orderQty.getValue()),
                new AvgPx(price.getValue()));

            exReport.Set(clOrdID);
            exReport.Set(symbol);
            exReport.Set(orderQty);
            exReport.Set(new LastQty(orderQty.getValue()));
            exReport.Set(new LastPx(price.getValue()));

            if (n.IsSetAccount())
            {
                exReport.SetField(n.Account);
            }

            try
            {
                Session.SendToTarget(exReport, s);
            }
            catch (SessionNotFound ex)
            {
                Console.WriteLine("==session not found exception!==");
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("==unknown exception==");
                Console.WriteLine(ex.ToString());
                Console.WriteLine(ex.StackTrace);
            }
        }
Beispiel #7
0
        public override void onMessage(QuickFix42.NewOrderSingle order, SessionID sessionID)
        {
            Symbol   symbol   = new Symbol();
            Side     side     = new Side();
            OrdType  ordType  = new OrdType();
            OrderQty orderQty = new OrderQty();
            Price    price    = new Price();
            ClOrdID  clOrdID  = new ClOrdID();

            order.get(ordType);

            if (ordType.getValue() != OrdType.LIMIT)
            {
                throw new IncorrectTagValue(ordType.getField());
            }

            order.get(symbol);
            order.get(side);
            order.get(orderQty);
            order.get(price);
            order.get(clOrdID);

            QuickFix42.ExecutionReport executionReport = new QuickFix42.ExecutionReport
                                                             (genOrderID(),
                                                             genExecID(),
                                                             new ExecTransType(ExecTransType.NEW),
                                                             new ExecType(ExecType.FILL),
                                                             new OrdStatus(OrdStatus.FILLED),
                                                             symbol,
                                                             side,
                                                             new LeavesQty(0),
                                                             new CumQty(orderQty.getValue()),
                                                             new AvgPx(price.getValue()));

            executionReport.set(clOrdID);
            executionReport.set(orderQty);
            executionReport.set(new LastShares(orderQty.getValue()));
            executionReport.set(new LastPx(price.getValue()));

            if (order.isSetAccount())
            {
                executionReport.set(order.getAccount());
            }

            try
            {
                Session.sendToTarget(executionReport, sessionID);
            }
            catch (SessionNotFound) {}
        }
        private void SendAck(NewOrderSingle newOrderSingle)
        {
            var      exReport = new QuickFix.FIX42.ExecutionReport();
            OrderQty orderQty = newOrderSingle.OrderQty;

            exReport.CopyFromOrder(newOrderSingle);
            exReport.Set(new OrderID(GenOrderID()));
            exReport.Set(new ExecID(GenExecID()));
            exReport.Set(new ExecTransType(ExecTransType.NEW));
            exReport.Set(new ExecType(ExecType.NEW));
            exReport.Set(new OrdStatus(OrdStatus.NEW));
            exReport.Set(new LeavesQty(orderQty.getValue()));
            exReport.Set(new CumQty(0));
            exReport.Set(new AvgPx(0));

            SendExecReport(exReport);
        }
Beispiel #9
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hash = 17;
         hash = hash * 23 + (DueDate == default(DateTime) ? 0 : DueDate.GetHashCode());
         hash = hash * 23 + (EndDate == null ? 0 : EndDate.GetHashCode());
         hash = hash * 23 + (ModifiedDate == default(DateTime) ? 0 : ModifiedDate.GetHashCode());
         hash = hash * 23 + (OrderQty == default(int) ? 0 : OrderQty.GetHashCode());
         hash = hash * 23 + (ProductId == default(int) ? 0 : ProductId.GetHashCode());
         hash = hash * 23 + (ScrappedQty == default(short) ? 0 : ScrappedQty.GetHashCode());
         hash = hash * 23 + (ScrapReasonId == null ? 0 : ScrapReasonId.GetHashCode());
         hash = hash * 23 + (StartDate == default(DateTime) ? 0 : StartDate.GetHashCode());
         hash = hash * 23 + (StockedQty == default(int) ? 0 : StockedQty.GetHashCode());
         return(hash);
     }
 }
Beispiel #10
0
        public void OnMessage(QuickFix.FIX44.NewOrderSingle n, SessionID s)
        {
            Symbol   symbol   = n.Symbol;
            Side     side     = n.Side;
            OrdType  ordType  = n.OrdType;
            OrderQty orderQty = n.OrderQty;
            Price    price    = new Price(DEFAULT_MARKET_PRICE);
            ClOrdID  clOrdID  = n.ClOrdID;

            switch (ordType.getValue())
            {
            case OrdType.LIMIT:
                price = n.Price;
                if (price.Obj == 0)
                {
                    throw new IncorrectTagValue(price.Tag);
                }
                break;

            case OrdType.MARKET: break;

            default: throw new IncorrectTagValue(ordType.Tag);
            }

            // Send Status New
            SendExecution(s, OrdStatus.NEW, ExecType.NEW, n, n.OrderQty.getValue(), 0, 0, 0, 0);
            Thread.Sleep(1000);

            // Send Status Partially Filled
            decimal filledQty = Math.Abs(Math.Round(n.OrderQty.getValue() / 4, 2));
            decimal cumQty    = filledQty;

            SendExecution(s, OrdStatus.PARTIALLY_FILLED, ExecType.PARTIAL_FILL, n, filledQty, filledQty, price.getValue(), filledQty, price.getValue());
            Thread.Sleep(1000);

            // Send Status Partially Filled
            filledQty = Math.Abs(Math.Round(n.OrderQty.getValue() / 4, 2));
            cumQty   += filledQty;
            SendExecution(s, OrdStatus.PARTIALLY_FILLED, ExecType.PARTIAL_FILL, n, n.OrderQty.getValue() - cumQty, cumQty, price.getValue(), filledQty, price.getValue());
            Thread.Sleep(1000);

            // Send Status Fully Filled
            filledQty = n.OrderQty.getValue() - cumQty;
            cumQty   += filledQty;
            SendExecution(s, OrdStatus.FILLED, ExecType.FILL, n, 0, cumQty, price.getValue(), filledQty, price.getValue());
        }
Beispiel #11
0
        public void OnMessage(QuickFix.FIX44.NewOrderSingle ord, SessionID sessionID)
        {
            Symbol   symbol   = ord.Symbol;
            Side     side     = ord.Side;
            OrdType  ordType  = ord.OrdType;
            OrderQty orderQty = ord.OrderQty;
            Price    price    = new Price(10);
            //q isso?
            ClOrdID clOrdID = ord.ClOrdID;

            QuickFix.FIX44.ExecutionReport exReport = new QuickFix.FIX44.ExecutionReport(
                new OrderID(GenOrderID()),
                new ExecID(GenExecID()),
                new ExecType(ExecType.FILL),
                new OrdStatus(OrdStatus.FILLED),
                symbol,
                side,
                new LeavesQty(0),
                new CumQty(orderQty.getValue()),
                new AvgPx(price.getValue())
                );
            exReport.ClOrdID  = clOrdID;
            exReport.Symbol   = symbol;
            exReport.OrderQty = orderQty;
            exReport.LastQty  = new LastQty(orderQty.getValue());
            exReport.LastPx   = new LastPx(price.getValue());

            if (ord.IsSetAccount())
            {
                exReport.Account = ord.Account;
            }
            try
            {
                Session.SendToTarget(exReport, sessionID);
            }
            catch (SessionNotFound ex)
            {
                Console.WriteLine("==session not found exception!==");
                Console.WriteLine(ex.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
 public override int GetHashCode()
 {
     unchecked
     {
         int hash = 17;
         hash = hash * 23 + (DueDate == default(DateTime) ? 0 : DueDate.GetHashCode());
         hash = hash * 23 + (LineTotal == default(decimal) ? 0 : LineTotal.GetHashCode());
         hash = hash * 23 + (ModifiedDate == default(DateTime) ? 0 : ModifiedDate.GetHashCode());
         hash = hash * 23 + (OrderQty == default(short) ? 0 : OrderQty.GetHashCode());
         hash = hash * 23 + (ProductId == default(int) ? 0 : ProductId.GetHashCode());
         hash = hash * 23 + (PurchaseOrderId == default(int) ? 0 : PurchaseOrderId.GetHashCode());
         hash = hash * 23 + (ReceivedQty == default(decimal) ? 0 : ReceivedQty.GetHashCode());
         hash = hash * 23 + (RejectedQty == default(decimal) ? 0 : RejectedQty.GetHashCode());
         hash = hash * 23 + (StockedQty == default(decimal) ? 0 : StockedQty.GetHashCode());
         hash = hash * 23 + (UnitPrice == default(decimal) ? 0 : UnitPrice.GetHashCode());
         return(hash);
     }
 }
 public override int GetHashCode()
 {
     unchecked
     {
         int hash = 17;
         hash = hash * 23 + (CarrierTrackingNumber == null ? 0 : CarrierTrackingNumber.GetHashCode());
         hash = hash * 23 + (LineTotal == default(decimal) ? 0 : LineTotal.GetHashCode());
         hash = hash * 23 + (ModifiedDate == default(DateTime) ? 0 : ModifiedDate.GetHashCode());
         hash = hash * 23 + (OrderQty == default(short) ? 0 : OrderQty.GetHashCode());
         hash = hash * 23 + (ProductId == default(int) ? 0 : ProductId.GetHashCode());
         hash = hash * 23 + (Rowguid == default(Guid) ? 0 : Rowguid.GetHashCode());
         hash = hash * 23 + (SalesOrderId == default(int) ? 0 : SalesOrderId.GetHashCode());
         hash = hash * 23 + (SpecialOfferId == default(int) ? 0 : SpecialOfferId.GetHashCode());
         hash = hash * 23 + (UnitPrice == default(decimal) ? 0 : UnitPrice.GetHashCode());
         hash = hash * 23 + (UnitPriceDiscount == default(decimal) ? 0 : UnitPriceDiscount.GetHashCode());
         return(hash);
     }
 }
Beispiel #14
0
  public override void onMessage( QuickFix40.NewOrderSingle order, SessionID sessionID )
  {
    Symbol symbol = new Symbol();
    Side side = new Side();
    OrdType ordType = new OrdType();
    OrderQty orderQty = new OrderQty();
    Price price = new Price();
    ClOrdID clOrdID = new ClOrdID();

    order.get( ordType );

    if ( ordType.getValue() != OrdType.LIMIT )
      throw new IncorrectTagValue( ordType.getField() );

    order.get( symbol );
    order.get( side );
    order.get( orderQty );
    order.get( price );
    order.get( clOrdID );

    QuickFix40.ExecutionReport executionReport = new QuickFix40.ExecutionReport
        ( genOrderID(),
          genExecID(),
          new ExecTransType( ExecTransType.NEW ),
          new OrdStatus ( OrdStatus.FILLED ),
          symbol,
          side,
          orderQty,
          new LastShares ( orderQty.getValue() ),
          new LastPx ( price.getValue() ),
          new CumQty ( orderQty.getValue() ),
          new AvgPx ( price.getValue() ) );

    executionReport.set( clOrdID );

    if( order.isSetAccount() )
      executionReport.set( order.getAccount() );

    try
    {
      Session.sendToTarget( executionReport, sessionID );
    }
    catch ( SessionNotFound ) {}
  }
        private static Order Convert(MessageType commandType,
                                     Symbol symbol,
                                     Side side,
                                     OrdType ordType,
                                     OrderQty orderQty,
                                     Price price,
                                     ClOrdID clOrdId,
                                     Account account)
        {
            switch (ordType.getValue())
            {
            case OrdType.LIMIT:
                if (price.Obj == 0)
                {
                    throw new IncorrectTagValue(price.Tag);
                }

                break;

            //case OrdType.MARKET: break;

            default:
                throw new IncorrectTagValue(ordType.Tag);
            }
            var orderId = DIContainer.ResolveByName <IdGenerator>("OrderIdGenerator").GenerateId();

            return(new Order
            {
                CommandType = commandType,
                OrderId = orderId,
                OrderSide = FixFieldsConverter.Convert(side),
                Asset = new Asset(symbol.getValue()),
                OrderType = FixFieldsConverter.Convert(ordType),
                Quantity = orderQty.getValue(),
                Price = price.getValue(),
                ClOrdId = clOrdId.getValue(),
                Account =
                    account == null
                            ? TradingAccount.None
                            : new TradingAccount(account.getValue())
            });
        }
Beispiel #16
0
        /// <summary>
        /// Returns the string presentation of the object
        /// </summary>
        /// <returns>String presentation of the object</returns>
        public override string ToString()
        {
            var sb = new System.Text.StringBuilder();

            sb.Append("class OrderResponse {\n");
            sb.Append("  OrderID: ").Append(OrderId.ToString()).Append("\n");
            sb.Append("  ClOrdID: ").Append(ClOrdId.ToString()).Append("\n");
            sb.Append("  ClOrdLinkID: ").Append(ClOrdLinkId.ToString()).Append("\n");
            sb.Append("  Account: ").Append(Account.ToString()).Append("\n");
            sb.Append("  Symbol: ").Append(Symbol.ToString()).Append("\n");
            sb.Append("  Side: ").Append(Side.ToString()).Append("\n");
            sb.Append("  OrderQty: ").Append(OrderQty.ToString()).Append("\n");
            sb.Append("  Price: ").Append(Price.ToString()).Append("\n");
            sb.Append("  DisplayQty: ").Append((DisplayQty == null) ? "null" : DisplayQty.ToString()).Append("\n");
            sb.Append("  StopPx: ").Append((StopPx == null) ? "null" : StopPx.ToString()).Append("\n");
            sb.Append("  PegOffsetValue: ").Append((PegOffsetValue == null) ? "null" : PegOffsetValue.ToString()).Append("\n");
            sb.Append("  PegPriceType: ").Append((PegPriceType == null) ? "null" : PegPriceType.ToString()).Append("\n");
            sb.Append("  Currency: ").Append((Currency == null) ? "null" : Currency.ToString()).Append("\n");
            sb.Append("  SettlCurrency: ").Append((SettlCurrency == null) ? "null" : SettlCurrency.ToString()).Append("\n");
            sb.Append("  OrdType: ").Append((OrdType == null) ? "null" : OrdType.ToString()).Append("\n");
            sb.Append("  TimeInForce: ").Append((TimeInForce == null) ? "null" : TimeInForce.ToString()).Append("\n");
            sb.Append("  ExecInst: ").Append((ExecInst == null) ? "null" : ExecInst.ToString()).Append("\n");
            sb.Append("  ContingencyType: ").Append((ContingencyType == null) ? "null" : ContingencyType.ToString()).Append("\n");
            sb.Append("  ExDestination: ").Append((ExDestination == null) ? "null" : ExDestination.ToString()).Append("\n");
            sb.Append("  OrdStatus: ").Append((OrdStatus == null) ? "null" : OrdStatus.ToString()).Append("\n");
            sb.Append("  Triggered: ").Append((Triggered == null) ? "null" : Triggered.ToString()).Append("\n");
            sb.Append("  WorkingIndicator: ").Append((WorkingIndicator == null) ? "null" : WorkingIndicator.ToString()).Append("\n");
            sb.Append("  OrdRejReason: ").Append((OrdRejReason == null) ? "null" : OrdRejReason.ToString()).Append("\n");
            sb.Append("  LeavesQty: ").Append((LeavesQty == null) ? "null" : LeavesQty.ToString()).Append("\n");
            sb.Append("  CumQty: ").Append((CumQty == null) ? "null" : CumQty.ToString()).Append("\n");
            sb.Append("  AvgPx: ").Append((AvgPx == null) ? "null" : AvgPx.ToString()).Append("\n");
            sb.Append("  MultiLegReportingType: ").Append((MultiLegReportingType == null) ? "null" : MultiLegReportingType.ToString()).Append("\n");
            sb.Append("  Text: ").Append((Text == null) ? "null" : Text.ToString()).Append("\n");
            sb.Append("  TransactTime: ").Append(TransactTime.ToString()).Append("\n");
            sb.Append("  Timestamp: ").Append(Timestamp.ToString()).Append("\n");
            sb.Append("}\n");
            return(sb.ToString());
        }
Beispiel #17
0
        private static OrderData TranslateOrderImpl(Symbol symbol,
                                                    Side side,
                                                    OrdType ordType,
                                                    OrderQty orderQty,
                                                    Price price,
                                                    ClOrdID clOrdID,
                                                    Account account)
        {
            switch (ordType.getValue())
            {
            case OrdType.LIMIT:
                if (price.Obj == 0)
                {
                    throw new IncorrectTagValue(price.Tag);
                }

                break;

            //case OrdType.MARKET: break;

            default:
                throw new IncorrectTagValue(ordType.Tag);
            }

            return(new OrderData
            {
                MarketSide = TranslateFixFields.Translate(side),
                Symbol = symbol.getValue(),
                OrderType = TranslateFixFields.Translate(ordType),
                Quantity = orderQty.getValue(),
                Price = price.getValue(),
                ClOrdID = clOrdID.getValue(),
                Account =
                    account == null
                            ? TradingAccount.None
                            : new TradingAccount(account.getValue())
            });
        }
Beispiel #18
0
        public int PrintLimitList()
        {
            Symbol   sym = new Symbol();
            Side     sd  = new Side();
            OrderQty oq  = new OrderQty();

            Console.WriteLine("      Index\tOrderID");
            int count = 0;

            foreach (string strOrdId in LimitOrders)
            {
                QuickFix42.Message msg = Msgs[strOrdId];

                msg.getField(sym);
                msg.getField(sd);
                msg.getField(oq);

                Console.WriteLine("\t" + count + "\t" + strOrdId + "\t" + sym + " " + sd + " " + oq);
                count++;
            }

            return(count);
        }
 /// <summary>
 /// 验证是否可以保存
 /// </summary>
 private bool Verification()
 {
     if (order != null && selectprocess.ProcessID != null && User != null && Qty > 1)
     {
         if ((Qty + Sum) > decimal.Parse(OrderQty.ToString()))
         {
             ZhuifengLib.MessageShow.Message.MessageInfo("录入数量不能大于工单总批量!");
             return(false);
         }
         else if (Qty > selectprocess.OnceQty)
         {
             ZhuifengLib.MessageShow.Message.MessageInfo("录入数量不能大于单次录入限制数" + selectprocess.OnceQty);
             return(false);
         }
         else
         {
             return(true);
         }
     }
     else
     {
         return(false);
     }
 }
        private void SendExecReport(NewOrderSingle newOrderSingle, IExecutionEngineSettings settings)
        {
            OrdType ordType = newOrderSingle.OrdType;
            Price   price   = new Price(10);

            switch (ordType.getValue())
            {
            case OrdType.LIMIT:
                price = newOrderSingle.Price;
                if (price.Obj == 0)
                {
                    throw new IncorrectTagValue(price.Tag);
                }
                break;

            case OrdType.MARKET:
                break;

            default:
                throw new IncorrectTagValue(ordType.Tag);
            }

            OrderQty orderQty = newOrderSingle.OrderQty;
            var      exReport = new QuickFix.FIX42.ExecutionReport();

            exReport.CopyFromOrder(newOrderSingle);
            exReport.Set(new ExecTransType(ExecTransType.NEW));
            exReport.Set(new ExecType(ExecType.FILL));
            exReport.Set(new LastPx(price.getValue()));
            exReport.Set(new AvgPx(price.getValue()));

            decimal qtyPerSlice = orderQty.getValue() *
                                  ((settings.EachFillPercentange ?? 100) / 100m);

            decimal leaves = orderQty.getValue();
            decimal cumQty = 0;

            while (leaves != 0)
            {
                if (leaves <= qtyPerSlice)
                {
                    leaves      = 0;
                    qtyPerSlice = leaves;
                    exReport.Set(new OrdStatus(OrdStatus.FILLED));
                }
                else
                {
                    leaves -= qtyPerSlice;
                    exReport.Set(new OrdStatus(OrdStatus.PARTIALLY_FILLED));
                }

                cumQty += qtyPerSlice;
                exReport.Set(new OrderID(GenOrderID()));
                exReport.Set(new ExecID(GenExecID()));

                exReport.Set(new LeavesQty(leaves));
                exReport.Set(new CumQty(cumQty));

                exReport.Set(new LastShares(qtyPerSlice));
                SendExecReport(exReport);
                Thread.Sleep(Convert.ToInt32(settings.SecondsBetweenFills * 1000));
            }
        }
Beispiel #21
0
        public Message NewOrder(MDEntryGroup entryGroup, double quantity)
        {
            bool isInvertedSecurity = entryGroup.OwnerEntry.IsInverted;
            Message message = null;
            Account account = new Account(GetOrderSession().getSenderCompID().ToLower());

            ClOrdID clOrdId = new ClOrdID("ClOrd_" + Guid.NewGuid());
            HandlInst handlInst = new HandlInst(HandlInst.AUTOMATED_EXECUTION_ORDER_PRIVATE_NO_BROKER_INTERVENTION);
            OrdType ordType = new OrdType(OrdType.LIMIT);
            TimeInForce timeInForce = new TimeInForce(TimeInForce.FILL_OR_KILL);
            TransactTime transactTime = new TransactTime();

            Price price = new Price(entryGroup.MDEntryPx);
            SecurityExchange securityExchange = new SecurityExchange(entryGroup.OwnerEntry.SecurityExchange);
            SecurityType securityType = new SecurityType(entryGroup.OwnerEntry.SecurityType);
            Symbol symbol = new Symbol(entryGroup.OwnerEntry.Symbol);
            SecurityID securityId = new SecurityID(entryGroup.OwnerEntry.SecurityID);
            OrderQty orderQty = new OrderQty(quantity);

            Side side = null;
            switch (entryGroup.MDEntryType)
            {
                case MDEntryType.BID:
                    side = new Side(Side.SELL);
                    break;
                case MDEntryType.OFFER:
                    side = new Side(Side.BUY);
                    break;
                default:
                    throw new Exception("Undefined entry type.");
            }

            //if (isInvertedSecurity && side.getValue() == Side.BUY)
            //    price = new Price(-price.getValue());

            message = new QuickFix42.NewOrderSingle();

            ((QuickFix42.NewOrderSingle) message).set(account);

            ((QuickFix42.NewOrderSingle) message).set(clOrdId);
            ((QuickFix42.NewOrderSingle) message).set(side);
            ((QuickFix42.NewOrderSingle) message).set(transactTime);
            ((QuickFix42.NewOrderSingle) message).set(ordType);

            ((QuickFix42.NewOrderSingle) message).set(price);
            ((QuickFix42.NewOrderSingle) message).set(orderQty);
            ((QuickFix42.NewOrderSingle) message).set(securityId);
            ((QuickFix42.NewOrderSingle) message).set(securityExchange);
            ((QuickFix42.NewOrderSingle) message).set(timeInForce);

            ((QuickFix42.NewOrderSingle) message).set(securityType);

            return message;
        }
        protected void CreateDetail(string strPO)
        {
            string         sqlCmdDMSource, sqlCmdDMTarget, sqlCommandRel;
            SqlDataReader  srcDataReader, tgtDataReader, relDataReader, outerDR;
            SqlConnection  scDMTarget = new SqlConnection(ConfigurationManager.ConnectionStrings["DMTargetConnectionString"].ConnectionString);
            SqlConnection  scDMSource = new SqlConnection(ConfigurationManager.ConnectionStrings["DMSourceConnectionString"].ConnectionString);
            SqlCommand     tgtCommand, relCommand;
            SqlTransaction srcTransaction;
            bool           hasComponents = false;
            bool           Replacement   = false;
            bool           Fallback      = false;
            bool           HasDetail     = false;
            string         strComponent;
            string         GCOrder   = "";
            string         Line      = "";
            string         LastLine  = "";
            string         OrderLine = "";
            string         Description;
            string         Item;
            string         itemLookup;
            string         Warehouse;
            decimal        OrderQty;
            string         CurrentPO;
            string         OriginalPO;
            string         LastPO = "";

            scDMTarget.Open();
            scDMSource.Open();

            OriginalPO = strPO;
            // Create a list of the possible PO/Replacement POs

            // 7/15/2020 changing loop from ONLY distinct purchase orders to all fields.
            // sqlCmdDMTarget = string.Concat("SELECT distinct(PBPONO) from POBCLBP where (PBVEND=", VendorList, ") and ((PBPONO='", strPO, "') or (PBORPO='", strPO, "'))");

            sqlCmdDMTarget = string.Concat("SELECT * from POBCLBP where (PBVEND=", VendorList, ") and ((PBPONO='", strPO, "') or (PBORPO='", strPO, "')) Order By PBORPO, PBORLN, PBPONO, PBLINE");
            SqlCommand command = new SqlCommand(sqlCmdDMTarget, scDMTarget);

            outerDR = command.ExecuteReader();
            if (!outerDR.HasRows)
            {
                // Only occurs if there is no detail for the PO and no replacement POs
                lblMessage.Text = "This PO cannot be located.";
            }
            else
            {
                // Mark having detail as false, will update when we find some
                while (outerDR.Read())
                {
                    Item = "";
                    Line = "";

                    CurrentPO   = outerDR["PBPONO"].ToString();
                    Replacement = (string.Compare(CurrentPO, strPO) != 0) ? true : false;

                    // Read necessary fields from AS400 Detail
                    if (Replacement)
                    {
                        Line = outerDR["PBORLN"].ToString();
                        // Line = srcDataReader["PDOLIN"].ToString();
                    }
                    else
                    {
                        Line = outerDR["PBLINE"].ToString();
                        // Line = srcDataReader["PDLINE"].ToString();
                    }

                    // Move to the next record if we are processing the PO line
                    if ((string.Compare(Line, LastLine) == 0) & (string.Compare(LastPO, CurrentPO) == 0))
                    {
                        continue;
                    }
                    LastLine  = Line;
                    LastPO    = CurrentPO;
                    OrderLine = outerDR["PBLINE"].ToString();
                    Item      = outerDR["PBITEM"].ToString();

                    // Pull this specific line from the order detail file
                    sqlCmdDMTarget = string.Concat("SELECT * from POORDDP where (PDPONO = '", CurrentPO, "') and (PDLINE= '", OrderLine, "') and (PDITEM <> '')");
                    command        = new SqlCommand(sqlCmdDMTarget, scDMTarget);
                    srcDataReader  = command.ExecuteReader();
                    if (srcDataReader.HasRows)
                    {
                        HasDetail = true;

                        // Begin a SQL transaction
                        srcTransaction = scDMSource.BeginTransaction();
                        try
                        {
                            while (srcDataReader.Read())
                            {
                                string DetailItem;
                                Description = "";
                                OrderQty    = 0;

                                Fallback   = false;
                                itemLookup = "";

                                OrderQty    = (decimal)srcDataReader["PDORQY"];
                                Description = srcDataReader["PDDESC"].ToString();
                                Warehouse   = srcDataReader["PDWHSI"].ToString();
                                DetailItem  = srcDataReader["PDITEM"].ToString();

                                // First step is to cross reference the vendor for this Item against ICITMBP
                                string sVen1 = "";
                                sqlCommandRel = string.Concat("Select * from ICITMBP where IBCONO=1 and IBITEM='", DetailItem, "' and IBWHSI='", Warehouse, "'");
                                relCommand    = new SqlCommand(sqlCommandRel, scDMTarget);
                                relDataReader = relCommand.ExecuteReader();
                                if (relDataReader.HasRows)
                                {
                                    relDataReader.Read();
                                    sVen1 = relDataReader["IBVEN1"].ToString();
                                }
                                relDataReader.Close();
                                // If the Vendor for this item isn't the current vendor, move to the next item from the detail
                                if (string.Compare(sVen1, VendorList) != 0)
                                {
                                    continue;
                                }

                                // Specific to Global Contract
                                // Check if this row is a Item or Component
                                // Next check in GCORDHP
                                sqlCommandRel = string.Concat("Select * from GCORDHP where CUSPON in ('", OriginalPO, "', '", string.Concat(strPO, "-RT"), "')");
                                relCommand    = new SqlCommand(sqlCommandRel, scDMTarget);
                                relDataReader = relCommand.ExecuteReader();


                                if (relDataReader.HasRows)
                                {
                                    hasComponents = true;
                                    relDataReader.Read();
                                    GCOrder = relDataReader["OrdNo"].ToString();
                                    relDataReader.Close();

                                    // Get the detail for this particular line
                                    sqlCommandRel = string.Concat("Select * from GCORDDP where ORDNO='", GCOrder, "' and [LineNo]=", Line);
                                    relCommand    = new SqlCommand(sqlCommandRel, scDMTarget);
                                    relDataReader = relCommand.ExecuteReader();
                                    if (relDataReader.HasRows)
                                    {
                                        // Get the product # for lookup
                                        relDataReader.Read();
                                        itemLookup = relDataReader["PRODNO"].ToString();
                                        relDataReader.Close();
                                    }
                                    else
                                    {
                                        relDataReader.Close();
                                        Fallback = true;
                                    }
                                }
                                else
                                {
                                    relDataReader.Close();
                                    Fallback = true;
                                }

                                // Not in GC's files, check the patterns of LP, HP, etc.
                                if (Fallback)
                                {
                                    string ItemList;
                                    itemLookup    = Item.Trim();
                                    ItemList      = string.Concat(" In ('", itemLookup, "', '", string.Concat(itemLookup, "LP"), "', '", string.Concat(itemLookup, "HP"), "', '", string.Concat(itemLookup, "B"), "', '", string.Concat(itemLookup, "E"), "', '", string.Concat(itemLookup, "FV"), "', '", string.Concat(itemLookup, "KL"), "', '", string.Concat(itemLookup, "KV"), "', '", string.Concat(itemLookup, "W"), "')");
                                    sqlCommandRel = string.Concat("Select * from GCBMPRP where GCPROD ", ItemList, " Order by GCPROD");
                                }
                                else
                                {
                                    sqlCommandRel = string.Concat("Select * from GCBMPRP where GCPROD='", itemLookup, "'");
                                }
                                relCommand    = new SqlCommand(sqlCommandRel, scDMTarget);
                                relDataReader = relCommand.ExecuteReader();

                                if (relDataReader.HasRows)
                                {
                                    hasComponents = true;
                                }

                                // Read existing detail rows for updating
                                sqlCmdDMSource         = string.Concat("Select * from SL_Detail where (Vendor=", VendorList, ") and PO='", OriginalPO, "' and Line='", Line, "'");
                                tgtCommand             = new SqlCommand(sqlCmdDMSource, scDMSource);
                                tgtCommand.Transaction = srcTransaction;
                                tgtDataReader          = tgtCommand.ExecuteReader();
                                if (!tgtDataReader.HasRows)
                                {
                                    sqlCmdDMSource         = string.Concat("Insert into SL_Detail (Vendor, PO, Line, LineType, Item, Description, ComponentQty, BOMQty, ShipQty, PackStatus, CalcLabels) Values (", VendorList, ", '", OriginalPO, "','", Line, "','I','", Item.Trim(), "','", Description, "', 1, ", OrderQty.ToString(), ",", OrderQty.ToString(), ", 'S', 0)");
                                    tgtCommand             = new SqlCommand(sqlCmdDMSource, scDMSource);
                                    tgtCommand.Transaction = srcTransaction;
                                    tgtCommand.ExecuteNonQuery();

                                    // Component Row?  Add Components to SL_Detail
                                    if (hasComponents)
                                    {
                                        string LastItem = "", ThisItem = "";
                                        // Loop through components and add detail into SL_Detail
                                        while (relDataReader.Read())
                                        {
                                            ThisItem = (string)relDataReader["GCPROD"];
                                            if ((ThisItem == LastItem) || (LastItem == ""))
                                            {
                                                strComponent = (string)relDataReader["GCCMPN"];
                                                Description  = (string)relDataReader["GCDSC1"];
                                                decimal PartQty = (decimal)relDataReader["GCQUAN"];
                                                decimal PartVol = (decimal)relDataReader["GCVOLM"];
                                                sqlCmdDMSource         = string.Concat("Insert into SL_Detail (Vendor, PO, Line, LineType, Item, Component, Description, ComponentQty, BOMQty, ShipQty, PackStatus, CalcLabels) Values (", VendorList, ", '", OriginalPO, "','", Line, "', 'C', '", Item.Trim(), "','", strComponent, "','", Description, "',", PartQty.ToString(), ", ", (OrderQty * PartQty).ToString(), ", ", (OrderQty * PartQty).ToString(), ", 'S', 0)");
                                                tgtCommand             = new SqlCommand(sqlCmdDMSource, scDMSource);
                                                tgtCommand.Transaction = srcTransaction;
                                                tgtCommand.ExecuteNonQuery();
                                            }
                                            else
                                            {
                                                if (LastItem != "")
                                                {
                                                    break;
                                                }
                                            }
                                            LastItem = (string)relDataReader["GCPROD"];
                                        }
                                    }
                                }
                                tgtDataReader.Close();
                                relDataReader.Close();
                            }   // End While Loop
                            srcDataReader.Close();
                            srcTransaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            srcTransaction.Rollback();
                            lblMessage.Text = "Critical error generating PO detail.";
                        }
                    }
                }   // End Outer Loop
                outerDR.Close();

                // We should be finished processing
                if (!HasDetail)
                {
                    lblMessage.Text += "No detail records exist for this PO.";
                }
            }

            scDMSource.Close();
            scDMTarget.Close();
        }