| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092 |
- namespace IndexFormula.Finance.DataProvider
- {
- using IndexFormula.Finance;
- using System;
- using System.Collections;
- using System.IO;
- using System.Reflection;
- public class CommonDataProvider : IDataProvider
- {
- private bool adjusted = true;
- private IDataProvider baseDataProvider;
- private IndexFormula.Finance.DataCycle dataCycle = IndexFormula.Finance.DataCycle.Day;
- private MergeCycleType dateMergeType = MergeCycleType.OPEN;
- private IDataManager dm;
- private int futureBars;
- private Hashtable htAllCycle = new Hashtable();
- private Hashtable htConstData = new Hashtable();
- private Hashtable htData = new Hashtable();
- private Hashtable htRealtime = new Hashtable();
- private Hashtable htStringData = new Hashtable();
- private ExchangeIntraday intradayInfo;
- private bool isPointAndFigure;
- private static string[] Keys = new string[] { "DATE", "OPEN", "HIGH", "LOW", "CLOSE", "VOLUME", "ADJCLOSE" };
- private int maxCount = -1;
- private int weekAdjust;
- public CommonDataProvider(IDataManager dm)
- {
- this.dm = dm;
- }
- private double[] AdjustByBase(double[] Date, double[] dd)
- {
- double[] numArray = this.BaseDataProvider["DATE"];
- double[] numArray2 = new double[numArray.Length];
- for (int i = 0; i < numArray.Length; i++)
- {
- numArray2[i] = double.NaN;
- }
- int index = dd.Length - 1;
- int num3 = numArray.Length - 1;
- while ((num3 >= 0) && (index >= 0))
- {
- if (numArray[num3] == Date[index])
- {
- numArray2[num3--] = dd[index--];
- }
- else
- {
- if (numArray[num3] > Date[index])
- {
- num3--;
- continue;
- }
- index--;
- }
- }
- return numArray2;
- }
- public static void AppendStreamingData(string Path, StreamingData sd)
- {
- using (FileStream stream = File.OpenWrite(string.Format(Path, sd.Symbol)))
- {
- using (BinaryWriter writer = new BinaryWriter(stream))
- {
- writer.Write(sd.QuoteTime.ToOADate());
- writer.Write(sd.Price);
- writer.Write(sd.Volume);
- }
- }
- }
- public void ClearData()
- {
- this.htData.Clear();
- for (int i = 0; i < Keys.Length; i++)
- {
- this.htData.Add(Keys[i], new double[0]);
- }
- this.htAllCycle.Clear();
- }
- public void DeleteData(DateTime FromTime, DateTime ToTime)
- {
- ArrayList[] listArray = new ArrayList[Keys.Length];
- for (int i = 0; i < listArray.Length; i++)
- {
- listArray[i] = new ArrayList();
- listArray[i].AddRange(this[Keys[i]]);
- }
- double num2 = FromTime.ToOADate();
- double num3 = ToTime.ToOADate();
- int index = 0;
- while (index < listArray[0].Count)
- {
- double num5 = (double) listArray[0][index];
- if ((num5 > num2) && (num5 < num3))
- {
- for (int k = 0; k < Keys.Length; k++)
- {
- listArray[k].RemoveAt(index);
- }
- }
- else
- {
- index++;
- }
- }
- this.htData.Clear();
- for (int j = 0; j < Keys.Length; j++)
- {
- this.htData.Add(Keys[j], (double[]) listArray[j].ToArray(typeof(double)));
- }
- this.htAllCycle.Clear();
- }
- private Hashtable DoExpandMinute(Hashtable ht)
- {
- double[] numArray = (double[]) ht["DATE"];
- if ((numArray == null) || (numArray.Length <= 0))
- {
- return ht;
- }
- double num = 0.00069444444444444436;
- double num2 = (int) numArray[0];
- double num3 = (int) (numArray[numArray.Length - 1] + 1.0);
- ArrayList list = new ArrayList();
- ArrayList list2 = new ArrayList();
- double d = (int) num2;
- for (int i = 1; i < numArray.Length; i++)
- {
- int end = (int) numArray[i];
- int start = (int) numArray[i - 1];
- if ((end - start) > 1)
- {
- this.intradayInfo.AddRemoveDays(start, end);
- }
- }
- int index = 0;
- while (d <= num3)
- {
- if (this.intradayInfo.InTimePeriod(d))
- {
- if (index >= numArray.Length)
- {
- list.Add(d);
- list2.Add(-1);
- }
- else
- {
- if (numArray[index] < (d - (num * 0.0001)))
- {
- index++;
- continue;
- }
- if (numArray[index] < (d + (num * 0.9999)))
- {
- list.Add(numArray[index]);
- list2.Add(index);
- index++;
- continue;
- }
- if ((list.Count == 0) || (((double) list[list.Count - 1]) < (d + (num / 100.0))))
- {
- list.Add(d + (num / 100.0));
- if (this.intradayInfo.InTimePeriod(numArray[index]))
- {
- if (list2.Count > 0)
- {
- list2.Add(list2[list2.Count - 1]);
- }
- else
- {
- list2.Add(0);
- }
- }
- else
- {
- list2.Add(index);
- }
- }
- }
- }
- for (d += num; this.intradayInfo.InRemoveDays(d); d++)
- {
- }
- }
- Hashtable hashtable = new Hashtable();
- double[] numArray2 = (double[]) ht["CLOSE"];
- foreach (string str in ht.Keys)
- {
- double[] numArray3 = (double[]) ht[str];
- double[] numArray4 = new double[list.Count];
- for (int j = 0; j < list.Count; j++)
- {
- if (str == "DATE")
- {
- numArray4[j] = (double) list[j];
- }
- else
- {
- int num10 = (int) list2[j];
- if (num10 < 0)
- {
- numArray4[j] = double.NaN;
- }
- else if (((j > 0) && (((int) list2[j]) == ((int) list2[j - 1]))) || ((j == 0) && (((int) list2[j]) == 0)))
- {
- if (str == "VOLUME")
- {
- numArray4[j] = 0.0;
- }
- else
- {
- numArray4[j] = numArray2[num10];
- }
- }
- else
- {
- numArray4[j] = numArray3[num10];
- }
- }
- }
- hashtable[str] = numArray4;
- }
- return hashtable;
- }
- private Hashtable ExpandFutureBars(Hashtable ht)
- {
- double[] numArray = (double[]) ht["DATE"];
- if ((numArray != null) && (numArray.Length > 0))
- {
- Hashtable hashtable = new Hashtable();
- double[] numArray2 = (double[]) ht["CLOSE"];
- foreach (string str in ht.Keys)
- {
- double[] numArray3 = (double[]) ht[str];
- double[] numArray4 = new double[numArray3.Length + this.futureBars];
- for (int i = 0; i < numArray3.Length; i++)
- {
- numArray4[i] = numArray3[i];
- }
- double num2 = DateTime.Today.ToOADate();
- if ((str == "DATE") && (numArray3.Length > 0))
- {
- num2 = numArray3[numArray3.Length - 1];
- }
- for (int j = numArray3.Length; j < numArray4.Length; j++)
- {
- if (str == "DATE")
- {
- numArray4[j] = (num2 + (j - numArray3.Length)) + 1.0;
- }
- else
- {
- numArray4[j] = double.NaN;
- }
- }
- hashtable[str] = numArray4;
- }
- return hashtable;
- }
- return ht;
- }
- private double First(double d1, double d2)
- {
- if (double.IsNaN(d1))
- {
- return d2;
- }
- return d1;
- }
- public double GetConstData(string DataType)
- {
- return (double) this.htConstData[DataType];
- }
- public Hashtable GetCycleData(IndexFormula.Finance.DataCycle dc)
- {
- if (((dc.CycleBase == DataCycleBase.DAY) && (dc.Repeat == 1)) && !this.Adjusted)
- {
- return this.htData;
- }
- dc.WeekAdjust = this.weekAdjust;
- Hashtable hashtable = (Hashtable) this.htAllCycle[dc.ToString()];
- if (hashtable == null)
- {
- if (this.htData == null)
- {
- return this.htData;
- }
- Hashtable htData = this.htData;
- if (this.intradayInfo != null)
- {
- htData = this.DoExpandMinute(htData);
- }
- if (this.futureBars != 0)
- {
- htData = this.ExpandFutureBars(htData);
- }
- if (htData["CLOSE"] != null)
- {
- if (htData["OPEN"] == null)
- {
- htData["OPEN"] = htData["CLOSE"];
- }
- if (htData["HIGH"] == null)
- {
- htData["HIGH"] = htData["CLOSE"];
- }
- if (htData["LOW"] == null)
- {
- htData["LOW"] = htData["CLOSE"];
- }
- }
- double[] oDATE = (double[]) htData["DATE"];
- if (oDATE == null)
- {
- return null;
- }
- int[] nEWDATE = new int[oDATE.Length];
- int num = -2147483648;
- int num2 = -1;
- for (int i = 0; i < oDATE.Length; i++)
- {
- int sequence;
- if (this.DataCycle.CycleBase == DataCycleBase.TICK)
- {
- sequence = i;
- }
- else
- {
- sequence = this.DataCycle.GetSequence(oDATE[i]);
- }
- if (sequence > num)
- {
- num2++;
- }
- nEWDATE[i] = num2;
- num = sequence;
- }
- hashtable = new Hashtable();
- foreach (string str in htData.Keys)
- {
- hashtable[str] = new double[num2 + 1];
- }
- bool flag = (this.Adjusted && (htData["ADJCLOSE"] != null)) && (htData["CLOSE"] != null);
- double[] cLOSE = (double[]) htData["CLOSE"];
- double[] aDJCLOSE = (double[]) htData["ADJCLOSE"];
- foreach (string str2 in htData.Keys)
- {
- MergeCycleType dateMergeType;
- bool doAdjust = flag;
- doAdjust = false;
- switch (str2)
- {
- case "DATE":
- dateMergeType = this.dateMergeType;
- break;
- case "VOLUME":
- case "AMOUNT":
- dateMergeType = MergeCycleType.SUM;
- break;
- default:
- try
- {
- dateMergeType = (MergeCycleType) Enum.Parse(typeof(MergeCycleType), str2);
- doAdjust = true;
- }
- catch
- {
- dateMergeType = MergeCycleType.CLOSE;
- }
- break;
- }
- this.MergeCycle(oDATE, nEWDATE, cLOSE, aDJCLOSE, (double[]) htData[str2], (double[]) hashtable[str2], dateMergeType, doAdjust);
- }
- this.htAllCycle[dc.ToString()] = hashtable;
- }
- return hashtable;
- }
- private double[] GetData(string DataType)
- {
- Hashtable cycleData = this.GetCycleData(this.DataCycle);
- if (cycleData == null)
- {
- throw new Exception(string.Concat(new object[] { "Quote data ", DataType, " ", this.DataCycle, " not found" }));
- }
- double[] dd = (double[]) cycleData[DataType.ToUpper()];
- if (dd == null)
- {
- throw new Exception("The name " + DataType + " does not exist.");
- }
- if ((this.BaseDataProvider != null) && (this.BaseDataProvider != this))
- {
- dd = this.AdjustByBase((double[]) cycleData["DATE"], dd);
- }
- if ((this.MaxCount == -1) || (dd.Length <= this.MaxCount))
- {
- return dd;
- }
- double[] destinationArray = new double[this.MaxCount];
- Array.Copy(dd, dd.Length - this.MaxCount, destinationArray, 0, this.MaxCount);
- return destinationArray;
- }
- public DataPacket GetDataPackage(int Index)
- {
- return new DataPacket(this.GetStringData("Code"), this["DATE"][Index], (double) ((float) this["OPEN"][Index]), (double) ((float) this["HIGH"][Index]), (double) ((float) this["LOW"][Index]), (double) ((float) this["CLOSE"][Index]), this["VOLUME"][Index], (double) ((float) this["ADJCLOSE"][Index]));
- }
- public DataPacket[] GetLastDataPackages(int Count)
- {
- return this.GetLastDataPackages(this.Count - Count, Count);
- }
- public DataPacket[] GetLastDataPackages(int Start, int Count)
- {
- DataPacket[] packetArray = new DataPacket[Count];
- double[] numArray = this["DATE"];
- double[] numArray2 = this["OPEN"];
- double[] numArray3 = this["HIGH"];
- double[] numArray4 = this["LOW"];
- double[] numArray5 = this["CLOSE"];
- double[] numArray6 = this["VOLUME"];
- double[] numArray7 = this["ADJCLOSE"];
- for (int i = Start; i < (Start + Count); i++)
- {
- if ((i >= 0) && (i < this.Count))
- {
- packetArray[i - Start] = new DataPacket(this.GetStringData("Code"), numArray[i], (double) ((float) numArray2[i]), (double) ((float) numArray3[i]), (double) ((float) numArray4[i]), (double) ((float) numArray5[i]), numArray6[i], (double) ((float) numArray7[i]));
- }
- }
- return packetArray;
- }
- public DataPacket GetLastPackage()
- {
- return this.GetDataPackage(this.Count - 1);
- }
- public string GetStringData(string DataType)
- {
- return (string) this.htStringData[DataType.ToUpper()];
- }
- public string GetUnique()
- {
- return this.DataCycle.ToString();
- }
- public void LoadBinary(Stream stream)
- {
- byte[] buffer = new byte[stream.Length];
- stream.Read(buffer, 0, (int) stream.Length);
- this.LoadByteBinary(buffer);
- }
- public void LoadBinary(string FileName)
- {
- using (FileStream stream = new FileStream(FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
- {
- this.LoadBinary(stream);
- }
- }
- /// <summary>
- /// 载入数据源
- /// </summary>
- /// <param name="ds">二维double数据源,ds[0]=OPEN,ds[1]=HIGH,ds[2]=LOW,ds[3]=CLOSE,ds[4]=VOLUME,ds[5]=DATE</param>
- public void LoadBinary(double[][] ds)
- {
- if (ds.Length > 4)
- {
- this.htData.Clear();
- this.htData.Add("OPEN", ds[0]);
- this.htData.Add("HIGH", ds[1]);
- this.htData.Add("LOW", ds[2]);
- this.htData.Add("CLOSE", ds[3]);
- this.htData.Add("VOLUME", ds[4]);
- this.htData.Add("DATE", ds[5]);
- if (ds.Length > 6)
- {
- this.htData.Add("ADJCLOSE", ds[6]);
- }
- else
- {
- double[] dst = new double[ds[0].Length];
- Buffer.BlockCopy(ds[3], 0, dst, 0, ds[0].Length * 8);
- this.htData.Add("ADJCLOSE", dst);
- }
- }
- this.htAllCycle.Clear();
- }
- public void LoadBinary(byte[] bs, int N)
- {
- this.htData.Clear();
- double[] numArray = new double[N];
- double[] numArray2 = new double[N];
- double[] numArray3 = new double[N];
- double[] numArray4 = new double[N];
- double[] dst = new double[N];
- double[] numArray6 = new double[N];
- double[] numArray7 = new double[N];
- float[] numArray8 = new float[N * DataPacket.PacketSize];
- Buffer.BlockCopy(bs, 0, numArray8, 0, bs.Length);
- for (int i = 0; i < N; i++)
- {
- Buffer.BlockCopy(numArray8, i * DataPacket.PacketByteSize, numArray6, i * 8, 8);
- numArray[i] = numArray8[(i * DataPacket.PacketSize) + 5];
- numArray2[i] = numArray8[(i * DataPacket.PacketSize) + 2];
- if (numArray2[i] == 0.0)
- {
- numArray2[i] = numArray[i];
- }
- numArray3[i] = numArray8[(i * DataPacket.PacketSize) + 3];
- if (numArray3[i] == 0.0)
- {
- numArray3[i] = numArray[i];
- }
- numArray4[i] = numArray8[(i * DataPacket.PacketSize) + 4];
- if (numArray4[i] == 0.0)
- {
- numArray4[i] = numArray[i];
- }
- Buffer.BlockCopy(numArray8, ((i * DataPacket.PacketSize) + 6) * 4, dst, i * 8, 8);
- numArray7[i] = numArray8[(i * DataPacket.PacketSize) + 8];
- }
- this.htData.Add("CLOSE", numArray);
- this.htData.Add("OPEN", numArray2);
- this.htData.Add("HIGH", numArray3);
- this.htData.Add("LOW", numArray4);
- this.htData.Add("VOLUME", dst);
- this.htData.Add("DATE", numArray6);
- this.htData.Add("ADJCLOSE", numArray7);
- this.htAllCycle.Clear();
- }
- public void LoadBinary(string DataType, double[] ds)
- {
- this.htData[DataType.ToUpper()] = ds;
- this.htAllCycle.Clear();
- }
- public void LoadByteBinary(byte[] bs)
- {
- this.LoadBinary(bs, bs.Length / DataPacket.PacketByteSize);
- }
- public void LoadStreamingBinary(Stream stream)
- {
- byte[] buffer = new byte[stream.Length];
- stream.Read(buffer, 0, (int) stream.Length);
- this.LoadStreamingBinary(buffer);
- }
- public void LoadStreamingBinary(string FileName)
- {
- using (FileStream stream = File.OpenRead(FileName))
- {
- this.LoadStreamingBinary(stream);
- }
- }
- public void LoadStreamingBinary(byte[] bs)
- {
- int num = bs.Length / 0x18;
- this.htData.Clear();
- double[] numArray = new double[num];
- double[] numArray2 = new double[num];
- double[] numArray3 = new double[num];
- double[] dst = new double[num * 3];
- Buffer.BlockCopy(bs, 0, dst, 0, bs.Length);
- for (int i = 0; i < num; i++)
- {
- numArray3[i] = dst[i * 3];
- numArray[i] = dst[(i * 3) + 1];
- numArray2[i] = dst[(i * 3) + 2];
- }
- this.htData.Add("CLOSE", numArray);
- this.htData.Add("VOLUME", numArray2);
- this.htData.Add("DATE", numArray3);
- this.htAllCycle.Clear();
- }
- private double Max(double d1, double d2)
- {
- if (double.IsNaN(d1))
- {
- return d2;
- }
- return Math.Max(d1, d2);
- }
- public void Merge(CommonDataProvider cdp)
- {
- ArrayList[] listArray = new ArrayList[Keys.Length];
- ArrayList[] listArray2 = new ArrayList[Keys.Length];
- for (int i = 0; i < listArray.Length; i++)
- {
- listArray[i] = new ArrayList();
- listArray[i].AddRange((double[]) this.htData[Keys[i]]);
- listArray2[i] = new ArrayList();
- listArray2[i].AddRange((double[]) cdp.htData[Keys[i]]);
- }
- int index = 0;
- int num3 = 0;
- while (num3 < listArray2[0].Count)
- {
- if (index < listArray[0].Count)
- {
- if (((double) listArray[0][index]) < ((double) listArray2[0][num3]))
- {
- index++;
- }
- else if (((double) listArray[0][index]) >= ((double) listArray2[0][num3]))
- {
- if (((double) listArray[0][index]) > ((double) listArray2[0][num3]))
- {
- for (int k = 0; k < Keys.Length; k++)
- {
- listArray[k].Insert(index, listArray2[k][num3]);
- }
- }
- else
- {
- for (int m = 1; m < Keys.Length; m++)
- {
- listArray[m][index] = listArray2[m][num3];
- }
- }
- index++;
- num3++;
- }
- }
- else
- {
- for (int n = num3; n < listArray2[0].Count; n++)
- {
- for (int num7 = 0; num7 < Keys.Length; num7++)
- {
- listArray[num7].Add(listArray2[num7][n]);
- }
- }
- break;
- }
- }
- this.htData.Clear();
- for (int j = 0; j < Keys.Length; j++)
- {
- this.htData.Add(Keys[j], (double[]) listArray[j].ToArray(typeof(double)));
- }
- this.htAllCycle.Clear();
- }
- public void Merge(DataPacket dp)
- {
- if ((dp != null) && !dp.IsZeroValue)
- {
- ArrayList[] listArray = new ArrayList[Keys.Length];
- for (int i = 0; i < listArray.Length; i++)
- {
- listArray[i] = new ArrayList();
- listArray[i].AddRange((double[]) this.htData[Keys[i]]);
- }
- for (int j = 0; j <= listArray[0].Count; j++)
- {
- if (j < listArray[0].Count)
- {
- if (((double) listArray[0][j]) < dp.DoubleDate)
- {
- continue;
- }
- if (((double) listArray[0][j]) > dp.DoubleDate)
- {
- for (int m = 0; m < Keys.Length; m++)
- {
- listArray[m].Insert(j, dp[Keys[m]]);
- }
- }
- else
- {
- for (int n = 1; n < Keys.Length; n++)
- {
- listArray[n][j] = dp[Keys[n]];
- }
- }
- }
- else
- {
- for (int num5 = 0; num5 < Keys.Length; num5++)
- {
- listArray[num5].Add(dp[Keys[num5]]);
- }
- }
- break;
- }
- this.htData.Clear();
- for (int k = 0; k < Keys.Length; k++)
- {
- this.htData.Add(Keys[k], (double[]) listArray[k].ToArray(typeof(double)));
- }
- this.htAllCycle.Clear();
- }
- }
- private void MergeCycle(double[] ODATE, int[] NEWDATE, double[] CLOSE, double[] ADJCLOSE, double[] ht, double[] htCycle, MergeCycleType mct, bool DoAdjust)
- {
- int num = -1;
- int index = -1;
- for (int i = 0; i < ODATE.Length; i++)
- {
- double num4 = 1.0;
- if (DoAdjust && (ADJCLOSE != null))
- {
- num4 = ADJCLOSE[i] / CLOSE[i];
- }
- double num5 = ht[i] * num4;
- if (num4 != 1.0)
- {
- num5 = Math.Round(num5, 2);
- }
- if (num != NEWDATE[i])
- {
- index++;
- htCycle[index] = num5;
- }
- else if (!double.IsNaN(num5))
- {
- if (mct == MergeCycleType.HIGH)
- {
- htCycle[index] = this.Max(htCycle[index], num5);
- }
- else if (mct == MergeCycleType.LOW)
- {
- htCycle[index] = this.Min(htCycle[index], num5);
- }
- else if (mct == MergeCycleType.CLOSE)
- {
- htCycle[index] = num5;
- }
- else if (mct == MergeCycleType.ADJCLOSE)
- {
- htCycle[index] = ht[i];
- }
- else if (mct == MergeCycleType.OPEN)
- {
- htCycle[index] = this.First(htCycle[index], num5);
- }
- else
- {
- htCycle[index] = this.Sum(htCycle[index], num5);
- }
- }
- num = NEWDATE[i];
- }
- }
- public static DataPacket MergeFile(string Filename, DataPacket dp, IndexFormula.Finance.DataCycle dc)
- {
- using (FileStream stream = new FileStream(Filename, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
- {
- byte[] buffer = new byte[DataPacket.PacketByteSize];
- if (stream.Length >= buffer.Length)
- {
- stream.Seek((long) -buffer.Length, SeekOrigin.End);
- }
- int num = stream.Read(buffer, 0, buffer.Length);
- DataPacket packet = DataPacket.FromBytes(buffer);
- packet.Symbol = dp.Symbol;
- if (packet.Merge(dp, dc))
- {
- stream.Seek((long) -buffer.Length, SeekOrigin.End);
- }
- buffer = packet.ToByte();
- stream.Write(buffer, 0, buffer.Length);
- return packet;
- }
- }
- public static byte[] MergeOneQuote(byte[] bs, DataPacket dp)
- {
- float[] dst = new float[(bs.Length / 4) + DataPacket.PacketSize];
- Buffer.BlockCopy(bs, 0, dst, 0, bs.Length);
- DateTime date = dp.Date.Date;
- int num = (dst.Length / DataPacket.PacketSize) - 1;
- for (int i = num - 1; i >= -1; i--)
- {
- DateTime minValue = DateTime.MinValue;
- if (i > -1)
- {
- minValue = DataPacket.GetDateTime(dst, i).Date;
- }
- int num3 = 0;
- if (minValue <= date)
- {
- if (minValue < date)
- {
- if ((i < (num - 1)) && (num > 0))
- {
- Buffer.BlockCopy(dst, (i + 1) * DataPacket.PacketByteSize, dst, (i + 2) * DataPacket.PacketByteSize, ((num - i) - 1) * DataPacket.PacketByteSize);
- }
- num3 = 1;
- }
- Buffer.BlockCopy(dp.GetFloat(), 0, dst, (i + num3) * DataPacket.PacketByteSize, DataPacket.PacketByteSize);
- bs = new byte[(dst.Length * 4) - ((1 - num3) * DataPacket.PacketByteSize)];
- Buffer.BlockCopy(dst, 0, bs, 0, bs.Length);
- return bs;
- }
- }
- return bs;
- }
- private double Min(double d1, double d2)
- {
- if (double.IsNaN(d1))
- {
- return d2;
- }
- return Math.Min(d1, d2);
- }
- public byte[] SaveBinary()
- {
- MemoryStream stream = new MemoryStream();
- this.SaveBinary(stream);
- return stream.ToArray();
- }
- public void SaveBinary(Stream stream)
- {
- using (BinaryWriter writer = new BinaryWriter(stream))
- {
- double[] numArray = (double[]) this.htData["CLOSE"];
- double[] numArray2 = (double[]) this.htData["OPEN"];
- double[] numArray3 = (double[]) this.htData["HIGH"];
- double[] numArray4 = (double[]) this.htData["LOW"];
- double[] numArray5 = (double[]) this.htData["VOLUME"];
- double[] numArray6 = (double[]) this.htData["DATE"];
- double[] numArray7 = (double[]) this.htData["ADJCLOSE"];
- int length = numArray.Length;
- for (int i = 0; i < length; i++)
- {
- writer.Write(numArray6[i]);
- writer.Write((float) numArray2[i]);
- writer.Write((float) numArray3[i]);
- writer.Write((float) numArray4[i]);
- writer.Write((float) numArray[i]);
- writer.Write(numArray5[i]);
- writer.Write((float) numArray7[i]);
- }
- }
- }
- public void SaveBinary(string FileName)
- {
- using (FileStream stream = new FileStream(FileName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
- {
- this.SaveBinary(stream);
- }
- }
- public byte[] SaveStreamingBinary()
- {
- MemoryStream stream = new MemoryStream();
- this.SaveStreamingBinary(stream);
- return stream.ToArray();
- }
- public void SaveStreamingBinary(Stream stream)
- {
- using (BinaryWriter writer = new BinaryWriter(stream))
- {
- double[] numArray = (double[]) this.htData["CLOSE"];
- double[] numArray2 = (double[]) this.htData["VOLUME"];
- double[] numArray3 = (double[]) this.htData["DATE"];
- int length = numArray.Length;
- for (int i = 0; i < length; i++)
- {
- writer.Write(numArray3[i]);
- writer.Write(numArray[i]);
- writer.Write(numArray2[i]);
- }
- }
- }
- public void SaveStreamingBinary(string FileName)
- {
- this.SaveStreamingBinary(File.OpenWrite(FileName));
- }
- public void SetStringData(string DataType, string Value)
- {
- this.htStringData[DataType.ToUpper()] = Value;
- }
- private double Sum(double d1, double d2)
- {
- if (double.IsNaN(d1))
- {
- return d2;
- }
- return (d1 + d2);
- }
- public void TrimTime()
- {
- double[] numArray = (double[]) this.htData["DATE"];
- for (int i = 0; i < numArray.Length; i++)
- {
- numArray[i] = (int) numArray[i];
- }
- }
- public bool Adjusted
- {
- get
- {
- return this.adjusted;
- }
- set
- {
- this.adjusted = value;
- }
- }
- public ICollection AllDataType
- {
- get
- {
- return this.htData.Keys;
- }
- }
- public IDataProvider BaseDataProvider
- {
- get
- {
- return this.baseDataProvider;
- }
- set
- {
- this.baseDataProvider = value;
- }
- }
- public int Count
- {
- get
- {
- return this["DATE"].Length;
- }
- }
- public IndexFormula.Finance.DataCycle DataCycle
- {
- get
- {
- return this.dataCycle;
- }
- set
- {
- this.dataCycle = value;
- }
- }
- public IDataManager DataManager
- {
- get
- {
- if (this.dm == null)
- {
- return this.dm;
- }
- return this.dm;
- }
- set
- {
- this.dm = value;
- }
- }
- public MergeCycleType DateMergeType
- {
- get
- {
- return this.dateMergeType;
- }
- set
- {
- this.dateMergeType = value;
- }
- }
- public static CommonDataProvider Empty
- {
- get
- {
- CommonDataProvider provider = new CommonDataProvider(null);
- provider.LoadByteBinary(new byte[0]);
- return provider;
- }
- }
- public int FutureBars
- {
- get
- {
- return this.futureBars;
- }
- set
- {
- this.futureBars = value;
- }
- }
- public bool HasData
- {
- get
- {
- return (((double[]) this.htData["DATE"]).Length > 0);
- }
- }
- public ExchangeIntraday IntradayInfo
- {
- get
- {
- return this.intradayInfo;
- }
- set
- {
- this.intradayInfo = value;
- this.htAllCycle.Clear();
- }
- }
- public bool IsPointAndFigure
- {
- get
- {
- return this.isPointAndFigure;
- }
- set
- {
- this.isPointAndFigure = value;
- }
- }
- public double[] this[string Name]
- {
- get
- {
- return this.GetData(Name);
- }
- }
- public int MaxCount
- {
- get
- {
- return this.maxCount;
- }
- set
- {
- this.maxCount = value;
- }
- }
- protected int WeekAdjust
- {
- get
- {
- return this.weekAdjust;
- }
- set
- {
- this.weekAdjust = value;
- }
- }
- }
- }
|