/// <summary> /// 获取通达信的历史数据 /// </summary> /// <param name="str">数据字符串</param> /// <param name="datas">历史数据</param> /// <returns>状态</returns> public static int GetHistoryDatasByTdxStr(String str, List <SecurityData> datas) { String[] strs = str.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); int strLen = strs.Length; for (int i = 2; i < strLen - 1; i++) { String[] strs2 = strs[i].Split(','); int strs2Size = strs2.Length; if (strs2Size >= 7) { String[] dateStrs = strs2[0].Split('-'); int year = 0, month = 0, day = 0, hour = 0, minute = 0; if (dateStrs.Length == 3) { year = CStrA.ConvertStrToInt(dateStrs[0]); month = CStrA.ConvertStrToInt(dateStrs[1]); day = CStrA.ConvertStrToInt(dateStrs[2]); } int si = 1; if (strs2Size == 8) { si = 2; hour = CStrA.ConvertStrToInt(strs2[1].Substring(0, 2)); minute = CStrA.ConvertStrToInt(strs2[1].Substring(2, 2)); } double open = CStrA.ConvertStrToDouble(strs2[si]); double high = CStrA.ConvertStrToDouble(strs2[si + 1]); double low = CStrA.ConvertStrToDouble(strs2[si + 2]); double close = CStrA.ConvertStrToDouble(strs2[si + 3]); double volume = CStrA.ConvertStrToDouble(strs2[si + 4]); double amount = CStrA.ConvertStrToDouble(strs2[si + 5]); if (volume == 0) { continue; } if (year != 0 && month != 0 && day != 0) { SecurityData securityData = new SecurityData(); if (hour != 0 || minute != 0) { securityData.m_date = CStrA.M129(year, month, day, hour, minute, 0, 0) - 300; } else { securityData.m_date = CStrA.M129(year, month, day, 0, 0, 0, 0); } securityData.m_open = open; securityData.m_high = high; securityData.m_low = low; securityData.m_close = close; securityData.m_volume = volume; securityData.m_amount = amount; datas.Add(securityData); } } } return(1); }
public static double SumHistoryData(CTable dataSource, double date, int cycle, int field) { double sumValue = 0; double value = 0; int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, ms = 0; CStrA.M130(date, ref year, ref month, ref day, ref hour, ref minute, ref second, ref ms); if (cycle == CYCLE_WEEK) { int dayOfWeek = DayOfWeek(year, month, day); if (dayOfWeek >= 5) { dayOfWeek = 4; } for (int i = 1; i <= dayOfWeek; i++) { double calcDate = CStrA.M129(year, month, day - i, 0, 0, 0, 0); value = dataSource.Get(calcDate, field); if (!double.IsNaN(value)) { sumValue += value; } } } else if (cycle == CYCLE_MONTH) { for (int i = 1; i < day; i++) { double calcDate = CStrA.M129(year, month, i, 0, 0, 0, 0); value = dataSource.Get(calcDate, field); if (!double.IsNaN(value)) { sumValue += value; } } } else if (cycle == 0) { int rowCount = dataSource.RowsCount; for (int i = 0; i < rowCount; i++) { value = dataSource.Get2(i, field); if (!double.IsNaN(value)) { sumValue += value; } } } return(sumValue); }
public static double GetMinuteVol(CTable dataSource, double date, int field, double volume) { int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, ms = 0; CStrA.M130(date, ref year, ref month, ref day, ref hour, ref minute, ref second, ref ms); double startDate = 0; double endDate = date; if (hour >= 6) { startDate = CStrA.M129(year, month, day, 6, 0, 0, 0); } else { double preDate = date - 86400; int lyear = 0, lmonth = 0, lday = 0, lhour = 0, lminute = 0, lsecond = 0, lms = 0; CStrA.M130(preDate, ref lyear, ref lmonth, ref lday, ref lhour, ref lminute, ref lsecond, ref lms); startDate = CStrA.M129(lyear, lmonth, lday, 6, 0, 0, 0); } int dataSize = dataSource.RowsCount; bool containsFlg = false; for (int i = dataSize - 1; i >= 0; i--) { containsFlg = false; double ldate = dataSource.GetXValue(i); if (startDate <= ldate && ldate <= endDate) { containsFlg = true; } if (!containsFlg) { break; } else { double vol = dataSource.Get2(i, KeyFields.VOL_INDEX); volume = volume - vol; } } return(volume); }
/// <summary> /// 获取分时线的历史数据 /// </summary> /// <param name="str">数据字符串</param> /// <param name="datas">历史数据</param> /// <returns>状态</returns> public static int GetHistoryDatasByMinuteStr(String str, List <SecurityData> datas) { String[] strs = str.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); int strLen = strs.Length; double lClose = 0, lHigh = 0, lLow = 0, lOpen = 0; double lVolume = 0, lAmount = 0, fVolume = 0, fAmount = 0, sum = 0; int lYear = 0, lMonth = 0, lDay = 0, lHour = 0, lMinute = 0; int startIndex = 0; for (int i = startIndex; i < strLen; i++) { String[] strs2 = strs[i].Split(','); if (strs2.Length == 4) { double date = CStrA.ConvertStrToDouble(strs2[0]); double close = CStrA.ConvertStrToDouble(strs2[1]); double volume = CStrA.ConvertStrToDouble(strs2[2]); double amount = CStrA.ConvertStrToDouble(strs2[3]); int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, ms = 0; CStrA.M130(date, ref year, ref month, ref day, ref hour, ref minute, ref second, ref ms); if (hour * 60 + minute >= 899) { hour = 14; minute = 59; } if (i == startIndex) { lClose = close; lHigh = close; lLow = close; lOpen = close; lVolume = volume; lAmount = amount; lYear = year; lMonth = month; lDay = day; lHour = hour; lMinute = minute; } bool inSameTime = false; if (hour == lHour && minute == lMinute) { inSameTime = true; if (close > lHigh) { lHigh = close; } if (close < lLow) { lLow = close; } } if (!inSameTime || i == strLen - 1) { SecurityData data = new SecurityData(); data.m_date = CStrA.M129(lYear, lMonth, lDay, lHour, lMinute, 0, 0); data.m_close = lClose; if (lHigh != 0) { data.m_high = lHigh; } else { data.m_high = lClose; } if (lLow != 0) { data.m_low = lLow; } else { data.m_low = lClose; } if (lOpen != 0) { data.m_open = lOpen; } else { data.m_open = lClose; } data.m_volume = lVolume - fVolume; data.m_amount = lAmount - fAmount; if (data.m_close != 0 && data.m_volume != 0) { sum += data.m_close; data.m_avgPrice = sum / (datas.Count + 1); datas.Add(data); } fVolume = lVolume; fAmount = lAmount; } if (!inSameTime) { lHigh = close; lLow = close; lOpen = close; lYear = year; lMonth = month; lDay = day; lHour = hour; lMinute = minute; } lClose = close; lVolume = volume; lAmount = amount; } } return(1); }
/// <summary> /// 根据字符串获取新浪的最新数据 /// </summary> /// <param name="str">数据字符串</param> /// <param name="formatType">格式</param> /// <param name="data">最新数据</param> /// <returns>状态</returns> public static int GetLatestDataBySinaStr(String str, int formatType, ref SecurityLatestData data) { //分析数据 String date = ""; String[] strs2 = str.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries); int strLen2 = strs2.Length; bool szIndex = false; for (int j = 0; j < strLen2; j++) { String str2 = strs2[j]; switch (j) { case 0: data.m_code = CStrA.ConvertSinaCodeToDBCode(str2); if (data.m_code.StartsWith("399")) { szIndex = true; } break; case 1: { data.m_open = CStrA.ConvertStrToDouble(str2); break; } case 2: { data.m_lastClose = CStrA.ConvertStrToDouble(str2); break; } case 3: { data.m_close = CStrA.ConvertStrToDouble(str2); break; } case 4: { data.m_high = CStrA.ConvertStrToDouble(str2); break; } case 5: { data.m_low = CStrA.ConvertStrToDouble(str2); break; } case 8: { data.m_volume = CStrA.ConvertStrToDouble(str2); if (szIndex) { data.m_volume /= 100; } break; } case 9: { data.m_amount = CStrA.ConvertStrToDouble(str2); break; } case 10: { if (formatType == 0) { data.m_buyVolume1 = (int)CStrA.ConvertStrToDouble(str2); } break; } case 11: { if (formatType == 0) { data.m_buyPrice1 = CStrA.ConvertStrToDouble(str2); } break; } case 12: { if (formatType == 0) { data.m_buyVolume2 = (int)CStrA.ConvertStrToDouble(str2); } break; } case 13: { if (formatType == 0) { data.m_buyPrice2 = CStrA.ConvertStrToDouble(str2); } break; } case 14: { if (formatType == 0) { data.m_buyVolume3 = (int)CStrA.ConvertStrToDouble(str2); } break; } case 15: { if (formatType == 0) { data.m_buyPrice3 = CStrA.ConvertStrToDouble(str2); } break; } case 16: { if (formatType == 0) { data.m_buyVolume4 = (int)CStrA.ConvertStrToDouble(str2); } break; } case 17: { if (formatType == 0) { data.m_buyPrice4 = CStrA.ConvertStrToDouble(str2); } break; } case 18: { if (formatType == 0) { data.m_buyVolume5 = (int)CStrA.ConvertStrToDouble(str2); } break; } case 19: { if (formatType == 0) { data.m_buyPrice5 = CStrA.ConvertStrToDouble(str2); } break; } case 20: { if (formatType == 0) { data.m_sellVolume1 = (int)CStrA.ConvertStrToDouble(str2); } break; } case 21: { if (formatType == 0) { data.m_sellPrice1 = CStrA.ConvertStrToDouble(str2); } break; } case 22: { if (formatType == 0) { data.m_sellVolume2 = (int)CStrA.ConvertStrToDouble(str2); } break; } case 23: { if (formatType == 0) { data.m_sellPrice2 = CStrA.ConvertStrToDouble(str2); } break; } case 24: { if (formatType == 0) { data.m_sellVolume3 = (int)CStrA.ConvertStrToDouble(str2); } break; } case 25: { if (formatType == 0) { data.m_sellPrice3 = CStrA.ConvertStrToDouble(str2); } break; } case 26: { if (formatType == 0) { data.m_sellVolume4 = (int)CStrA.ConvertStrToDouble(str2); } break; } case 27: { if (formatType == 0) { data.m_sellPrice4 = CStrA.ConvertStrToDouble(str2); } break; } case 28: { if (formatType == 0) { data.m_sellVolume5 = (int)CStrA.ConvertStrToDouble(str2); } break; } case 29: { if (formatType == 0) { data.m_sellPrice5 = CStrA.ConvertStrToDouble(str2); } break; } case 30: date = str2; break; case 31: date += " " + str2; break; } } //获取时间 if (date != null && date.Length > 0) { DateTime dateTime = Convert.ToDateTime(date); data.m_date = CStrA.M129(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, 0); } //价格修正 if (data.m_close != 0) { if (data.m_open == 0) { data.m_open = data.m_close; } if (data.m_high == 0) { data.m_high = data.m_close; } if (data.m_low == 0) { data.m_low = data.m_close; } } return(0); }