public void OnReply(DataItem _data)
        {
            String typ = _data.strAgent;

            bool bDeal     = (typ == "D");
            bool bCanceled = (typ == "C");



            if (bDeal)
            {
                tBuySell dealBuySell = (_data.strBuySell[0] == 'B') ? tBuySell.Buy : tBuySell.Sell;

                //成交價
                int dealPrice = 0;
                try
                {
                    long _dp = (long.Parse(_data.strPrice));
                    if (_dp < 999999)
                    {
                        dealPrice = (int)_dp;
                    }
                }
                catch { }

                //成交數量
                int __nqty = 0;
                try { __nqty = int.Parse(_data.strQty); }
                catch { }
                if (__nqty > 0)
                {
                    nQty = __nqty;
                }


                // 剛剛送出委託
                if (g_bWaitingDeal != waitDealMode.notWaiting)
                {
                    String _t     = _data.strTime;
                    int    hour   = int.Parse(_t.Substring(0, 2));
                    int    minute = int.Parse(_t.Substring(2, 2));
                    int    second = int.Parse(_t.Substring(4, 2));

                    DateTime dealtime = new DateTime(todate.Year, todate.Month, todate.Day, hour, minute, second);
                    if (DateTime.Compare(dealtime, g_lastOrderSentTime) >= 0)
                    {
                        // Write Log
                        String strRes = "";
                        if (g_bWaitingDeal == waitDealMode.waitToBuildInventory)
                        {
                            string strInventoryTyp = "建倉";
                            if (g_CurDeposit > 0) // 加碼倉
                            {
                                strInventoryTyp = "加碼";
                            }
                            strRes = strInventoryTyp + "賣出成交 , ";
                            if (dealBuySell == tBuySell.Buy)
                            {
                                strRes = strInventoryTyp + "買進成交 , ";
                            }


                            if (g_CurDeposit > 0) // 加碼倉
                            {
                                strRes += "時間:" + g_CurTime.ToString() + " 價格:" + dealPrice.ToString();
                            }
                            else
                            {
                                strRes += "時間:" + g_CurTime.ToString() + " 價格:" + dealPrice.ToString();
                            }

                            g_LastDealPrice = dealPrice;
                            g_CurDeposit   += nQty;

                            // 建立倉位價格配對表
                            for (int k = 0; k < nQty; k++)
                            {
                                TradeInOutPrice inout = new TradeInOutPrice();
                                inout.In  = dealPrice;
                                inout.Out = 0;
                                inOutPriceList.Add(inout);
                            }
                            g_bWaitingDeal = waitDealMode.notWaiting;

                            Console.WriteLine(strRes);
                        }
                        #region 平倉
                        else if (g_bWaitingDeal == waitDealMode.waitToCleanInventory)
                        {
                            g_CurDeposit -= nQty;
                            int _cnt = 0;
                            for (int j = 0; j < inOutPriceList.Count; j++)
                            {
                                if (inOutPriceList[j].Out == 0)
                                {
                                    inOutPriceList[j].Out = dealPrice;
                                    _cnt++;
                                    if (_cnt >= nQty)
                                    {
                                        break;
                                    }
                                }
                            }
                            #region 全部平倉完畢
                            // 全部平倉完畢才統計贏的點數
                            if (g_CurDeposit == 0)
                            {
                                g_bWaitingDeal = waitDealMode.notWaiting;

                                if (dealBuySell == tBuySell.Sell) // 平倉賣出
                                {
                                    //g_todayWinPoint += (dealPrice - g_LastDealPrice) * numContractPerTrade;
                                    //if (g_CurDeposit > numContractPerTrade) // 有加碼倉
                                    //    g_todayWinPoint += (dealPrice - g_LastAddOnDealPrice) * (g_CurDeposit - numContractPerTrade);
                                    for (int j = 0; j < inOutPriceList.Count; j++)
                                    {
                                        if ((inOutPriceList[j].Out != 0) && (inOutPriceList[j].In != 0))
                                        {
                                            g_todayWinPoint += inOutPriceList[j].Out - inOutPriceList[j].In;
                                        }
                                    }


                                    switch (g_cleanUpMode)
                                    {
                                    case (cleanupMode.cleanupMode_KLEnd):
                                        strRes = "INV 分K結束平倉賣出成交 時間:" + dealtime.ToString() + " 價格:" + dealPrice.ToString() + " 賺賠:" + (g_todayWinPoint).ToString();
                                        break;

                                    case (cleanupMode.cleanupMode_DayEnd):
                                        strRes = "INV 收盤平倉賣出成交 時間:" + dealtime.ToString() + " 價格:" + dealPrice.ToString() + " 賺賠:" + (g_todayWinPoint).ToString();
                                        break;
                                    }
                                }
                                else // 平倉買進
                                {
                                    for (int j = 0; j < inOutPriceList.Count; j++)
                                    {
                                        if ((inOutPriceList[j].Out != 0) && (inOutPriceList[j].In != 0))
                                        {
                                            g_todayWinPoint += inOutPriceList[j].In - inOutPriceList[j].Out;
                                        }
                                    }

                                    switch (g_cleanUpMode)
                                    {
                                    case (cleanupMode.cleanupMode_KLEnd):
                                        strRes = "INV 分K結束平倉買進成交 時間:" + dealtime.ToString() + " 價格:" + dealPrice.ToString() + " 賺賠:" + (g_todayWinPoint).ToString();
                                        break;

                                    case (cleanupMode.cleanupMode_DayEnd):
                                        strRes = "INV 收盤平倉買進成交 時間:" + dealtime.ToString() + " 價格:" + dealPrice.ToString() + " 賺賠:" + (g_todayWinPoint).ToString();
                                        break;
                                    }
                                }

                                // 配對清單清空
                                inOutPriceList.Clear();

                                Console.WriteLine(strRes);

                                // 停損
                                if (g_todayWinPoint < -100)
                                {
                                    bDoTrading = false;
                                    Console.WriteLine("停損,今日停單");
                                }
                            }
                            #endregion
                        }
                        #endregion
                        // 成交成功,代表送出委託結束
                        bOrderSent = false;
                    }
                }
                else // 不是我送出的單,可能遭到強制平倉
                {
                    bool bReluctClean = false;

                    //買進遭到平倉賣出 or 賣出遭到平倉買進
                    if (
                        ((dealBuySell == tBuySell.Sell) && (g_b1MinTradePositive)) ||
                        ((dealBuySell == tBuySell.Buy) && (!g_b1MinTradePositive))
                        )
                    {
                        bReluctClean = true;
                    }

                    if (!bReluctClean)
                    {
                        return;
                    }

                    #region 平倉

                    g_CurDeposit -= nQty;
                    int _cnt = 0;
                    for (int j = 0; j < inOutPriceList.Count; j++)
                    {
                        if (inOutPriceList[j].Out == 0)
                        {
                            inOutPriceList[j].Out = dealPrice;
                            _cnt++;
                            if (_cnt >= nQty)
                            {
                                break;
                            }
                        }
                    }

                    if (g_CurDeposit == 0)
                    {
                        string strRes = "";
                        g_bWaitingDeal = waitDealMode.notWaiting;

                        String _t     = _data.strTime;
                        int    hour   = int.Parse(_t.Substring(0, 2));
                        int    minute = int.Parse(_t.Substring(2, 2));
                        int    second = int.Parse(_t.Substring(4, 2));

                        DateTime dealtime = new DateTime(todate.Year, todate.Month, todate.Day, hour, minute, second);

                        if (dealBuySell == tBuySell.Sell) // 平倉賣出
                        {
                            for (int j = 0; j < inOutPriceList.Count; j++)
                            {
                                if ((inOutPriceList[j].Out != 0) && (inOutPriceList[j].In != 0))
                                {
                                    g_todayWinPoint += inOutPriceList[j].Out - inOutPriceList[j].In;
                                }
                            }
                            strRes = "遭到強制平倉賣出成交 時間:" + dealtime.ToString() + " 價格:" + dealPrice.ToString() + " 賺賠:" + (g_todayWinPoint).ToString();
                        }
                        else // 平倉買進
                        {
                            for (int j = 0; j < inOutPriceList.Count; j++)
                            {
                                if ((inOutPriceList[j].Out != 0) && (inOutPriceList[j].In != 0))
                                {
                                    g_todayWinPoint += inOutPriceList[j].In - inOutPriceList[j].Out;
                                }
                            }
                            strRes = "遭到強制平倉買進成交 時間:" + dealtime.ToString() + " 價格:" + dealPrice.ToString() + " 賺賠:" + (g_todayWinPoint).ToString();
                        }

                        // 配對清單清空
                        inOutPriceList.Clear();

                        Console.WriteLine(strRes);

                        // 停損
                        if (g_todayWinPoint < -100)
                        {
                            bDoTrading = false;
                            Console.WriteLine("停損,今日停單");
                        }
                    }
                    #endregion
                }
            }
            // 被取消單,嘗試繼續送單
            if ((bCanceled) && (g_bWaitingDeal != waitDealMode.notWaiting))
            {
                bOrderSent = false;
            }
        }
        public void OnReply(DataItem _data)
        {
            String typ = _data.strAgent;

            bool bDeal = (typ == "D");
            bool bCanceled = (typ == "C");

            if (bDeal)
            {
                tBuySell dealBuySell = (_data.strBuySell[0] == 'B') ? tBuySell.Buy : tBuySell.Sell;

                //成交價
                int dealPrice = 0;
                try
                {
                    long _dp = (long.Parse(_data.strPrice));
                    if (_dp < 999999)
                        dealPrice = (int)_dp;
                }
                catch { }

                //成交數量
                int __nqty = 0;
                try { __nqty = int.Parse(_data.strQty); }
                catch { }
                if (__nqty > 0) nQty = __nqty;

                // 剛剛送出委託
                if (g_bWaitingDeal != waitDealMode.notWaiting)
                {
                    String _t = _data.strTime;
                    int hour = int.Parse(_t.Substring(0, 2));
                    int minute = int.Parse(_t.Substring(2, 2));
                    int second = int.Parse(_t.Substring(4, 2));

                    DateTime dealtime = new DateTime(todate.Year, todate.Month, todate.Day, hour, minute, second);
                    if (DateTime.Compare(dealtime, g_lastOrderSentTime) >= 0)
                    {
                        // Write Log
                        String strRes = "";
                        if (g_bWaitingDeal == waitDealMode.waitToBuildInventory)
                        {
                            string strInventoryTyp = "建倉";
                            if (g_CurDeposit > 0) // 加碼倉
                                strInventoryTyp = "加碼";
                            strRes = strInventoryTyp + "賣出成交 , ";
                            if (dealBuySell == tBuySell.Buy)
                                strRes = strInventoryTyp + "買進成交 , ";

                            if (g_CurDeposit > 0) // 加碼倉
                                strRes += "時間:" + g_CurTime.ToString() + " 價格:" + dealPrice.ToString();
                            else
                                strRes += "時間:" + g_CurTime.ToString() + " 價格:" + dealPrice.ToString();

                            g_LastDealPrice = dealPrice;
                            g_CurDeposit += nQty;

                            // 建立倉位價格配對表
                            for (int k = 0; k < nQty; k++)
                            {
                                TradeInOutPrice inout = new TradeInOutPrice();
                                inout.In = dealPrice;
                                inout.Out = 0;
                                inOutPriceList.Add(inout);
                            }
                            g_bWaitingDeal = waitDealMode.notWaiting;

                            Console.WriteLine(strRes);
                        }
                        #region 平倉
                        else if (g_bWaitingDeal == waitDealMode.waitToCleanInventory)
                        {
                            g_CurDeposit -= nQty;
                            int _cnt = 0;
                            for (int j = 0; j < inOutPriceList.Count; j++)
                            {
                                if (inOutPriceList[j].Out == 0)
                                {
                                    inOutPriceList[j].Out = dealPrice;
                                    _cnt++;
                                    if (_cnt >= nQty)
                                        break;
                                }
                            }
                            #region 全部平倉完畢
                            // 全部平倉完畢才統計贏的點數
                            if (g_CurDeposit == 0)
                            {
                                g_bWaitingDeal = waitDealMode.notWaiting;

                                if (dealBuySell == tBuySell.Sell) // 平倉賣出
                                {
                                    //g_todayWinPoint += (dealPrice - g_LastDealPrice) * numContractPerTrade;
                                    //if (g_CurDeposit > numContractPerTrade) // 有加碼倉
                                    //    g_todayWinPoint += (dealPrice - g_LastAddOnDealPrice) * (g_CurDeposit - numContractPerTrade);
                                    for (int j = 0; j < inOutPriceList.Count; j++)
                                    {
                                        if( (inOutPriceList[j].Out != 0) && (inOutPriceList[j].In != 0) )
                                        {
                                            g_todayWinPoint += inOutPriceList[j].Out - inOutPriceList[j].In;
                                        }
                                    }

                                    switch (g_cleanUpMode)
                                    {
                                        case (cleanupMode.cleanupMode_KLEnd):
                                            strRes = "INV 分K結束平倉賣出成交 時間:" + dealtime.ToString() + " 價格:" + dealPrice.ToString() + " 賺賠:" + (g_todayWinPoint ).ToString();
                                            break;
                                        case (cleanupMode.cleanupMode_DayEnd):
                                            strRes = "INV 收盤平倉賣出成交 時間:" + dealtime.ToString() + " 價格:" + dealPrice.ToString() + " 賺賠:" + (g_todayWinPoint ).ToString();
                                            break;
                                    }

                                }
                                else // 平倉買進
                                {
                                    for (int j = 0; j < inOutPriceList.Count; j++)
                                    {
                                        if ((inOutPriceList[j].Out != 0) && (inOutPriceList[j].In != 0))
                                        {
                                            g_todayWinPoint += inOutPriceList[j].In - inOutPriceList[j].Out;
                                        }
                                    }

                                    switch (g_cleanUpMode)
                                    {
                                        case (cleanupMode.cleanupMode_KLEnd):
                                            strRes = "INV 分K結束平倉買進成交 時間:" + dealtime.ToString() + " 價格:" + dealPrice.ToString() + " 賺賠:" + (g_todayWinPoint ).ToString();
                                            break;
                                        case (cleanupMode.cleanupMode_DayEnd):
                                            strRes = "INV 收盤平倉買進成交 時間:" + dealtime.ToString() + " 價格:" + dealPrice.ToString() + " 賺賠:" + (g_todayWinPoint ).ToString();
                                            break;
                                    }
                                }

                                // 配對清單清空
                                inOutPriceList.Clear();

                                Console.WriteLine(strRes);

                                // 停損
                                if (g_todayWinPoint < -100)
                                {
                                    bDoTrading = false;
                                    Console.WriteLine("停損,今日停單");
                                }
                            }
                            #endregion
                        }
                        #endregion
                        // 成交成功,代表送出委託結束
                        bOrderSent = false;
                    }
                }
                else // 不是我送出的單,可能遭到強制平倉
                {
                    bool bReluctClean = false;

                    //買進遭到平倉賣出 or 賣出遭到平倉買進
                    if (
                        ((dealBuySell == tBuySell.Sell) && (g_b1MinTradePositive)) ||
                        ((dealBuySell == tBuySell.Buy) && (!g_b1MinTradePositive))
                      )
                        bReluctClean = true;

                    if (!bReluctClean) return;

                    #region 平倉

                    g_CurDeposit -= nQty;
                    int _cnt = 0;
                    for (int j = 0; j < inOutPriceList.Count; j++)
                    {
                        if (inOutPriceList[j].Out == 0)
                        {
                            inOutPriceList[j].Out = dealPrice;
                            _cnt++;
                            if (_cnt >= nQty)
                                break;
                        }
                    }

                    if (g_CurDeposit == 0)
                    {
                        string strRes = "";
                        g_bWaitingDeal = waitDealMode.notWaiting;

                        String _t = _data.strTime;
                        int hour = int.Parse(_t.Substring(0, 2));
                        int minute = int.Parse(_t.Substring(2, 2));
                        int second = int.Parse(_t.Substring(4, 2));

                        DateTime dealtime = new DateTime(todate.Year, todate.Month, todate.Day, hour, minute, second);

                        if (dealBuySell == tBuySell.Sell) // 平倉賣出
                        {
                            for (int j = 0; j < inOutPriceList.Count; j++)
                            {
                                if ((inOutPriceList[j].Out != 0) && (inOutPriceList[j].In != 0))
                                {
                                    g_todayWinPoint += inOutPriceList[j].Out - inOutPriceList[j].In;
                                }
                            }
                                strRes = "遭到強制平倉賣出成交 時間:" + dealtime.ToString() + " 價格:" + dealPrice.ToString() + " 賺賠:" + (g_todayWinPoint).ToString();
                        }
                        else // 平倉買進
                        {
                            for (int j = 0; j < inOutPriceList.Count; j++)
                            {
                                if ((inOutPriceList[j].Out != 0) && (inOutPriceList[j].In != 0))
                                {
                                    g_todayWinPoint += inOutPriceList[j].In - inOutPriceList[j].Out;
                                }
                            }
                                strRes = "遭到強制平倉買進成交 時間:" + dealtime.ToString() + " 價格:" + dealPrice.ToString() + " 賺賠:" + (g_todayWinPoint).ToString();
                        }

                        // 配對清單清空
                        inOutPriceList.Clear();

                        Console.WriteLine(strRes);

                        // 停損
                        if (g_todayWinPoint < -100)
                        {
                            bDoTrading = false;
                            Console.WriteLine("停損,今日停單");
                        }
                    }
                    #endregion
                }
            }
            // 被取消單,嘗試繼續送單
            if ((bCanceled) && (g_bWaitingDeal != waitDealMode.notWaiting))
            {
                bOrderSent = false;
            }
        }
        // 取得未平倉部位資訊
        void OnOverseaFutureOpenInterest(string strData)
        {
            //"OSE,大阪證券交易所,F0200001709003,JNM    201503,mini大阪日經 201503,B,1,18835.00000,18815.0000,18630.00000,2000.00"
               // string strtest = "OSE,大阪證券交易所,F0200001709003,JNM    201503,mini大阪日經 201503,B,1,18835.00000,18815.0000,18630.00000,2000.00";
            if (JNAutoDayTrade_Strategy.ContainStr(strData, "OSE,"))
            {
                string[] stspl = strData.Split(',');
                bool btradePositive = stspl[5].Equals("B");
                int invCnt = int.Parse(stspl[6]);
                int lastDealPrice = int.Parse(stspl[8].Split('.')[0]);

                dayTradeSt.g_LastDealPrice = lastDealPrice;
                dayTradeSt.g_CurDeposit = invCnt;
                dayTradeSt.g_b1MinTradePositive = btradePositive;
                // 建立倉位價格配對表
                for (int k = 0; k < invCnt; k++)
                {
                    TradeInOutPrice inout = new TradeInOutPrice();
                    inout.In = lastDealPrice;
                    inout.Out = 0;
                    dayTradeSt.inOutPriceList.Add(inout);
                }
            }
        }