public int CompareTo(object obj) { OriginalRecord recordToBeCompared = (OriginalRecord)obj; return(this.TradeTime.CompareTo(recordToBeCompared.TradeTime)); }
public void prepareFirst() { if (now.Day <= 9) { nowDay = Convert.ToString("0" + now.Day); } else { nowDay = Convert.ToString(now.Day); } if (now.Month <= 9) { nowMonth = Convert.ToString("0" + now.Month); } else { nowMonth = Convert.ToString(now.Month); } lotArray = lots.Split(','); string appDir = System.Windows.Forms.Application.StartupPath; loseLine = new Dictionary<int, int>(); winLine = new Dictionary<int, int>(); reverseLine = new Dictionary<int, double>(); strategyFile = StrategyFile.getInstance(); strategyFile.dealStrategyRule(appDir); this.winLine = strategyFile.getWinLine(); this.loseLine = strategyFile.getLoseLine(); this.reverseLine = strategyFile.getReverseLine(); isPrevWin = false;//上一次交易是否獲利 //stopTradeTime = new DateTime(now.Year, now.Month, now.Day, 13, 44, 0); fileName = appDir + "\\" + Output_Dir + "\\" + "NEW_Daily_" + now.Year + "_" + now.Month + "_" + nowDay + ".rpt"; allTradeOutputFile = new TradeFile(fileName); allTradeOutputFile.prepareWriter(); tradeRecordFileName = appDir + "\\" + Output_Dir + "\\" + "TradeRecord_" + now.Year + "_" + now.Month + "_" + nowDay + ".rpt"; tradeRecordFile = new TradeFile(tradeRecordFileName); tradeRecordFile.prepareWriter(); recordList = new List<OriginalRecord>(); befofeRecord = new OriginalRecord(); RecordScanner.setRecordList(recordList); debugMsg(now + "------<<開始交易>>"); showParameters(); prepareOrderAPI(); }
private void dealOutCore()//處理平倉後記錄獲利動作的核心 { calOneProfit(); totalProfitPoint += oneProfitPoint; oneNetProfit = oneProfitPoint * valuePerPoint - Convert.ToInt32(lotArray[lotIndex]) * (orderNewPriceList.Count) * cost; totalNetProfit += oneNetProfit; debugMsg("平倉點數---->" + orderEvenPrice); debugMsg("平倉時間---->" + orderEvenTime); debugMsg("純利潤 : " + oneNetProfit); debugMsg("總純利 : " + totalNetProfit); debugMsg("停損策略 : " + loseLine[orderNewPriceList.Count]); debugMsg("停利策略 : " + winLine[orderNewPriceList.Count]); if (orderNewPriceList.Count > 1) { debugMsg("反轉策略 : " + reverseLine[orderNewPriceList.Count - 1]); } debugMsg("----------------------------------------------------------------------------------------------"); if ((outStyle == Out_Loss_Buy) || (outStyle == Out_Loss_Sell)) {//認賠停損 isStartOrder = false; befofeRecord = null; orderNewPriceList.Clear();//平倉後,把新倉(包括加碼的新倉)列表清空。 minTradePoint = 99999;//新倉後最低價 maxTradePoint = 0;//新倉後最高價 } lotIndex--; if (lotIndex < 0) { lotIndex = 0; } }
private Boolean dealSellOrBuy(OriginalRecord record, DateTime tradeDateTime)//決定買或賣的方向,回傳値代表計算成功或是失敗 { try { sellOrBuyCheckPeriod = new int[checkCount]; int baseTimePeriod = 5; int[] basePrice = new int[checkCount]; minuteBeforeTradeTime = new DateTime[checkCount]; string[] direction = new string[checkCount]; for (int i = 0; i < checkCount; i++) { direction[i] = "NONE"; sellOrBuyCheckPeriod[i] = baseTimePeriod; baseTimePeriod += 5; minuteBeforeTradeTime[i] = tradeDateTime.AddSeconds(0 - sellOrBuyCheckPeriod[i]); debugMsg("minuteBeforeTradeTime[" + i + "]:" + minuteBeforeTradeTime[i]); } for (int i = 0; i < checkCount; i++) { try { befofeRecord = RecordScanner.getRecordMinuteBeforeOrAfter(minuteBeforeTradeTime[i]);//XX鐘前的交易紀錄 if (befofeRecord == null) { return false; } basePrice[i] = befofeRecord.TradePrice;//交易基準 debugMsg("basePrice:" + i + ":" + basePrice[i]); } catch (Exception e) { Console.WriteLine("掃描失敗:" + e.Message + "---" + e.StackTrace + "---" + e.Source); } }//end for for (int i = 0; i < checkCount; i++) { if (record.TradePrice > basePrice[i])//目前交易金額大於XX分鐘前的交易金額 { direction[i] = BS_Type_B; } else if (record.TradePrice < basePrice[i])//目前交易金額小於XX分鐘前的交易金額 { direction[i] = BS_Type_S; } } for (int i = checkCount - 1; i > 0; i--) { if (direction[i] != direction[i - 1]) { return false; } } if (direction[0].Equals("NONE"))//五個時間的價位都一樣 { return false; } nowTradeType = direction[0]; for (int i = 0; i < checkCount; i++) { debugMsg("direction[" + i + "]:" + direction[i]); } debugMsg("nowTradeType : " + nowTradeType); return true; } catch (Exception ex) { Console.WriteLine(ex.Source); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } return false; }
public void startTrade(String matchTime, String matchPrice, String matchQuantity)//回傳値表示是否結束本日交易 { try { record = new OriginalRecord(); record.TradeTime = matchTime; record.TradeMoment = Convert.ToDateTime(matchTime); record.TradeHour = record.TradeMoment.Hour; record.TradeMinute = record.TradeMoment.Minute; record.TradePrice = Convert.ToInt32(matchPrice); record.TradeVolumn = Convert.ToInt32(matchQuantity); recordList.Add(record); } catch (Exception e) { debugMsg(e.StackTrace); } if (isOrderAPIReady) { coreLogic(); } }