コード例 #1
0
ファイル: KTAIB.cs プロジェクト: junwin/TradingTools
        private void modifyOrder(KaiTrade.Interfaces.IMessage msg)
        {
            KaiTrade.Interfaces.IModifyOrderRequst mod = null;
            try
            {
                mod = JsonConvert.DeserializeObject<K2DataObjects.ModifyOrderRequest>(msg.Data);
                // Extract the raw FIX Message from the inbound message
                string strOrder = msg.Data;

                KaiTrade.Interfaces.IFill fill = new K2DataObjects.Fill();
                fill.OrderStatus = KaiTrade.Interfaces.OrderStatus.REPLACED;
                fill.ExecType = KaiTrade.Interfaces.ExecType.ORDER_STATUS;
                fill.OrderID = DriverBase.Identities.Instance.getNextOrderID();

                if (mod.ClOrdID.Length == 0)
                {

                    sendCancelReplaceRej(mod, KaiTrade.Interfaces.CxlRejReason.UnknownOrder, "a clordid must be specified on a modify order");
                    Exception myE = new Exception("a clordid must be specified on a modify order");
                    throw myE;
                }

                if (mod.OrigClOrdID.Length == 0)
                {
                    sendCancelReplaceRej(mod, KaiTrade.Interfaces.CxlRejReason.UnknownOrder, "a original clordid must be specified on a modify order");
                    Exception myE = new Exception("an original clordid must be specified on a modify order");
                    throw myE;
                }

                int myIBOrderID = 0;

                    DriverBase.OrderContext myCntx = GetOrderContextClID(mod.OrigClOrdID);
                    if (myCntx == null)
                    {
                        throw new Exception("Cannot locate order context on modify request");
                    }
                    // record the context against the incomming request
                    RecordOrderContext(mod.ClOrdID, myCntx);

                // get the contract
                TWSLib.IContract myContract = getIBContract(myCntx.QFOrder);
                if (myContract == null)
                {
                    this.SendAdvisoryMessage("IB TWS: cannot find a valid contract");
                    throw new Exception("IB TWS: cannot find a valid contract");
                }

                // create an IB Order
                TWSLib.IOrder myIBOrder = m_Host.TWS.createOrder();

                myIBOrder.whatIf = 0;
                myIBOrder.account = myCntx.OriginalOrder.Account;

                if (myCntx.OriginalOrder.OrdType == KaiTrade.Interfaces.OrderType.LIMIT)
                {
                    myIBOrder.orderType = "LMT";
                }
                else if (myCntx.OriginalOrder.OrdType == KaiTrade.Interfaces.OrderType.MARKET)
                {
                    myIBOrder.orderType = "MKT";
                }
                else
                {
                    this.SendAdvisoryMessage("IB TWS: order type not supported");
                    throw new Exception("IB TWS: order type not supported");
                }

                myIBOrder.totalQuantity = (int)myCntx.OriginalOrder.OrderQty;

                // Side
                string myAction = myCntx.OriginalOrder.Side;
                myIBOrder.action = myAction;

                // Time in force
                string myTIF = myCntx.OriginalOrder.TimeInForce;
                myIBOrder.timeInForce = myTIF;

                if (myCntx.OriginalOrder.OrdType == KaiTrade.Interfaces.OrderType.LIMIT)
                {
                    myIBOrder.lmtPrice = myCntx.Price;
                }

                myCntx.ClOrdID = mod.ClOrdID;
                //int myIBOrderID = 0;
                myIBOrderID = int.Parse(myCntx.APIOrderID);

                m_Host.TWS.placeOrderEx(myIBOrderID, myContract, myIBOrder);
            }
            catch (Exception myE)
            {
                sendCancelReplaceRej(mod, KaiTrade.Interfaces.CxlRejReason.Other, myE.Message);

                _log.Error("modifyOrder", myE);
                _log.Error("modifyOrder:req:"+msg.Data);
            }
        }
コード例 #2
0
ファイル: KTASimulator.cs プロジェクト: junwin/TradingTools
        /// <summary>
        /// FIX loop back order 
        /// </summary>
        /// <param name="msg"></param>
        public void submitOrder(KaiTrade.Interfaces.IMessage myMsg)
        {
            KaiTrade.Interfaces.ISubmitRequest nos = null;
            try
            {
                nos = JsonConvert.DeserializeObject<K2DataObjects.SubmitRequest>(myMsg.Data);

                log.Error("SUBTEST:" + myMsg.Data);

                long quantity = nos.OrderQty;
                decimal myOrdPrice = nos.Price.Value;

                // Get the we want to order
                string myMnemonic = nos.Mnemonic;

                if (nos.SecurityID != null)
                {
                    if (nos.SecurityID.Length > 0)
                    {
                        // is this new market processing?
                        if (m_Markets.ContainsKey(nos.SecurityID))
                        {
                            m_Markets[nos.SecurityID].submitOrder(myMsg);
                            return;
                        }
                    }
                }

                SimulatorProduct myProd = getProduct( myMnemonic);

                if (myProd == null)
                {
                    // we dont simulate this so reject it
                    string myError = "Product not available";
                    Exception myE = new Exception(myError);
                    throw myE;
                }

                // simulate rejecting certail accounts
                if (nos.Account.Length>0)
                {
                    if (nos.Account == "TestBadAccount")
                    {
                        // we dont simulate this so reject it
                        string myError = "Account not valid:" + nos.Account;
                        Exception myE = new Exception(myError);
                        throw myE;
                    }
                }

                // put this into the internal book
                // send order in book exec report
                KaiTrade.Interfaces.IFill fill = new K2DataObjects.Fill();
                fill.OrderStatus = KaiTrade.Interfaces.OrderStatus.NEW;
                fill.ExecType = KaiTrade.Interfaces.ExecType.ORDER_STATUS;
                fill.OrderID = DriverBase.Identities.Instance.getNextOrderID();
                //sendExecReport(string orderID, string status, string execType, double lastQty, int leavesQty,int cumQty, double lastPx, double avePx, string text, string ordRejReason)

                if (myProd.IsAutoFill)
                {
                    DriverBase.OrderContext myContext = new DriverBase.OrderContext();
                    //myContext.QFOrder = myOrder;
                    myContext.ClOrdID = nos.ClOrdID;
                    myContext.OrderID = fill.OrderID;
                    myContext.OrderQty =(int) quantity;
                    //myContext.LeavesQty = quantity;
                    myContext.CumQty = 0;
                    // record the order in the context maps
                    RecordOrderContext(myContext.ClOrdID, myContext);
                    //m_OrderContextClOrdID.Add(myContext.ClOrdID, myContext);
                    m_OrderContextOrdID.Add(myContext.OrderID, myContext);

                    sendExecReport(myContext, fill.OrderID, fill.OrderStatus, fill.ExecType, 0.0, (int)quantity, 0, (double)myOrdPrice, (double)myOrdPrice, "", "");
                    if ((nos.OrdType == KaiTrade.Interfaces.OrderType.STOP) || (nos.OrdType == KaiTrade.Interfaces.OrderType.STOPLIMIT))
                    {
                        // Just do the default
                    }
                    else
                    {

                        // is this for auto fill over time?
                        if (nos.Mnemonic == "HPQ")
                        {
                            myContext.FillPattern = DriverBase.fillPattern.gradual;
                            myContext.UpdatePeriod = 1;
                            m_FillList.Add(myContext);
                        }
                        // is this for auto fill over time?
                        if (nos.Mnemonic == "VOD")
                        {
                            myContext.FillPattern = DriverBase.fillPattern.fixedAmount;
                            int fillAmount =(int) ( (double)quantity * 0.5);
                            if (fillAmount > 0)
                            {
                                myContext.TargetFillAmount = fillAmount;
                            }
                            else
                            {
                                myContext.TargetFillAmount = 1;
                            }

                            myContext.UpdatePeriod = 12;
                            myContext.TimerCount = 1;
                            m_FillList.Add(myContext);
                        }
                    }
                }
                else
                {
                    // put this into the internal book
                    // send order in book exec report
                    if (myOrdPrice == (decimal)0.0)
                    {
                        myOrdPrice = (decimal) this.getTradePx(myMnemonic);
                    }

                    // do nothing for now just let is stay working
                    DriverBase.OrderContext myContext = new DriverBase.OrderContext();
                    //myContext.QFOrder = myOrder;
                    myContext.ClOrdID = nos.ClOrdID;
                    myContext.OrderID = fill.OrderID;
                    myContext.OrderQty = (int)nos.OrderQty;
                    //myContext.LeavesQty = quantity;
                    myContext.CumQty = 0;

                    // record the order in the context maps
                    RecordOrderContext(myContext.ClOrdID, myContext);
                    //m_OrderContextClOrdID.Add(myContext.ClOrdID, myContext);
                    m_OrderContextOrdID.Add(myContext.OrderID, myContext);

                    sendExecReport(myContext, fill.OrderID, fill.OrderStatus, fill.ExecType, 0.0, (int)nos.OrderQty, 0, 0.0, 0.0,"","");

                    // do some simple STOP processing
                    if ((nos.OrdType == KaiTrade.Interfaces.OrderType.STOP) || (nos.OrdType == KaiTrade.Interfaces.OrderType.STOPLIMIT))
                    {

                    }
                    else
                    {

                        // is this for auto fill over time?
                        if (nos.Mnemonic == "MRK")
                        {
                            // partial fill
                            int lastQty = 1;

                            int leavesQty = 0;
                            if (quantity > 1)
                            {
                                lastQty = (int)(quantity / 2);

                                leavesQty = (int)quantity - lastQty;
                                quantity = (int)(quantity / 2);
                            }

                            fill.OrderStatus = KaiTrade.Interfaces.OrderStatus.PARTIALLY_FILLED;
                            fill.ExecType = KaiTrade.Interfaces.ExecType.PARTIAL_FILL;
                            sendExecReport(myContext, fill.OrderID, fill.OrderStatus, fill.ExecType, (double)lastQty, leavesQty, lastQty, (double)myOrdPrice, (double)myOrdPrice,"", "");

                            myContext.OrderQty = (int)nos.OrderQty;
                           // myContext.LeavesQty = quantity;
                            myContext.CumQty = 0;

                            // record the order in the context maps
                            RecordOrderContext(myContext.ClOrdID, myContext);
                            //m_OrderContextClOrdID.Add(myContext.ClOrdID, myContext);
                            m_OrderContextOrdID.Add(myContext.OrderID, myContext);

                        }
                        else if (nos.Mnemonic == "ZSELL")
                        {
                            int lastQty = 1;

                            int leavesQty = 0;
                            if (!m_ZSELLTrigger)
                            {
                                m_ZSELLTrigger = true;
                                // partial fill

                                if (quantity > 1)
                                {
                                    lastQty = (int)(quantity / 2);

                                    leavesQty = (int)quantity - lastQty;
                                    quantity = (int)(quantity / 2);
                                }

                                fill.OrderStatus = KaiTrade.Interfaces.OrderStatus.PARTIALLY_FILLED;
                                fill.ExecType = KaiTrade.Interfaces.ExecType.PARTIAL_FILL;

                            }
                            else
                            {
                                m_ZSELLTrigger = false;
                                lastQty = (int)(quantity);

                                leavesQty = 0;
                                fill.OrderStatus = KaiTrade.Interfaces.OrderStatus.PARTIALLY_FILLED;
                                fill.ExecType = KaiTrade.Interfaces.ExecType.PARTIAL_FILL;

                            }
                            sendExecReport(myContext, fill.OrderID, fill.OrderStatus, fill.ExecType, (double)lastQty, leavesQty, lastQty, (double)myOrdPrice, (double)myOrdPrice, "", "");

                            myContext.OrderQty = (int)quantity;
                            //myContext.LeavesQty = quantity;
                            myContext.CumQty = 0;

                            // record the order in the context maps
                            RecordOrderContext(myContext.ClOrdID, myContext);
                            //m_OrderContextClOrdID.Add(myContext.ClOrdID, myContext);
                            m_OrderContextOrdID.Add(myContext.OrderID, myContext);
                        }
                        else if ((nos.Mnemonic == "ZBUY") && (nos.Side == KaiTrade.Interfaces.Side.SELL))
                        {
                            int lastQty = 1;

                            int leavesQty = 0;
                            if (!m_ZBUYTrigger)
                            {
                                m_ZBUYTrigger = true;
                                // partial fill

                                if (quantity > 1)
                                {
                                    lastQty = (int)(quantity / 2);

                                    leavesQty = (int)quantity - lastQty;
                                    quantity = (int)(quantity / 2);
                                }

                                fill.OrderStatus = KaiTrade.Interfaces.OrderStatus.PARTIALLY_FILLED;
                                fill.ExecType = KaiTrade.Interfaces.ExecType.PARTIAL_FILL;
                            }
                            else
                            {
                                m_ZBUYTrigger = false;
                                lastQty = (int)(quantity);

                                leavesQty = 0;
                                fill.OrderStatus = KaiTrade.Interfaces.OrderStatus.FILLED;
                                fill.ExecType = KaiTrade.Interfaces.ExecType.FILL;

                            }

                            sendExecReport(myContext, fill.OrderID, fill.OrderStatus, fill.ExecType, (double)lastQty, leavesQty, lastQty, (double)myOrdPrice, (double)myOrdPrice, "", "");

                            myContext.OrderQty = (int) quantity;
                            //myContext.LeavesQty = quantity;
                            myContext.CumQty = 0;

                            // record the order in the context maps
                            RecordOrderContext(myContext.ClOrdID, myContext);
                            //m_OrderContextClOrdID.Add(myContext.ClOrdID, myContext);
                            m_OrderContextOrdID.Add(myContext.OrderID, myContext);
                        }
                        else
                        {
                            // fully fill
                             fill.OrderStatus = KaiTrade.Interfaces.OrderStatus.FILLED;
                             fill.ExecType = KaiTrade.Interfaces.ExecType.FILL;
                            sendExecReport(myContext, fill.OrderID, fill.OrderStatus, fill.ExecType, (double)quantity, 0, (int)quantity, (double)myOrdPrice, (double)myOrdPrice, "", "");

                        }
                    }

                }

            }
            catch (Exception myE)
            {
                log.Error("submitOrder", myE);
                // To provide the end user with more information
                // send an advisory message, again this is optional
                // and depends on the adpater
                SendAdvisoryMessage("KTA Simulator:submitOrder: problem submitting order:" + myE.ToString());

                if (nos != null)
                {
                    sendExecReport(nos, KaiTrade.Interfaces.OrderStatus.REJECTED, KaiTrade.Interfaces.ExecType.REJECTED, myE.ToString(), "OTHER");

                }

            }
        }
コード例 #3
0
ファイル: KTAIB.cs プロジェクト: junwin/TradingTools
        /// <summary>
        /// Pull an order using the IB TWS api
        /// </summary>
        /// <param name="myMsg"></param>
        private void pullOrder(KaiTrade.Interfaces.IMessage myMsg)
        {
            KaiTrade.Interfaces.ICancelOrderRequest cancel = null;
            try
            {

                cancel = JsonConvert.DeserializeObject<K2DataObjects.CancelOrderRequest>(msg.Data);

                KaiTrade.Interfaces.IFill fill = new K2DataObjects.Fill();
                fill.OrderStatus = KaiTrade.Interfaces.OrderStatus.CANCELED;
                fill.ExecType = KaiTrade.Interfaces.ExecType.ORDER_STATUS;
                fill.OrderID = DriverBase.Identities.Instance.getNextOrderID();

                if (cancel.ClOrdID.Length == 0)
                {
                    sendCancelRej(cancel, KaiTrade.Interfaces.CxlRejReason.UnknownOrder, "a clordid must be specified on a modify order");
                    Exception myE = new Exception("a clordid must be specified on a modify order");
                    throw myE;
                }

                if (cancel.OrigClOrdID.Length == 0)
                {
                    sendCancelRej(cancel, KaiTrade.Interfaces.CxlRejReason.UnknownOrder, "a original clordid must be specified on a modify order");
                    Exception myE = new Exception("an original clordid must be specified on a modify order");
                    throw myE;
                }

               try
               {

                   DriverBase.OrderContext myCntx;

                   // if the origClORdID is set then use that else use the
                   // ClOrdID

                       myCntx = GetOrderContextClID(cancel.OrigClOrdID);
                       if (myCntx == null)
                       {
                           throw new Exception("Cannot locate order context on cancel request");
                       }
                       // record the context against the incomming request
                       RecordOrderContext(myClOrdID.getValue(), myCntx);

                    int myIBOrderID = 0;
                    myIBOrderID = int.Parse(myCntx.APIOrderID);

                    // Cancel the order
                    m_Host.TWS.cancelOrder(myIBOrderID);

                }
                catch (Exception myE)
                {
                    // cancel failed so reject the cancel request
                    _log.Error("pullOrder", myE);
                    if (myPull != null)
                    {
                        sendCancelRej(myPull, QuickFix.CxlRejReason.OTHER, myE.Message);
                    }
                }

            }
            catch (Exception myE)
            {
                _log.Error("pullOrder", myE);
            }
        }
コード例 #4
0
ファイル: KTASimulator.cs プロジェクト: junwin/TradingTools
        /// <summary>
        /// Modify an order 
        /// </summary>
        /// <param name="msg"></param>
        public void modifyOrder(KaiTrade.Interfaces.IMessage msg)
        {
            KaiTrade.Interfaces.IModifyOrderRequst mod = null;
            try
            {
                mod = JsonConvert.DeserializeObject<K2DataObjects.ModifyOrderRequest>(msg.Data);
                // Extract the raw FIX Message from the inbound message
                string strOrder = msg.Data;

                KaiTrade.Interfaces.IFill fill = new K2DataObjects.Fill();
                fill.OrderStatus = KaiTrade.Interfaces.OrderStatus.REPLACED;
                fill.ExecType = KaiTrade.Interfaces.ExecType.ORDER_STATUS;
                fill.OrderID = DriverBase.Identities.Instance.getNextOrderID();

                if (mod.ClOrdID.Length == 0)
                {

                    sendCancelReplaceRej(mod, KaiTrade.Interfaces.CxlRejReason.UnknownOrder, "a clordid must be specified on a modify order");
                    Exception myE = new Exception("a clordid must be specified on a modify order");
                    throw myE;
                }

                if (mod.OrigClOrdID.Length == 0)
                {
                    sendCancelReplaceRej(mod, KaiTrade.Interfaces.CxlRejReason.UnknownOrder, "a original clordid must be specified on a modify order");
                    Exception myE = new Exception("an original clordid must be specified on a modify order");
                    throw myE;
                }

                // is this new market processing?

                    if (m_Markets.ContainsKey(mod.Mnemonic))
                    {
                        m_Markets[mod.Mnemonic].modifyOrder(msg);
                        return;
                    }

                // Get the context - we must have this to access the CQG order
                DriverBase.OrderContext myContext = null;
                if (_clOrdIDOrderMap.ContainsKey(mod.OrigClOrdID))
                {
                    myContext = _clOrdIDOrderMap[mod.OrigClOrdID];
                }
                if (myContext == null)
                {
                    sendCancelReplaceRej(mod, KaiTrade.Interfaces.CxlRejReason.UnknownOrder, "an order does not exist for the modify requested");
                    Exception myE = new Exception("an order does not exist for the modify requested");
                    throw myE;
                }

                // modify the limit price
                if (mod.Price.HasValue)
                {
                    myContext.Price = (decimal)mod.Price.Value;
                }

                // modify the stop price
                if (mod.StopPrice.HasValue)
                {
                    myContext.StopPrice = (decimal)mod.StopPrice.Value;
                }

                // modify the qtyqty
                if (mod.Qty.HasValue)
                {
                    myContext.OrderQty = (int)mod.Qty.Value;

                }

                // update the ClOrdID's on our order in the context
                myContext.ClOrdID = mod.ClOrdID;
                myContext.OrigClOrdID = mod.OrigClOrdID;

                // record the context against the new clordid
                _clOrdIDOrderMap.Add(mod.ClOrdID, myContext);

                // send order in book exec report
                sendExecReport(myContext, fill.OrderID, fill.OrderStatus, fill.ExecType, 0.0, (int)myContext.LeavesQty, myContext.CumQty, 0.0, 0.0, "", "");

            }
            catch (Exception myE)
            {

                Log.Error("modifyOrder", myE);
                // To provide the end user with more information
                // send an advisory message, again this is optional
                // and depends on the adpater
                SendAdvisoryMessage("modifyOrder: problem modify order:" + myE.ToString());

            }
        }
コード例 #5
0
ファイル: KTASimulator.cs プロジェクト: junwin/TradingTools
        /// <summary>
        /// Example code of pulling an order - used for testing 
        /// </summary>
        /// <param name="msg"></param>
        public void pullOrder(KaiTrade.Interfaces.IMessage msg)
        {
            KaiTrade.Interfaces.ICancelOrderRequest cancel = null;
            try
            {
                cancel = JsonConvert.DeserializeObject<K2DataObjects.CancelOrderRequest>(msg.Data);

                KaiTrade.Interfaces.IFill fill = new K2DataObjects.Fill();
                fill.OrderStatus = KaiTrade.Interfaces.OrderStatus.CANCELED;
                fill.ExecType = KaiTrade.Interfaces.ExecType.ORDER_STATUS;
                fill.OrderID = DriverBase.Identities.Instance.getNextOrderID();

                if (cancel.ClOrdID.Length == 0)
                {
                    sendCancelRej(cancel, KaiTrade.Interfaces.CxlRejReason.UnknownOrder, "a clordid must be specified on a modify order");
                    Exception myE = new Exception("a clordid must be specified on a modify order");
                    throw myE;
                }

                if (cancel.OrigClOrdID.Length == 0)
                {
                    sendCancelRej(cancel, KaiTrade.Interfaces.CxlRejReason.UnknownOrder, "a original clordid must be specified on a modify order");
                    Exception myE = new Exception("an original clordid must be specified on a modify order");
                    throw myE;
                }

                string strOrder = msg.Data;

                if (m_Markets.ContainsKey(cancel.Mnemonic))
                {
                    m_Markets[cancel.Mnemonic].pullOrder(msg);
                    return;
                }

                // Get the context - we must have this to access the CQG order
                DriverBase.OrderContext myContext = null;
                if (_clOrdIDOrderMap.ContainsKey(cancel.OrigClOrdID))
                {
                    myContext = _clOrdIDOrderMap[cancel.OrigClOrdID];
                }
                if (myContext == null)
                {
                    sendCancelRej(cancel, KaiTrade.Interfaces.CxlRejReason.UnknownOrder, "an order does not exist for the cancel requested");
                    Exception myE = new Exception("an order does not exist for the cancel requested");
                    throw myE;
                }

                double myAveFillPrice = 0.0;

                myContext.ClOrdID = cancel.ClOrdID;
                myContext.OrigClOrdID = cancel.OrigClOrdID;

                // send order cancelled exec report
                sendExecReport(myContext, fill.OrderID, fill.OrderStatus, fill.ExecType, 0.0, (int)myContext.LeavesQty, myContext.CumQty, 0.0, 0.0, "", "");

                myContext.OrdStatus = fill.OrderStatus;

                throw new Exception("Delete the order from the simulator");

            }
            catch (Exception myE)
            {

                Log.Error("pullOrder", myE);
                // To provide the end user with more information
                // send an advisory message, again this is optional
                // and depends on the adpater
                SendAdvisoryMessage("pullOrder: problem pulling order:" + myE.ToString());

            }
        }
コード例 #6
0
ファイル: KTASimulator.cs プロジェクト: junwin/TradingTools
        public void fixedAmountFill(DriverBase.OrderContext myContext, int qtyToFill, decimal? fillPx)
        {
            try
            {
                // send order in book exec report
                // fully fill
                KaiTrade.Interfaces.IFill fill = new K2DataObjects.Fill();
                fill.ClOrdID = myContext.ClOrdID;

                fill.OrderID = myContext.OrderID;
                if (fillPx.HasValue)
                {
                    fill.LastPx = (double)fillPx.Value;
                }
                else
                {
                    fill.LastPx = (double)myContext.Price;
                }
                fill.AvgPx = 0;

                if (myContext.LeavesQty > 0)
                {

                    if (myContext.LeavesQty > qtyToFill)
                    {
                        fill.OrderStatus = KaiTrade.Interfaces.OrderStatus.PARTIALLY_FILLED;
                        fill.ExecType = KaiTrade.Interfaces.ExecType.PARTIAL_FILL;
                        fill.FillQty = qtyToFill;
                        myContext.CumQty += qtyToFill;
                        fill.CumQty = myContext.CumQty;

                    }
                    else
                    {
                        fill.OrderStatus = KaiTrade.Interfaces.OrderStatus.FILLED;
                        fill.ExecType = KaiTrade.Interfaces.ExecType.FILL;

                        double myQty = myContext.LeavesQty;
                        myContext.CumQty += (int)myQty;
                        fill.FillQty = myContext.LeavesQty;
                        fill.CumQty = myContext.CumQty;

                    }
                    fill.LeavesQty = myContext.LeavesQty;
                    sendExecReport(fill);
                }
            }
            catch (Exception myE)
            {
                log.Error("gradualFill", myE);
            }
        }
コード例 #7
0
ファイル: KTASimulator.cs プロジェクト: junwin/TradingTools
        /// <summary>
        /// Modify an order 
        /// </summary>
        /// <param name="msg"></param>
        public override OrderReplaceResult modifyOrder(DriverBase.ModifyRequestData replaceData)
        {
            try
            {

                // Get the context - we must have this to access the  order
                if (replaceData.Price.HasValue)
                {
                    replaceData.OrderContext.Price = (decimal)replaceData.Price.Value;
                }

                if (replaceData.StopPrice.HasValue)
                {
                    replaceData.OrderContext.StopPrice = (decimal)replaceData.StopPrice.Value;
                }

                // modify the qty
                if (replaceData.qty.HasValue)
                {
                    replaceData.OrderContext.OrderQty = (int)replaceData.qty.Value;
                    // force the leaves qty for the purpose of a simple simulation
                    //myContext.LeavesQty = (int)newOrderQty.getValue();
                }

                // record the context against the new clordid
                //RecordOrderContext(replaceData.ClOrdID, replaceData.OrderContext);
                //m_OrderContextClOrdID.Add(replaceData.ClOrdID, replaceData.OrderContext);

                // send order in book exec report
                // fully fill
                KaiTrade.Interfaces.IFill fill = new K2DataObjects.Fill();
                fill.OrderStatus = KaiTrade.Interfaces.OrderStatus.REPLACED;
                fill.ExecType = KaiTrade.Interfaces.ExecType.ORDER_STATUS;
                fill.OrderID = replaceData.OrderContext.OrderID;
                fill.LastPx = 0;
                fill.AvgPx = 0;

                sendExecReport(replaceData.OrderContext, fill.OrderID, fill.OrderStatus, fill.ExecType, 0.0, replaceData.OrderContext.LeavesQty, replaceData.OrderContext.CumQty,fill.LastPx,fill.AvgPx ,"", "");

                if (replaceData.Price.HasValue)
                {
                    if (replaceData.Price.Value == 100)
                    {
                        m_FillList.Add(replaceData.OrderContext);
                    }
                }

                return OrderReplaceResult.success;
            }
            catch (Exception myE)
            {

                log.Error("modifyOrderRD", myE);
                // To provide the end user with more information
                // send an advisory message, again this is optional
                // and depends on the adpater
                SendAdvisoryMessage("SIM:modifyOrderRD: problem modify order:" + myE.ToString());
                return OrderReplaceResult.error;
            }
        }
コード例 #8
0
ファイル: Market.cs プロジェクト: junwin/TradingTools
        /// <summary>
        /// FIX loop back order 
        /// </summary>
        /// <param name="msg"></param>
        public void submitOrder(KaiTrade.Interfaces.IMessage myMsg)
        {
            KaiTrade.Interfaces.ISubmitRequest nos = null;
            try
            {
                m_Parent.Log.Error("SUBTEST:" + myMsg.Data);
                nos = JsonConvert.DeserializeObject<K2DataObjects.SubmitRequest>(myMsg.Data);

                int quantity = (int)nos.OrderQty;

                decimal myOrdPrice = 99;
                if (nos.Price.HasValue)
                {

                    myOrdPrice = nos.Price.Value;
                }

                KaiTrade.Interfaces.IFill fill = new K2DataObjects.Fill();
                fill.OrderStatus = KaiTrade.Interfaces.OrderStatus.NEW;
                fill.ExecType = KaiTrade.Interfaces.ExecType.ORDER_STATUS;
                fill.OrderID = DriverBase.Identities.Instance.getNextOrderID();

                DriverBase.OrderContext myContext = new DriverBase.OrderContext();
                //myContext.QFOrder = myOrder;
                myContext.ClOrdID = nos.ClOrdID;
                myContext.OrderID = fill.OrderID;
                myContext.OrderQty = quantity;
                //myContext.LeavesQty = quantity;
                myContext.CumQty = 0;
                myContext.Price = myOrdPrice;
                myContext.Side = nos.Side;
                myContext.OrderType = nos.OrdType;
                // record the order in the context maps
                m_OrderContextClOrdID.Add(myContext.ClOrdID, myContext);
                m_OrderContextOrdID.Add(myContext.OrderID, myContext);
                myContext.OrdStatus = fill.OrderStatus;

                m_Parent.sendExecReport(myContext, fill.OrderID, fill.OrderStatus, fill.ExecType, 0.0, (int)nos.OrderQty, 0, 0.0, 0.0, "", "");

            }
            catch (Exception myE)
            {
                m_Parent.log.Error("submitOrder", myE);
                // To provide the end user with more information
                // send an advisory message, again this is optional
                // and depends on the adpater
                m_Parent.SendAdvisoryMessage("KTA Simulator:submitOrder: problem submitting order:" + myE.ToString());

                if (nos != null)
                {
                    m_Parent.sendExecReport(nos, KaiTrade.Interfaces.OrderStatus.REJECTED, KaiTrade.Interfaces.ExecType.REJECTED, myE.ToString(), "OTHER");

                }
            }
        }
コード例 #9
0
ファイル: DriverBase.cs プロジェクト: junwin/TradingTools
        public void sendExecReport(KaiTrade.Interfaces.ISubmitRequest nos, string status, string execType, string text, string ordRejReason)
        {

            K2DataObjects.Fill fill = new K2DataObjects.Fill();
            if (nos.ClOrdID != null)
            {
                fill.ClOrdID = nos.ClOrdID;
            }      
            fill.OrderID = "";
            fill.OrderStatus = status;
            fill.ExecType = execType;
            fill.FillQty = 0;
            fill.LeavesQty = 0;
            fill.CumQty = 0;
            fill.LastPx = 0.0;
            fill.AvgPx = 0.0;
            fill.Text = text;
            fill.OrdRejReason = ordRejReason;

            sendExecReport(fill);

        }
コード例 #10
0
ファイル: DriverBase.cs プロジェクト: junwin/TradingTools
        public void sendExecReport(OrderContext myCntx, string orderID, string status, string execType, double lastQty, int leavesQty, int cumQty, double lastPx, double avePx)
        {
            myCntx.OrdStatus = status;
            myCntx.ExecType = execType;
            myCntx.LastAveragePrice = avePx;
            K2DataObjects.Fill fill = new K2DataObjects.Fill();
            fill.OrderID = orderID;
            fill.OrderStatus = status;
            fill.ExecType = execType;
            fill.FillQty = lastQty;
            fill.LeavesQty = leavesQty;
            fill.CumQty = cumQty;
            fill.LastPx = lastPx;
            fill.AvgPx = avePx;

            sendExecReport(fill);

        }
コード例 #11
0
ファイル: DriverBase.cs プロジェクト: junwin/TradingTools
 public void sendExecReport(string orderID, string status, string execType, double lastQty, int leavesQty,int cumQty, double lastPx, double avePx, string text, string ordRejReason)
 {
     try
     {
         
         K2DataObjects.Fill fill = new K2DataObjects.Fill();
         fill.OrderID = orderID;
         fill.OrderStatus = status;
         fill.ExecType = execType;
         fill.FillQty = lastQty;
         fill.LeavesQty = leavesQty;
         fill.CumQty = cumQty;
         fill.LastPx = lastPx;
         fill.AvgPx = avePx;
         fill.Text = text;
         fill.OrdRejReason = ordRejReason;
     }
     catch (Exception myE)
     {
         log.Error("sendExecReport", myE);
     }
 }
コード例 #12
0
ファイル: DriverBase.cs プロジェクト: junwin/TradingTools
 public void sendExecReport(OrderContext context, string orderID, string status, string execType, double lastQty, int leavesQty, int cumQty, double lastPx, double avePx, string text, string ordRejReason)
 {
     K2DataObjects.Fill fill = new K2DataObjects.Fill();
     fill.OrderID = orderID;
     fill.ClOrdID = context.ClOrdID;
     fill.OrigClOrdID = context.OrigClOrdID;
     fill.OrderStatus = status;
     fill.ExecType = execType;
     fill.FillQty = lastQty;
     fill.LeavesQty = leavesQty;
     fill.CumQty = cumQty;
     fill.LastPx = lastPx;
     fill.AvgPx = avePx;
     fill.Text = text;
     fill.OrdRejReason = ordRejReason;
     sendExecReport(fill);
 }