| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118 |
- namespace Easychart.Finance.DataProvider
- {
- using Easychart.Finance;
- using System;
- using System.Collections;
- using System.IO;
- using System.Reflection;
- public class CommonDataProvider : IDataProvider
- {
- private bool adjusted = true;
- private IDataProvider baseDataProvider;
- private Easychart.Finance.DataCycle dataCycle = Easychart.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", "TURNOVERS" };
- 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(Easychart.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":
- case "TURNOVERS":
- 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);
- }
- }
- 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);
- }
- if (ds.Length > 7)
- {
- this.htData.Add("TURNOVERS", ds[7]);
- }
- else
- {
- double[] dst = new double[ds[0].Length];
- Buffer.BlockCopy(ds[3], 0, dst, 0, ds[0].Length * 8);
- this.htData.Add("TURNOVERS", 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, Easychart.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 Easychart.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
- {
- try
- {
- return this.GetData(Name);
- }
- catch (Exception ex)
- {
- return new double[]{};
- }
- }
- }
- public int MaxCount
- {
- get
- {
- return this.maxCount;
- }
- set
- {
- this.maxCount = value;
- }
- }
- protected int WeekAdjust
- {
- get
- {
- return this.weekAdjust;
- }
- set
- {
- this.weekAdjust = value;
- }
- }
- public void Dispose()
- {
- htAllCycle.Clear();
- htAllCycle.Clear();
- htConstData.Clear();
- htData.Clear();
- htRealtime.Clear();
- htStringData.Clear();
- }
- }
- }
|