/// <summary> /// Primary constructor /// </summary> public CandlePriceSaver(string u, string p) { m_username = u; m_password = p; instrumentList = ContractUtilities.ContractMetaInfo.cmeFuturesTickerheadList.Union(ContractUtilities.ContractMetaInfo.iceFuturesTickerheadList).ToArray(); liquidContractList = new ContractUtilities.ContractList(instrumentList); DateTime referanceDate = DateTime.Today; int minInterval = 10; //30 startTime = new DateTime(referanceDate.Year, referanceDate.Month, referanceDate.Day, 1, 0, 0); endTime = new DateTime(referanceDate.Year, referanceDate.Month, referanceDate.Day, 9, 0, 0); //900 candleObj = new DataAnalysis.CandleStick(startTime, endTime, liquidContractList.dbTickerList.ToArray(), minInterval); OutputFolder = TA.DirectoryNames.GetDirectoryName(ext: "overnightCandlestick") + TA.DirectoryNames.GetDirectoryExtension(DateTime.Now.Date); System.IO.Directory.CreateDirectory(OutputFolder); ttapiSubs = new ttapiUtils.Subscription(m_username, m_password); ttapiSubs.dbTickerList = liquidContractList.dbTickerList; ttapiSubs.ilsUpdateList = new List <EventHandler <InstrumentLookupSubscriptionEventArgs> > { ttapiSubs.startPriceSubscriptions }; ttapiSubs.asu_update = ttapiSubs.startInstrumentLookupSubscriptions; ttapiSubs.priceUpdatedEventHandler = m_ps_FieldsUpdated; }
/// <summary> /// Primary constructor /// </summary> public CandlePriceSaver(string u, string p) { m_username = u; m_password = p; instrumentList = ContractUtilities.ContractMetaInfo.cmeFuturesTickerheadList.Union(ContractUtilities.ContractMetaInfo.iceFuturesTickerheadList).ToArray(); liquidContractList = new ContractUtilities.ContractList(instrumentList); DateTime referanceDate = DateTime.Today; int minInterval = 10; //30 startTime = new DateTime(referanceDate.Year, referanceDate.Month, referanceDate.Day, 1, 0, 0); endTime = new DateTime(referanceDate.Year, referanceDate.Month, referanceDate.Day, 9, 0, 0); //900 candleObj = new DataAnalysis.CandleStick(startTime, endTime, liquidContractList.dbTickerList.ToArray(), minInterval); OutputFolder = TA.DirectoryNames.GetDirectoryName(ext: "overnightCandlestick") + TA.DirectoryNames.GetDirectoryExtension(DateTime.Now.Date); System.IO.Directory.CreateDirectory(OutputFolder); ttapiSubs = new ttapiUtils.Subscription(m_username, m_password); ttapiSubs.dbTickerList = liquidContractList.dbTickerList; ttapiSubs.ilsUpdateList = new List<EventHandler<InstrumentLookupSubscriptionEventArgs>> { ttapiSubs.startPriceSubscriptions }; ttapiSubs.asu_update = ttapiSubs.startInstrumentLookupSubscriptions; ttapiSubs.priceUpdatedEventHandler = m_ps_FieldsUpdated; }
/// <summary> /// Primary constructor /// </summary> public BreakoutTrader(string u, string p) { m_username = u; m_password = p; todayDate = DateTime.Now.Date; OutputFolder = TA.DirectoryNames.GetDirectoryName("overnightCandlestick") + TA.DirectoryNames.GetDirectoryExtension(todayDate); LogFile = new StreamWriter(OutputFolder + "/Log" + DateTime.Now.ToString("HHmmss") + ".txt", true); BreakoutLogger = new Logger(LogFile); instrumentList = ContractUtilities.ContractMetaInfo.cmeFuturesTickerheadList.Union(ContractUtilities.ContractMetaInfo.iceFuturesTickerheadList).ToArray(); liquidContractList = new ContractUtilities.ContractList(instrumentList); ttapiTickerList = liquidContractList.ttapiTickerList; dbTickerList = liquidContractList.dbTickerList; DateTimePastPnlDisplay = DateTime.MinValue; BreakoutPosition = new Portfolio.Position(fullTickerList: dbTickerList); CovMatrix = Risk.PorfolioRisk.LoadCovMatrix(); candleStickData = new DataTable(); rangeMinList = new List <double>(); rangeMaxList = new List <double>(); ilsUpdateList = new List <EventHandler <InstrumentLookupSubscriptionEventArgs> >(); candleStickData.ReadXml(OutputFolder + "/" + TA.FileNames.candlestick_signal_file); StdDict = new Dictionary <string, double>(); QtyDict = new Dictionary <string, int>(); startTime = new DateTime(todayDate.Year, todayDate.Month, todayDate.Day, 8, 30, 0); endTime = new DateTime(todayDate.Year, todayDate.Month, todayDate.Day, 9, 0, 0); //900 LastTradeEntryTime = new DateTime(todayDate.Year, todayDate.Month, todayDate.Day, 9, 20, 0); //920 selectedCandleStickData = candleStickData.Select("start>= #" + startTime.ToString() + "# AND end<= #" + endTime.ToString() + " # "); for (int i = 0; i < dbTickerList.Count; i++) { double rangeMin = double.MaxValue; double rangeMax = double.MinValue; for (int j = 0; j < selectedCandleStickData.Length; j++) { rangeMax = Math.Max(selectedCandleStickData[j].Field <Double>(dbTickerList[i] + "_high"), rangeMax); rangeMin = Math.Min(selectedCandleStickData[j].Field <Double>(dbTickerList[i] + "_low"), rangeMin); } rangeMinList.Add(rangeMin); rangeMaxList.Add(rangeMax); StdDict.Add(dbTickerList[i], Risk.PorfolioRisk.GetStd4Ticker(dbTickerList[i], CovMatrix)); QtyDict.Add(dbTickerList[i], (int)Math.Min(MaxQty4Ticker, Math.Floor(StdPerBet / StdDict[dbTickerList[i]]))); } // ttapiSubs = new ttapiUtils.Subscription(m_username, m_password); ttapiSubs.dbTickerList = dbTickerList; ilsUpdateList.Add(ttapiSubs.startPriceSubscriptions); ilsUpdateList.Add(ttapiSubs.startTradeSubscriptions); ttapiSubs.ilsUpdateList = ilsUpdateList; ttapiSubs.asu_update = ttapiSubs.startInstrumentLookupSubscriptions; ttapiSubs.priceUpdatedEventHandler = BreakoutAlgo; ttapiSubs.orderFilledEventHandler = BreakoutStopLogic; }
/// <summary> /// Primary constructor /// </summary> public BreakoutTrader(string u, string p) { m_username = u; m_password = p; todayDate = DateTime.Now.Date; OutputFolder = TA.DirectoryNames.GetDirectoryName("overnightCandlestick") + TA.DirectoryNames.GetDirectoryExtension(todayDate); LogFile = new StreamWriter(OutputFolder + "/Log" + DateTime.Now.ToString("HHmmss") + ".txt", true); BreakoutLogger = new Logger(LogFile); instrumentList = ContractUtilities.ContractMetaInfo.cmeFuturesTickerheadList.Union(ContractUtilities.ContractMetaInfo.iceFuturesTickerheadList).ToArray(); liquidContractList = new ContractUtilities.ContractList(instrumentList); ttapiTickerList = liquidContractList.ttapiTickerList; dbTickerList = liquidContractList.dbTickerList; DateTimePastPnlDisplay = DateTime.MinValue; BreakoutPosition = new Portfolio.Position(fullTickerList: dbTickerList); CovMatrix = Risk.PorfolioRisk.LoadCovMatrix(); candleStickData = new DataTable(); rangeMinList = new List<double>(); rangeMaxList = new List<double>(); ilsUpdateList = new List<EventHandler<InstrumentLookupSubscriptionEventArgs>>(); candleStickData.ReadXml(OutputFolder + "/" + TA.FileNames.candlestick_signal_file); StdDict = new Dictionary<string, double>(); QtyDict = new Dictionary<string, int>(); startTime = new DateTime(todayDate.Year, todayDate.Month, todayDate.Day, 8, 30, 0); endTime = new DateTime(todayDate.Year, todayDate.Month, todayDate.Day, 9, 0, 0); //900 LastTradeEntryTime = new DateTime(todayDate.Year, todayDate.Month, todayDate.Day, 9, 20, 0); //920 selectedCandleStickData = candleStickData.Select("start>= #" + startTime.ToString() + "# AND end<= #" + endTime.ToString() + " # "); for (int i = 0; i < dbTickerList.Count; i++) { double rangeMin = double.MaxValue; double rangeMax = double.MinValue; for (int j = 0; j < selectedCandleStickData.Length; j++) { rangeMax = Math.Max(selectedCandleStickData[j].Field<Double>(dbTickerList[i] + "_high"), rangeMax); rangeMin = Math.Min(selectedCandleStickData[j].Field<Double>(dbTickerList[i] + "_low"), rangeMin); } rangeMinList.Add(rangeMin); rangeMaxList.Add(rangeMax); StdDict.Add(dbTickerList[i], Risk.PorfolioRisk.GetStd4Ticker(dbTickerList[i], CovMatrix)); QtyDict.Add(dbTickerList[i], (int)Math.Min(MaxQty4Ticker, Math.Floor(StdPerBet / StdDict[dbTickerList[i]]))); } // ttapiSubs = new ttapiUtils.Subscription(m_username, m_password); ttapiSubs.dbTickerList = dbTickerList; ilsUpdateList.Add(ttapiSubs.startPriceSubscriptions); ilsUpdateList.Add(ttapiSubs.startTradeSubscriptions); ttapiSubs.ilsUpdateList = ilsUpdateList; ttapiSubs.asu_update = ttapiSubs.startInstrumentLookupSubscriptions; ttapiSubs.priceUpdatedEventHandler = BreakoutAlgo; ttapiSubs.orderFilledEventHandler = BreakoutStopLogic; }