public void TestTrade_Tick() { string code = "RB1710"; int startDate = 20170601; int endDate = 20170605; IDataForward_Code historyDataForward = ForwardDataGetter.GetHistoryDataForward_Code(code, startDate, endDate, true); historyDataForward.Forward(); IAccount account = DataCenter.Default.AccountManager.CreateAccount(100000, historyDataForward); account.AccountSetting.TradeType = AccountTradeType.MARKETPRICE; account.OnReturnOrder += Account_OnReturnOrder; account.OnReturnTrade += Account_OnReturnTrade; account.Open(code, 3099, market.OrderSide.Buy, 10); account.Open(code, 3095, market.OrderSide.Buy, 10); int index = 0; while (index < 2000) { historyDataForward.Forward(); index++; if (isOpen && historyDataForward.GetTickData().SellPrice >= 3102) { account.Close(code, 3102, market.OrderSide.Sell, 10); account.Close(code, 3105, market.OrderSide.Sell, 10); } //Console.WriteLine(historyDataForward.GetTickData()); } Console.WriteLine(account); Assert.AreEqual(100880, account.Money); }
public void TestSaveLoad_DataForward_Code() { string code = "rb1710"; int startDate = 20170601; int endDate = 20170602; ForwardPeriod forwardPeriod = new ForwardPeriod(true, KLinePeriod.KLinePeriod_1Minute); ForwardReferedPeriods referedPeriods = new ForwardReferedPeriods(new KLinePeriod[] { KLinePeriod.KLinePeriod_1Minute, KLinePeriod.KLinePeriod_15Minute, KLinePeriod.KLinePeriod_1Hour, KLinePeriod.KLinePeriod_1Day }, true, false); IDataForward_Code dataForward = DataCenter.Default.HistoryDataForwardFactory.CreateDataForward_Code(code, startDate, endDate, referedPeriods, forwardPeriod); for (int i = 0; i < 100; i++) { dataForward.Forward(); } Console.WriteLine(XmlUtils.ToString(dataForward)); XmlElement root = GetXmlRoot(); dataForward.Save(root); IDataForward_Code dataForward2 = DataCenter.Default.HistoryDataForwardFactory.CreateDataForward_Code(root); for (int i = 0; i < 100; i++) { dataForward.Forward(); dataForward2.Forward(); } Console.WriteLine(XmlUtils.ToString(dataForward2)); Assert.AreEqual(dataForward.Time, dataForward2.Time); }
public void TestAccountSave() { string code = "RB1710"; int startDate = 20170601; int endDate = 20170605; IDataForward_Code historyDataForward = ForwardDataGetter.GetHistoryDataForward_Code(code, startDate, endDate, true); historyDataForward.Forward(); IAccount account = DataCenter.Default.AccountManager.CreateAccount(100000, historyDataForward); account.AccountSetting.TradeType = AccountTradeType.MARKETPRICE; account.OnReturnOrder += Account_OnReturnOrder; account.OnReturnTrade += Account_OnReturnTrade; account.Open(code, 3099, market.OrderSide.Buy, 10); account.Open(code, 3095, market.OrderSide.Buy, 10); int index = 0; while (index < 2000) { historyDataForward.Forward(); index++; if (isOpen && historyDataForward.GetTickData().SellPrice >= 3102) { account.Close(code, 3102, market.OrderSide.Sell, 10); account.Close(code, 3105, market.OrderSide.Sell, 10); } //Console.WriteLine(historyDataForward.GetTickData()); } account.Open(code, 3105, market.OrderSide.Buy, 10); account.Open(code, 3025, market.OrderSide.Buy, 10); for (int i = 0; i < 100; i++) { historyDataForward.Forward(); } XmlElement root = GetXmlRoot(); account.Save(root); Account account2 = (Account)DataCenter.Default.AccountManager.CreateAccount(root); //Console.WriteLine(account); //Console.WriteLine(account2); Assert.AreEqual(XmlUtils.ToString(account), XmlUtils.ToString(account2)); IDataForward_Code historyDataForward2 = ForwardDataGetter.GetHistoryDataForward_Code(code, startDate, endDate, true); historyDataForward2.NavigateTo(account2.Time); account2.BindRealTimeReader(historyDataForward2); //IDataForward_Code historyDataForward2 = account2.DataForward_Code; for (int i = 0; i < 100; i++) { historyDataForward2.Forward(); } Console.WriteLine(account2); }
public void TestKLineDataForward_Tick() { printStrs_Forward_Tick.Clear(); string code = "RB1710"; int start = 20170601; int endDate = 20170603; IDataForward_Code klineDataForward = GetKLineDataForward(code, start, endDate); klineDataForward.OnBar += KlineDataForward_OnBar; klineDataForward.OnTick += KlineDataForward_OnTick; DateTime prevtime = DateTime.Now; while (klineDataForward.Forward()) { } DateTime time = DateTime.Now; TimeSpan span = time.Subtract(prevtime); Console.WriteLine(span.Minutes * 60 * 1000 + span.Seconds * 1000 + span.Milliseconds); //ITimeLineData timeLineData = klineDataForward.GetTimeLineData(); //for(int i = 0; i < timeLineData.Length; i++) //{ // ITimeLineBar timeLineBar = timeLineData.GetBar(i); // Console.WriteLine(timeLineBar); //} AssertUtils.AssertEqual_List("forward_tick", GetType(), printStrs_Forward_Tick); printStrs_Forward_Tick.Clear(); }
public bool Forward(ForwardPeriod forwardPeriod) { if (!forwardPeriod.IsTickForward) { return(Forward(forwardPeriod.KlineForwardPeriod)); } IDataForward_Code dataForward = GetDataForward(); isTickForward = true; return(dataForward.Forward()); }
public void TestCompareWithReader() { string code = "RB0000"; int start = 20170601; int endDate = 20170605; IDataForward_Code klineDataForward = GetKLineDataForward(code, start, endDate); klineDataForward.Forward(); AddContent_Tick(start, klineDataForward.GetTickData().ToString()); klineDataForward.OnBar += KlineDataForward_OnBar_CompareWithReader; klineDataForward.OnTick += KlineDataForward_OnTick_CompareWithReader; while (klineDataForward.Forward()) { } AssertKLineDataInDic(code, start, endDate); AssertTickDataInDic(code); }
private bool ExecuteStrategy(IDataForward_Code realTimeReader) { //执行策略 while (!realTimeReader.IsEnd) { realTimeReader.Forward(); if (isCancel) { return(false); } } return(true); }
public void TestRealTimeReader_OnTick() { string code = "RB1710"; int start = 20170601; int endDate = 20170610; IDataForward_Code realTimeReader = GetRealTimeReader(code, start, endDate, true); realTimeReader.OnTick += RealTimeReader_OnTick; realTimeReader.OnBar += RealTimeReader_OnBar; while (!realTimeReader.IsEnd) { realTimeReader.Forward(); Console.WriteLine("timeline:" + realTimeReader.GetTimeLineData()); } }
public void TestRealTimeReader() { string code = "RB1710"; int start = 20170601; int endDate = 20170610; IDataForward_Code realTimeReader = GetRealTimeReader(code, start, endDate, false); while (!realTimeReader.IsEnd) { realTimeReader.Forward(); IKLineData klineData = realTimeReader.GetKLineData(KLinePeriod.KLinePeriod_1Minute); Console.WriteLine(klineData); } }
public void TestForward_TimeLineData() { printStrs_Forward_TimeLine.Clear(); string code = "RB1710"; int start = 20170601; int endDate = 20170603; IDataForward_Code klineDataForward = ForwardDataGetter.GetHistoryDataForward_Code(code, start, endDate, true, true, new KLinePeriod[] { KLinePeriod.KLinePeriod_1Minute }); klineDataForward.OnTick += KlineDataForward_OnTick; DateTime prevtime = DateTime.Now; while (klineDataForward.Forward()) { } AssertUtils.AssertEqual_List("forward_tick_timeline", GetType(), printStrs_Forward_TimeLine); printStrs_Forward_TimeLine.Clear(); }
public void TestKLineDataForward_Tick_OnBar() { string code = "RB1710"; int start = 20170601; int endDate = 20170603; printStrs_Forward_TimeInfo_OnBar.Clear(); IDataForward_Code klineDataForward = GetKLineDataForward(code, start, endDate); klineDataForward.OnBar += KlineDataForward_OnBar2; while (klineDataForward.Forward()) { } AssertUtils.AssertEqual_List("forward_tick_onbar", GetType(), printStrs_Forward_TimeInfo_OnBar); printStrs_Forward_TimeInfo_OnBar.Clear(); }
public void TestForwardTimeInfo_OnBar() { string code = "RB1710"; int start = 20170601; int endDate = 20170603; IDataForward_Code klineDataForward = GetKLineDataForward(code, start, endDate); klineDataForward.OnBar += KlineDataForward_OnBar1; //klineDataForward.OnTick += KlineDataForward_OnTick; //print_Forward_TimeInfo_OnTick.Clear(); while (klineDataForward.Forward()) { } //AssertUtils.AssertEqual_List("forward_tick_timeinfo", GetType(), print_Forward_TimeInfo_OnTick); //print_Forward_TimeInfo_OnTick.Clear(); }
public void TestTickAttachTick() { int start = 20170601; int endDate = 20170602; //string code = "A0401"; //int start = 20040106; //int endDate = 20040106; IDataForward_Code historyDataForward = ForwardDataGetter.GetHistoryDataForward_Code(code, start, endDate, true, true); historyDataForward.AttachOtherData(code2); //historyDataForward.OnBar += HistoryDataForward_OnBar; historyDataForward.OnTick += HistoryDataForward_OnTick; //historyDataForward.OnTick += KlineDataForward_OnTick; while (historyDataForward.Forward()) { } }
public void TestKLineDataForward_OnBar() { list_OnBar.Clear(); string code = "RB1710"; int start = 20170601; int endDate = 20170603; IDataForward_Code klineDataForward = GetDataForward(code, start, endDate); klineDataForward.OnBar += KlineDataForward_OnBar; list_OnBar.Add(KLinePeriod.KLinePeriod_1Minute + ":" + klineDataForward.GetKLineData(KLinePeriod.KLinePeriod_1Minute)); Console.WriteLine(KLinePeriod.KLinePeriod_1Minute + ":" + klineDataForward.GetKLineData(KLinePeriod.KLinePeriod_1Minute)); while (klineDataForward.Forward()) { } AssertUtils.AssertEqual_List("forward_kline", GetType(), list_OnBar); }
//[TestMethod] public void TestKLineDataForward_Tick_Long() { printStrs_Forward_Tick.Clear(); //string code = "RB1710"; //int start = 20170401; //int endDate = 20170803; string code = "RB0000"; int start = 20150401; int endDate = 20170803; IDataForward_Code klineDataForward = GetKLineDataForward(code, start, endDate); klineDataForward.OnBar += KlineDataForward_OnBar_Long; klineDataForward.OnTick += KlineDataForward_OnTick_Long; while (klineDataForward.Forward()) { } }
//[TestMethod] public void TestNavigate_ChangeTime() { int start = 20170601; int endDate = 20170603; KLinePeriod[] periods = new KLinePeriod[] { KLinePeriod.KLinePeriod_1Minute, KLinePeriod.KLinePeriod_5Minute, KLinePeriod.KLinePeriod_15Minute, KLinePeriod.KLinePeriod_1Day }; this.klineData_1Minute = new KLineDataExtend_RealTime(DataCenter.Default.DataReader.KLineDataReader.GetData_Extend(code, start, endDate, 0, 0, KLinePeriod.KLinePeriod_1Minute)); this.klineData_5Minute = new KLineDataExtend_RealTime(DataCenter.Default.DataReader.KLineDataReader.GetData_Extend(code, start, endDate, 0, 0, KLinePeriod.KLinePeriod_5Minute)); this.klineData_15Minute = new KLineDataExtend_RealTime(DataCenter.Default.DataReader.KLineDataReader.GetData_Extend(code, start, endDate, 0, 0, KLinePeriod.KLinePeriod_15Minute)); this.klineData_1Day = new KLineDataExtend_RealTime(DataCenter.Default.DataReader.KLineDataReader.GetData_Extend(code, start, endDate, 0, 0, KLinePeriod.KLinePeriod_1Day)); IDataForward_Code dataForward = ForwardDataGetter.GetHistoryDataForward_Code(code, start, endDate, true, true, periods); //dataForward.Forward(); dataForward.OnTick += DataForward_OnTick; while (dataForward.Forward()) { } }
public void TestTickAttachKLine() { int start = 20170601; int endDate = 20170602; //string code = "A0401"; //int start = 20040106; //int endDate = 20040106; printStrs_Forward_KLine.Clear(); IDataForward_Code historyDataForward = ForwardDataGetter.GetHistoryDataForward_Code(code, start, endDate, false); historyDataForward.AttachOtherData(code2); historyDataForward.OnBar += HistoryDataForward_OnBar; historyDataForward.OnTick += HistoryDataForward_OnTick; //historyDataForward.OnTick += KlineDataForward_OnTick; while (historyDataForward.Forward()) { } AssertUtils.AssertEqual_List("attachcode_kline", GetType(), printStrs_Forward_KLine); }
public void TestKLineDataForward_Minute() { string code = "RB1710"; int start = 20170101; int endDate = 20170803; IDataForward_Code klineDataForward = GetDataForward(code, start, endDate); //List<string> list = new List<string>(); dic_Period_Content.Clear(); klineDataForward.OnBar += KlineDataForward_OnBar; //AddToList(list, klineDataForward); //Print(klineDataForward); //Console.WriteLine(KLinePeriod.KLinePeriod_1Minute + ":" + klineDataForward.GetKLineData(KLinePeriod.KLinePeriod_1Minute)); AddContent(KLinePeriod.KLinePeriod_1Minute, klineDataForward.GetKLineData(KLinePeriod.KLinePeriod_1Minute).ToString()); while (klineDataForward.Forward()) { } AssertKLineDataInDic(code, start, endDate); //AssertUtils.AssertEqual_List("forward_bigperiod", GetType(), list); }
public void TestTrade_TickDelay2() { string code = "RB1710"; int startDate = 20170601; int endDate = 20170605; IDataForward_Code historyDataForward = ForwardDataGetter.GetHistoryDataForward_Code(code, startDate, endDate, true); historyDataForward.OnTick += HistoryDataForward_OnTick; account = DataCenter.Default.AccountManager.CreateAccount(100000, historyDataForward); account.AccountSetting.TradeType = AccountTradeType.DELAYTICK; account.AccountSetting.AutoFilter = true; account.AccountSetting.DelayTick = 4; int index = 0; while (index < 100) { historyDataForward.Forward(); index++; } Console.WriteLine(account); Assert.AreEqual(53395, account.Money); Assert.AreEqual(1, account.CurrentOrderInfo.Count); }