Beispiel #1
0
        //---------------------------------------------------------------------------
        public void fn_LotEnd()
        {
            m_tEndTime = DateTime.Now;

            //Lot Data Save...


            fn_WriteLog(string.Format($"[Lot End] Recipe : {m_sRecipeName} / LOT : {m_sLotNo}"), EN_LOG_TYPE.ltLot);

            m_dLotEndTime = TICK._GetTickTime();

            double dRunTotal = (double)TICK.ConvTimetoSec(m_dLotEndTime - m_dLotStartTime);

            m_sLogMsg = string.Format($"[Lot Run Time] {TICK.ConvTimeTickToStr(m_dLotEndTime - m_dLotStartTime)} / {dRunTotal} sec");
            fn_WriteLog(m_sLogMsg, EN_LOG_TYPE.ltLot);
            Console.WriteLine(m_sLogMsg);

            m_sLogMsg = string.Format($" -------------- UPH : {SPC.CalUPH(dRunTotal, 1).ToString("0.0000")} -------------- ");
            fn_WriteLog(m_sLogMsg, EN_LOG_TYPE.ltLot);
            Console.WriteLine(m_sLogMsg);

            //Clear Lot info
            m_bLotOpen    = false;
            m_sRecipeName = string.Empty;
            //m_sLotNo      = string.Empty;
        }
Beispiel #2
0
        //---------------------------------------------------------------------------
        //Slurry
        private void THREAD_PROCESS_6()
        {
            bool   bGo      = false;
            double Start    = 0;
            double Scan     = 0;
            int    nNo      = TH6;
            int    nInteval = THREAD_INTERVAL6;

            //
            try
            {
                while (m_bThreadRun[nNo])
                {
                    Thread.Sleep(1);

                    if (!bGo)
                    {
                        Start = TICK._GetTickTime();

                        m_bWatchDog[TH6] = false;

                        if (FM.m_stSystemOpt.nUseAutoSlurry == 1)
                        {
                            //Auto Supply Update
                            SUPPLY[0].fn_PlcUpdate(); //SLURRY
                            SUPPLY[1].fn_PlcUpdate(); //SOAP
                        }

                        m_bWatchDog[TH6] = true;

                        Scan = TICK._GetTickTime() - Start;
                        bGo  = true;
                        m_tDelayTimer[nNo].Clear();
                    }

                    if (Scan < nInteval)
                    {
                        if (!m_tDelayTimer[nNo].OnDelay(bGo, nInteval - Scan))
                        {
                            continue;
                        }
                    }

                    bGo = false;

                    //Scan Time Check
                    m_nScanTime [nNo] = (uint)(TICK._GetTickTime() - m_nStartTime[nNo]);
                    m_nStartTime[nNo] = (uint)TICK._GetTickTime();
                }
            }
            catch (System.Exception ex)
            {
                m_bWatchDog[TH6] = false;
                System.Diagnostics.Trace.WriteLine(ex.Message);
                LOG.ExceptionTrace("[THREAD_PROCESS_6]", ex);
            }
        }
Beispiel #3
0
        //---------------------------------------------------------------------------
        private void THREAD_PROCESS_7()
        {
            bool   bGo      = false;
            double Start    = 0;
            double Scan     = 0;
            int    idx      = TH7;
            int    interval = THREAD_INTERVAL7;

            //
            try
            {
                while (m_bThreadRun[idx])
                {
                    Thread.Sleep(1);

                    if (!bGo)
                    {
                        Start            = TICK._GetTickTime();
                        m_bWatchDog[TH7] = false;

                        //RFID
                        RFID.fn_Upate();

                        //REST API
                        REST.fn_Upate();

                        m_bWatchDog[TH7] = true;

                        Scan = TICK._GetTickTime() - Start;
                        bGo  = true;
                        m_tDelayTimer[idx].Clear();
                    }

                    if (Scan < interval)
                    {
                        if (!m_tDelayTimer[idx].OnDelay(bGo, interval - Scan))
                        {
                            continue;
                        }
                    }

                    bGo = false;


                    //Scan Time Check
                    m_nScanTime [idx] = (uint)(TICK._GetTickTime() - m_nStartTime[idx]);
                    m_nStartTime[idx] = (uint)TICK._GetTickTime();
                }
            }
            catch (System.Exception ex)
            {
                m_bWatchDog[TH7] = false;
                System.Diagnostics.Trace.WriteLine(ex.Message);
                LOG.ExceptionTrace($"[THREAD_PROCESS_{interval}]", ex);
            }
        }
Beispiel #4
0
        //Method
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        //생성자 & 소멸자. (Constructor & Destructor)
        public SpcManager()
        {
            m_tDayChangeTime = DateTime.Parse("23:00:00");
            m_bDayChanged    = false;

            //
            m_dSeqSrtTime  = TICK._GetTickTime();
            m_dSeqEndTime  = TICK._GetTickTime();
            m_dDrngJamTime = m_dDrngSeqTime = 0.0;
        }
Beispiel #5
0
        //---------------------------------------------------------------------------
        //PMC
        private void THREAD_PROCESS_5()
        {
            bool   bGo   = false;
            double Start = 0;
            double Scan  = 0;


            //
            try
            {
                while (m_bThreadRun[TH5])
                {
                    Thread.Sleep(1);

                    if (!bGo)
                    {
                        Start            = TICK._GetTickTime();
                        m_bWatchDog[TH5] = false;

                        //PMC Update
                        //if(FM.m_stMasterOpt.nUsePMC == 1) PMC.fn_Update();

                        IO.fn_UpdateACSReboot();

                        m_bWatchDog[TH5] = true;

                        Scan = TICK._GetTickTime() - Start;
                        bGo  = true;
                        m_tDelayTimer[TH5].Clear();
                    }

                    if (Scan < THREAD_INTERVAL5)
                    {
                        if (!m_tDelayTimer[TH5].OnDelay(bGo, THREAD_INTERVAL5 - Scan))
                        {
                            continue;
                        }
                    }

                    bGo = false;



                    //Scan Time Check
                    m_nScanTime [TH5] = (uint)(TICK._GetTickTime() - m_nStartTime[TH5]);
                    m_nStartTime[TH5] = (uint)TICK._GetTickTime();
                }
            }
            catch (System.Exception ex)
            {
                m_bWatchDog[TH5] = false;
                System.Diagnostics.Trace.WriteLine(ex.Message);
                LOG.ExceptionTrace("[THREAD_PROCESS_5]", ex);
            }
        }
Beispiel #6
0
        //---------------------------------------------------------------------------
        //LoadCell
        private void THREAD_PROCESS_4()
        {
            bool   bGo   = false;
            double Start = 0;
            double Scan  = 0;

            //
            try
            {
                while (m_bThreadRun[TH4])
                {
                    Thread.Sleep(1);

                    if (!bGo)
                    {
                        Start            = TICK._GetTickTime();
                        m_bWatchDog[TH4] = false;

                        //Load Cell Update
                        LDCBTM.fn_Update();

                        //Top Cell Data
                        IO.fn_UpdateTopLDC();

                        m_bWatchDog[TH4] = true;

                        Scan = TICK._GetTickTime() - Start;
                        bGo  = true;
                        m_tDelayTimer[TH4].Clear();
                    }

                    if (Scan < THREAD_INTERVAL4)
                    {
                        if (!m_tDelayTimer[TH4].OnDelay(bGo, THREAD_INTERVAL4 - Scan))
                        {
                            continue;
                        }
                    }

                    bGo = false;

                    //Scan Time Check
                    m_nScanTime [TH4] = (uint)(TICK._GetTickTime() - m_nStartTime[TH4]);
                    m_nStartTime[TH4] = (uint)TICK._GetTickTime();
                }
            }
            catch (System.Exception ex)
            {
                m_bWatchDog[TH4] = false;
                System.Diagnostics.Trace.WriteLine(ex.Message);
                LOG.ExceptionTrace("[THREAD_PROCESS_4]", ex);
            }
        }
Beispiel #7
0
        //---------------------------------------------------------------------------
        //MANUAL, Sequence
        private void THREAD_PROCESS_2()
        {
            bool   bGo   = false;
            double Start = 0;
            double Scan  = 0;

            //
            try
            {
                while (m_bThreadRun[TH2])
                {
                    Thread.Sleep(1);

                    if (!bGo)
                    {
                        Start = TICK._GetTickTime();

                        m_bWatchDog[TH2] = false;

                        //Motor Data Update
                        MOTR.fn_Update(SEQ._bRun);

                        m_bWatchDog[TH2] = true;

                        Scan = TICK._GetTickTime() - Start;
                        bGo  = true;
                        m_tDelayTimer[TH2].Clear();
                    }

                    if (Scan < THREAD_INTERVAL2)
                    {
                        if (!m_tDelayTimer[TH2].OnDelay(bGo, THREAD_INTERVAL2 - Scan))
                        {
                            continue;
                        }
                    }

                    bGo = false;


                    //Scan Time Check
                    m_nScanTime [TH2] = (uint)(TICK._GetTickTime() - m_nStartTime[TH2]);
                    m_nStartTime[TH2] = (uint)TICK._GetTickTime();
                }
            }
            catch (System.Exception ex)
            {
                m_bWatchDog[TH2] = false;
                System.Diagnostics.Trace.WriteLine(ex.Message);
                LOG.ExceptionTrace("[THREAD_PROCESS_2]", ex);
            }
        }
Beispiel #8
0
        //---------------------------------------------------------------------------
        //Log Process
        private void THREAD_PROCESS_1()
        {
            bool   bGo   = false;
            double Start = 0;
            double Scan  = 0;

            //
            try
            {
                while (m_bThreadRun[TH1])
                {
                    Thread.Sleep(30);

                    if (!bGo)
                    {
                        m_bWatchDog[TH1] = false;

                        //Log
                        LOG.fn_UpdateLog();

                        m_bWatchDog[TH1] = true;


                        bGo = true;
                        m_tDelayTimer[TH1].Clear();
                    }

                    //if(Scan < THREAD_INTERVAL1)
                    //{
                    //    if (!m_tDelayTimer[TH1].OnDelay(bGo, THREAD_INTERVAL1 - Scan)) continue;
                    //}

                    bGo = false;


                    m_dScanTime[TH1] = TICK._GetTickTime() - Start;
                    Start            = TICK._GetTickTime();


                    //Scan Time Check
                    m_nScanTime [TH1] = (uint)(TICK._GetTickTime() - m_nStartTime[TH1]);
                    m_nStartTime[TH1] = (uint)TICK._GetTickTime();
                }
            }
            catch (System.Exception ex)
            {
                m_bWatchDog[TH1] = false;
                System.Diagnostics.Trace.WriteLine(ex.Message);
                LOG.ExceptionTrace("[THREAD_PROCESS_1]", ex);
            }
        }
Beispiel #9
0
        //---------------------------------------------------------------------------
        public bool fn_LotOpen(string recipe, string lotno = "") //Lot No = RFID No
        {
            //Vision Recipe Open
            if (g_VisionManager.fn_LoadRecipe(recipe))
            {
                m_sRecipeName   = recipe;
                FM._sRecipeName = recipe;

                m_bLotOpen = true;

                //
                SEQ_SPIND.fn_StepDataClear();


                if (lotno != "")
                {
                    m_sLotNo = string.Format($"[{DateTime.Now:yyMMdd}]LOT_{lotno}");
                }
                else
                {
                    m_sLotNo = string.Format($"[{DateTime.Now:yyMMdd}]LOT_{DateTime.Now:yyMMdd_HHmmss}");
                }

                m_tStartTime = DateTime.Now;

                fn_WriteLog(string.Format($"[Lot Open] Recipe : {m_sRecipeName} / LOT : {m_sLotNo}"));
                fn_WriteLog(string.Format($"[Lot Open] Recipe : {m_sRecipeName} / LOT : {m_sLotNo}"), EN_LOG_TYPE.ltLot);

                m_dLotStartTime = TICK._GetTickTime();

                return(true);
            }

            m_bLotOpen = false;
            m_sLotNo   = string.Empty;

            return(false);
        }
 void insertTodayKLine(TICK tTick, KLine _KL)
 {
     if (_KL.open == 0) _KL.open = tTick.m_nClose;
     _KL.close = tTick.m_nClose;
     _KL.amount += tTick.m_nQty;
     if (tTick.m_nClose < _KL.lowest)
         _KL.lowest = tTick.m_nClose;
     else if (tTick.m_nClose > _KL.highest)
         _KL.highest = tTick.m_nClose;
 }
        //----------------------------------------------------------------------
        // Initialize
        //----------------------------------------------------------------------
        public ServMain(string[] args)
        {
            //開啟之後特殊模式判別,雙擊開啟不會有任何特殊模式
            string strMode = "";
            int iMode = 0;
            try
            {
                strMode = args[0];
                iMode = int.Parse(strMode);
            }
            catch { }
            switch (iMode)
            {
                case 0: quoteProgramMode = QuoteProgramModeOS.QPM_Neutural;
                    Console.WriteLine("當前模式為  Server 一般雙擊開啟");
                    break;
                case 1: quoteProgramMode = QuoteProgramModeOS.QPM_AllProduct;
                    Console.WriteLine("當前模式為  Server 取得當前商品列表");
                    break;
                case 2: quoteProgramMode = QuoteProgramModeOS.QPM_MarketKLGetter;
                    Console.WriteLine("當前模式為  Server 昨日下午盤K棒資訊擷取");
                    break;
                case 3: quoteProgramMode = QuoteProgramModeOS.QPM_MarketAM;
                    Console.WriteLine("當前模式為  Server  小日經上午盤中作單模式");
                    break;
                case 4: quoteProgramMode = QuoteProgramModeOS.QPM_AMMarketTickGet;
                    Console.WriteLine("當前模式為  Server  小日經上午盤後Tick資訊擷取,上午倉位紀錄");
                    break;
                case 5: quoteProgramMode = QuoteProgramModeOS.QPM_MarketPM;
                    Console.WriteLine("當前模式為  Server  小日經下午盤作單模式");
                    break;
                case 6: quoteProgramMode = QuoteProgramModeOS.QPM_AfterMarket;
                    Console.WriteLine("當前模式為  Server  小日經下午盤後Tick資訊擷取,寫入每日歷史紀錄");
                    break;
            }

            InitializeComponent();

            fConnect = new FOnConnect(OnConnect);
            GC.KeepAlive(fConnect);

            fQuoteUpdate = new FOnGetStockIdx(OnQuoteUpdate);
            GC.KeepAlive(fQuoteUpdate);

            fNotifyTicks = new FOnNotifyTicks(OnNotifyTicks);
            GC.KeepAlive(fNotifyTicks);

            fOnNotifyBest5 = new FOnGetStockIdx(OnNotifyBest5);
            GC.KeepAlive(fOnNotifyBest5);

            fOverseaProducts = new FOnOverseaProducts(OnOverseaProducts);
            GC.KeepAlive(fOverseaProducts);

            fNotifyServerTime = new FOnNotifyServerTime(OnNotifyServerTime);
            GC.KeepAlive(fNotifyServerTime);

            fNotifyKLineData = new FOnNotifyKLineData(OnNotifyKLineData);
            GC.KeepAlive(fNotifyKLineData);

            fOnNotifyTicksGet = new FOnNotifyTicksGet(OnNotifyTicksGet);
            GC.KeepAlive(fOnNotifyTicksGet);

            // Order Lib
            fOrderAsync = new OrderReply.FOnOrderAsyncReport(OnOrderAsyncReport);
            GC.KeepAlive(fOrderAsync);

            fOnExecutionReport = new OrderReply.FOnGetExecutionReoprt(OnExecutionReport);
            GC.KeepAlive(fOnExecutionReport);
            GC.SuppressFinalize(fOnExecutionReport);

            // Reply Lib
            fData = new OrderReply.FOnData(OnReceiveReplyData);
            GC.KeepAlive(fData);

            fRConnect = new OrderReply.FOnConnect(OnRConnect);
            GC.KeepAlive(fConnect);

            fDisconnect = new OrderReply.FOnConnect(OnRDisconnect);
            GC.KeepAlive(fDisconnect);

            fComplete = new OrderReply.FOnComplete(OnComplete);
            GC.KeepAlive(fComplete);

            m_Logger = new Logger();

            m_Tick = new TICK();

            // 繪圖初始
            StockPointList _stklist = new StockPointList();
            StockPointList _ema11Plist = new StockPointList();
            StockPointList _ema22Plist = new StockPointList();

            this.AsyncEventHandler += new AsyncEventArgs(_AsyncEventHandler);
            m_updGraphDelegate = new updGraphDelegate(updGraph);
            CreateGraph(zg1, _stklist, _ema11Plist, _ema22Plist);

            // 啟動策略,更新繪圖
            dayTradeSt = new JNAutoDayTrade_Strategy(Application.StartupPath,this);

            //更新繪圖資訊
            DrawGraphOnce(dayTradeSt.m_KLdata_30Min, dayTradeSt.EMA11.records, dayTradeSt.EMA22.records);

            // 取得商品資訊已經搬移到client ,一定是server mode
            //if(
            //    (quoteProgramMode==QuoteProgramModeOS.QPM_MarketAM) ||
            //    (quoteProgramMode == QuoteProgramModeOS.QPM_AMMarketTickGet) ||
            //    (quoteProgramMode == QuoteProgramModeOS.QPM_MarketPM) ||
            //    (quoteProgramMode == QuoteProgramModeOS.QPM_AfterMarket)
            //  )
              bServerMode = true;

            //今天日期
            DateTime todate = DateTime.Now;

            // Server 不分上下午,只需開收盤時間
            g_marketStartTime_AM = new DateTime(todate.Year, todate.Month, todate.Day, 9, 0, 0);
            DateTime nxDate = todate.AddDays(1);
            g_marketEndTime_PM = new DateTime(nxDate.Year, nxDate.Month, nxDate.Day, 3, 0, 0);

            this.timer2.Interval = 100;
            this.timer2.Start();
        }
        bool insertNewKLine(TICK tTick, DateTime _time, List<KLine> madata, double interval)
        {
            bool bNewKLineInserted = false;

            //最後一根分k的時間轉 time_t
            int cnt = madata.Count;
            if (cnt > historyKLCnt)
            {
                KLine lastK = madata[(cnt - 1)];
                DateTime lastKLineTime = lastK.datetime;

                //現在已超出最後一根k棒的時間
                double timedif = Math.Abs((_time - lastKLineTime).TotalSeconds);

                if (timedif >= interval)
                {
                    DateTime tdate = lastKLineTime.AddSeconds(interval);
                    bNewKLineInserted = true;
                    KLine kl = new KLine(interval, tdate, tTick.m_nClose, tTick.m_nClose,
                        tTick.m_nClose, tTick.m_nClose, tTick.m_nQty);

                    madata.Add(kl);
                }
                else
                {
                    lastK.close = tTick.m_nClose;
                    lastK.amount += tTick.m_nQty;
                    if (tTick.m_nClose < lastK.lowest)
                        lastK.lowest = tTick.m_nClose;
                    else if (tTick.m_nClose > lastK.highest)
                        lastK.highest = tTick.m_nClose;

                    // 上下檔壓力記錄
                    if (tTick.m_nClose == lastK.open)
                        lastK.OpenCloseHitTime++;
                    lastK.tickAmount++;

                }
            }
            else //一根k棒都沒有
            {
                //算出當前tick最靠近的一個區間時間,可以在任意時間開啟監看
                DateTime curbaseTime = date_RoundDown(_time, TimeSpan.FromSeconds(interval));
                KLine kl = new KLine(interval, curbaseTime, tTick.m_nClose, tTick.m_nClose,
                    tTick.m_nClose, tTick.m_nClose, tTick.m_nQty);
                madata.Add(kl);
            }

            return bNewKLineInserted;
        }
Beispiel #13
0
        //---------------------------------------------------------------------------
        private void THREAD_PROCESS_9()
        {
            bool   bGo      = false;
            double Start    = 0;
            double Scan     = 0;
            int    idx      = TH9;
            int    interval = THREAD_INTERVAL9;

            m_TryCount_Cam = 0;
            //
            try
            {
                while (m_bThreadRun[idx])
                {
                    Thread.Sleep(1);

                    if (!bGo)
                    {
                        Start            = TICK._GetTickTime();
                        m_bWatchDog[TH9] = false;

                        // Cam Connection Try
                        if (g_VisionManager._CamManager.CameraRetryCount < 12)
                        {
                            if (g_VisionManager._CamManager.fn_OpenCam() == true)
                            {
                                g_VisionManager._CamManager.CameraRetryCount = 12;
                            }
                            else
                            {
                                g_VisionManager._CamManager.CameraRetryCount++;
                            }
                        }

                        m_bWatchDog[TH9] = true;

                        Scan = TICK._GetTickTime() - Start;
                        bGo  = true;
                        m_tDelayTimer[idx].Clear();
                    }

                    if (Scan < interval)
                    {
                        if (!m_tDelayTimer[idx].OnDelay(bGo, interval - Scan))
                        {
                            continue;
                        }
                    }

                    bGo = false;



                    //Scan Time Check
                    m_nScanTime [idx] = (uint)(TICK._GetTickTime() - m_nStartTime[idx]);
                    m_nStartTime[idx] = (uint)TICK._GetTickTime();
                }
            }
            catch (System.Exception ex)
            {
                m_bWatchDog[TH9] = false;
                System.Diagnostics.Trace.WriteLine(ex.Message);
                LOG.ExceptionTrace($"[THREAD_PROCESS_{interval}]", ex);
            }
        }
        void collectKLineData(TICK tTick, DateTime curT,bool bTicksGet=true)
        {
            insertTodayKLine(tTick, KLineToday);
            if (insertNewKLine(tTick, curT, m_KLdata_30Min, THIRTY_MINUTE))
            {
                KLine _curK = m_KLdata_30Min[m_KLdata_30Min.Count-2];
                //Console.WriteLine("KL: [op:" + _curK.open.ToString() + "] [cl:" + _curK.close.ToString() + "]");
                RecordMACD(_curK);
                updateGraphData(_curK);
            }

            if (!bTicksGet)
            {
                // K棒結束後2秒內出手(盤中要送單測試暫時關閉)
                //DoDayTradeMACD(m_KLdata_30Min);

                // 不用平倉
                //dayTradCleanInventory_EndDay(m_KLdata_30Min);
            }

            //如果等不到回報,表示上次的order沒有成交,應該要繼續嘗試強制平倉
            if(m_KLdata_30Min.Count > 0)
            {
                if ((ServMain.quoteProgramMode == QuoteProgramModeOS.QPM_MarketPM) || (ServMain.quoteProgramMode == QuoteProgramModeOS.QPM_MarketAM))
                {
                    if (g_bWaitingDeal == waitDealMode.waitToCleanInventory)
                        doCleanInventory(m_KLdata_30Min[m_KLdata_30Min.Count - 1], g_cleanUpMode);
                    else if (g_bWaitingDeal == waitDealMode.waitToBuildInventory)
                        doBuildInventory(AttackKL, g_b1MinTradePositive);
                }
            }
        }
        public void updTime(TICK tTick)
        {
            int hour = 0;
            int minute = 0;
            int second = 0;
            String cstime = tTick.m_nTime.ToString();
            int strln = cstime.Length;
            if (strln == 1)
            {
                bTimeOver24 = true;
            }
            if (bTimeOver24)
            {
                g_CurTime = g_CurTime.AddSeconds(1);
            }
            else
            {
                if (strln == 5)
                {
                    hour = int.Parse(cstime[0].ToString());
                    minute = int.Parse(cstime.Substring(1, 2));
                    second = int.Parse(cstime.Substring(3, 2));
                }
                else if (strln == 6)
                {
                    hour = int.Parse(cstime.Substring(0, 2));
                    minute = int.Parse(cstime.Substring(2, 2));
                    second = int.Parse(cstime.Substring(4, 2));
                }
            }

            //更新當前時間
            g_CurTime = new DateTime(g_CurTime.Year, g_CurTime.Month, g_CurTime.Day, hour, minute, second);
        }
        // 盤前擷取資訊
        public void resetStatus(string exeRootPth)
        {
            //Force GC
            System.GC.Collect();
            GC.WaitForPendingFinalizers();
            g_todayWinPoint = 0;
            todayTradeTimes = 0;
            g_CurDeposit = 0;
            readHistoryKLData();

            if (ServMain.quoteProgramMode == QuoteProgramModeOS.QPM_MarketAM)
                bDoTrading = true;
            else if (ServMain.quoteProgramMode == QuoteProgramModeOS.QPM_MarketPM)
            {
                string ff = exeRootPth + @"\AMTicks.xml";
                using (StreamReader sr = new StreamReader(ff, Encoding.Default, true))
                {
                    while (sr.Peek() != -1)
                    {
                        string _tkstr = sr.ReadLine();
                        if (_tkstr.IndexOf("Tick") != -1)
                        {
                            string[] sptk = _tkstr.Split(':');
                            int _t_ = int.Parse(sptk[1].Split('=')[0]);
                            int _price_ = int.Parse(sptk[2].Split(' ')[0]);
                            int _amt_ = int.Parse(sptk[3].Split(' ')[0]);

                            //int hour = _t_ / 10000;
                            //int minute = (_t_ - hour*10000)/100;
                            //int second = (_t_ - hour * 10000 - minute*100 );
                            //g_CurTime = new DateTime(todate.Year, todate.Month, todate.Day, hour, minute, second);
                            //Console.WriteLine(g_CurTime.ToString());

                            TICK tTick = new TICK();
                            tTick.m_nClose = _price_;
                            tTick.m_nQty = _amt_;
                            tTick.m_nTime = _t_;

                            updTime(tTick);
                            collectKLineData(tTick, g_CurTime);
                        }
                    }
                }
                bDoTrading = true;
            }
        }
        public void OnNotifyTicksGet(TICK tTick)
        {
            m_tick = tTick;
            //先更新tick時間
            updTime(tTick);
            if (!(isDuringMarketTime(g_CurTime)))
                return;

            collectKLineData(tTick, g_CurTime);
            if (parent != null)
                parent.LastCbTime = DateTime.Now;
        }
        public void OnNotifyTicks(TICK tTick)
        {
            m_tick = tTick;
            //先更新tick時間
            updTime(tTick);
            //Console.WriteLine("## Tick ==> " + g_CurTime + " : " + tTick.m_nClose.ToString() + " : " + tTick.m_nQty.ToString());
            if (!(isDuringMarketTime(g_CurTime)))
                return;

            collectKLineData(tTick, g_CurTime,false);
            if (parent != null)
                parent.LastCbTime = DateTime.Now;
        }
Beispiel #19
0
        //---------------------------------------------------------------------------
        private void THREAD_PROCESS_10()
        {
            bool   bGo      = false;
            double Start    = 0;
            double Scan     = 0;
            int    idx      = TH10;
            int    interval = THREAD_INTERVAL10;
            int    nIdex    = 0;

            //
            try
            {
                while (m_bThreadRun[idx])
                {
                    Thread.Sleep(1);

                    if (!bGo)
                    {
                        Start = TICK._GetTickTime();

                        //Check Thread
                        for (nIdex = 0; nIdex < MAX_THREAD - 1; nIdex++)
                        {
                            if (!m_bThreadRun[nIdex])
                            {
                                continue;
                            }

                            if (nIdex >= TH7)
                            {
                                continue;
                            }

                            m_tChkTimer[nIdex].OnDelay(!m_bWatchDog[nIdex], 3000);
                            if (m_tChkTimer[nIdex].Out)
                            {
                                //Console.WriteLine(string.Format($"THREAD ERROR_{nIdex}"));
                                //EPU.fn_SetErr(ERRID.EN_ERR_LIST.ERR_0120 + nIdex); //JUNG/200605
                            }
                        }


                        Scan = TICK._GetTickTime() - Start;
                        bGo  = true;
                        m_tDelayTimer[idx].Clear();
                    }

                    if (Scan < interval)
                    {
                        if (!m_tDelayTimer[idx].OnDelay(bGo, interval - Scan))
                        {
                            continue;
                        }
                    }

                    bGo = false;

                    //Scan Time Check
                    m_nScanTime [idx] = (uint)(TICK._GetTickTime() - m_nStartTime[idx]);
                    m_nStartTime[idx] = (uint)TICK._GetTickTime();
                }
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                LOG.ExceptionTrace($"[THREAD_PROCESS_{interval}]", ex);
            }
        }
        public void OnNotifyTicksGet( short sStockidx,int nPtr, int nTime, int nClose, int nQty)
        {
            if (listTicks.InvokeRequired == true)
            {
                this.Invoke(new InvokeHisTick(this.OnNotifyTicksGet), new object[] {  sStockidx,nPtr, nTime, nClose, nQty });
            }
            else
            {
                //string strMsg = "時間:" + nTime.ToString() + "  成交價:" + nClose.ToString() + "  量:" + nQty.ToString();

                //listTicks.Items.Add(strMsg);

                //listTicks.SelectedIndex = listTicks.Items.Count - 1;

                #region TEST SERVERSEND
                //TICK _t = new TICK();
                //_t.m_nClose = nClose;
                //_t.m_nQty = nQty;
                //_t.m_nTime = nTime;
                //_t.m_nPtr = nPtr;
                //client.ServiceProxy.OnNotifyTicks(_t);
                #endregion

                if ((quoteProgramMode == QuoteProgramModeOS.QPM_AMMarketTickGet) || (quoteProgramMode == QuoteProgramModeOS.QPM_AfterMarket))
                {
                    string tkStr = "<Tick Time:" + nTime.ToString() + "= Price:" + nClose.ToString() + " Amount:" + nQty.ToString() + " \" />";
                    tickLog.Add(tkStr);
                }
                else
                {
                    TICK tTick = new TICK();
                    tTick.m_nClose = nClose;
                    tTick.m_nPtr = nPtr;
                    tTick.m_nQty = nQty;
                    tTick.m_nTime = nTime;
                    client.ServiceProxy.OnNotifyTicksGet(tTick);
                }
                LastCbTime = DateTime.Now;
            }
        }
Beispiel #21
0
        //---------------------------------------------------------------------------
        public void fn_Update(EN_SEQ_STATE iSeqStat)
        {
            //if(SEQ._bRun) return;

            bool bLotOpen  = LOT._bLotOpen;
            bool bDoorOpen = SEQ.fn_IsAnyDoorOpen(true);

            //Set Start.
            m_dSeqSrtTime = TICK._GetTickTime();

            //Get During Seq Time.
            m_dDrngSeqTime = m_dSeqSrtTime - m_dSeqEndTime;


            EN_ERR_KIND iLastErrKind = (EN_ERR_KIND)EPU.fn_GetKind(EPU._nLastErr);


            //Clear. //86400000 == 24:00:00

            //Day Sequence 별 시간 증가.
            //dPMTime : PM Time / dDownTime : 비가동 / dRunTime : 가동


            switch (iSeqStat)
            {
            case EN_SEQ_STATE.RUNNING:
            case EN_SEQ_STATE.RUNWARN:

                DAILY_DATA.dRunTime   += m_dDrngSeqTime;
                DAILY_DATA.dTotalTime += m_dDrngSeqTime;
                break;

            case EN_SEQ_STATE.INIT:
            case EN_SEQ_STATE.WARNING:
            case EN_SEQ_STATE.STOP:
            case EN_SEQ_STATE.IDLE:
                if (bLotOpen)
                {
                    DAILY_DATA.dPMTime += m_dDrngSeqTime;
                }
                else
                {
                    if (bDoorOpen)
                    {
                        DAILY_DATA.dPMTime += m_dDrngSeqTime;
                    }
                    else
                    {
                        DAILY_DATA.dDownTime += m_dDrngSeqTime;
                    }
                }

                DAILY_DATA.dTotalTime += m_dDrngSeqTime;
                break;

            case EN_SEQ_STATE.ERROR:
                if (bLotOpen)
                {
                    DAILY_DATA.dPMTime += m_dDrngSeqTime;
                }
                else
                {
                    if (bDoorOpen)
                    {
                        DAILY_DATA.dPMTime += m_dDrngSeqTime;
                    }
                    else
                    {
                        DAILY_DATA.dDownTime += m_dDrngSeqTime;
                    }
                }

                DAILY_DATA.dErrorTime += m_dDrngSeqTime;
                DAILY_DATA.dTotalTime += m_dDrngSeqTime;
                break;

            default:
                if (bLotOpen)
                {
                    DAILY_DATA.dPMTime += m_dDrngSeqTime;
                }
                else
                {
                    if (bDoorOpen)
                    {
                        DAILY_DATA.dPMTime += m_dDrngSeqTime;
                    }
                    else
                    {
                        DAILY_DATA.dDownTime += m_dDrngSeqTime;
                    }
                }

                DAILY_DATA.dTotalTime += m_dDrngSeqTime;
                break;
            }

            //
            //DAILY_DATA.dTotalTime += m_dDrngSeqTime;


            //Set End Time.
            m_dSeqEndTime = TICK._GetTickTime();

            //Check Changing Time.
            if (!IsChangedDay())
            {
                return;
            }

            string sLog = string.Empty;

            //string sLog = string.Format($"Day Change : MTBI= {CalMTBI(DAILY_DATA.dRunTime, DAILY_DATA.iJamQty)})");
            //fn_WriteLog(sLog);

            sLog = string.Format($"TOTAL TIME : {TICK.ConvTimeTickToStr(SPC.DAILY_DATA.dTotalTime)} / RUN TIME : {TICK.ConvTimeTickToStr(SPC.DAILY_DATA.dRunTime)} / DOWN TIME : {TICK.ConvTimeTickToStr(SPC.DAILY_DATA.dDownTime)} / PM TIME : {TICK.ConvTimeTickToStr(SPC.DAILY_DATA.dPMTime)}");
            fn_WriteLog(sLog);

            //Kill Past Log
            LOG.fn_DeleteOldFile();

            SPC_EFF.ResetData();
            DAILY_DATA.ResetData();
        }
Beispiel #22
0
        //---------------------------------------------------------------------------
        //Main Process
        private void THREAD_PROCESS_0()
        {
            bool   bGo   = false;
            double Start = 0;
            double Scan  = 0;

            //
            try
            {
                while (m_bThreadRun[TH0])
                {
                    Thread.Sleep(1);

                    if (!bGo)
                    {
                        //-----------------------------------------------
                        Monitor.Enter(Obj);
                        try
                        {
                            m_bWatchDog[TH0] = false;

                            //Main Sequence
                            if (m_bIOOn)
                            {
                                SEQ.fn_Update();
                            }
                            //SEQ.fn_Update1();

                            m_bWatchDog[TH0] = true;
                        }
                        finally
                        {
                            Monitor.Exit(Obj);
                        }
                        //-----------------------------------------------



                        bGo = true;
                        m_tDelayTimer[TH0].Clear();
                    }

                    //if (Scan < THREAD_INTERVAL0)
                    //{
                    //    if (!m_tDelayTimer[TH0].OnDelay(bGo, THREAD_INTERVAL0 - Scan)) continue;
                    //}

                    bGo = false;

                    m_dScanTime[TH0] = TICK._GetTickTime() - Start;
                    Start            = TICK._GetTickTime();


                    //Scan Time Check
                    m_nScanTime [TH0] = (uint)Environment.TickCount - m_nStartTime[TH0];
                    m_nStartTime[TH0] = (uint)Environment.TickCount;
                }
            }
            catch (System.Exception ex)
            {
                m_bWatchDog[TH0] = false;

                System.Diagnostics.Trace.WriteLine(ex.Message);
                LOG.ExceptionTrace("[THREAD_PROCESS_0]", ex);
            }
        }