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); }
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); }
// 盤前擷取資訊 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; } }
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; } }
public void InsertTick(TICK pTick) { DataRow myDataRow = m_dtTick.NewRow(); myDataRow["m_nPtr"] = pTick.m_nPtr; myDataRow["m_nTime"] = pTick.m_nTime; if (pTick.m_nBid == -999999) { myDataRow["m_nBid"] = 0; } else { myDataRow["m_nBid"] = pTick.m_nBid / 100.00; } if (pTick.m_nAsk == -999999) { myDataRow["m_nAsk"] = 0; } else { myDataRow["m_nAsk"] = pTick.m_nAsk / 100.00; } if (pTick.m_nAsk == -999999) { myDataRow["m_nClose"] = 0; } else { myDataRow["m_nClose"] = pTick.m_nClose / 100.00; } myDataRow["m_nQty"] = pTick.m_nQty; m_dtTick.Rows.Add(myDataRow); }
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 static extern int SKQuoteLib_GetTick(int sMarketNo, int sStockidx, int nPtr, out TICK Tick);
public static extern int SKQuoteLib_GetTick(int sMarketNo, int sStockidx,int nPtr, out TICK Tick);
public void InsertTick( TICK pTick) { DataRow myDataRow = m_dtTick.NewRow(); myDataRow["m_nPtr"] = pTick.m_nPtr; myDataRow["m_nTime"] = pTick.m_nTime; if (pTick.m_nBid == -999999) myDataRow["m_nBid"] = 0; else myDataRow["m_nBid"] = pTick.m_nBid / 100.00; if (pTick.m_nAsk == -999999) myDataRow["m_nAsk"] = 0; else myDataRow["m_nAsk"] = pTick.m_nAsk / 100.00; if (pTick.m_nAsk == -999999) myDataRow["m_nClose"] = 0; else myDataRow["m_nClose"] = pTick.m_nClose / 100.00; myDataRow["m_nQty"] = pTick.m_nQty; m_dtTick.Rows.Add(myDataRow); }