Ejemplo n.º 1
0
        public void RecordOHLCData()
        {
            long? since = null;
            string filePath = this.CheckFileAndDirectoryOHLCData();

            OHLCData lastdata = GetLastLineOHLCDataRecorded();
            if( lastdata != null)
            {
                since = (long)lastdata.time;
            }

            // Sending rate increase the meter and check if can continue ootherwise stop 4sec;
            SRM.RateAddition(2);
            HTMLUpdate("LastAction", "RecordOHLCData");
            OHLCReceived = this.GetOHLCDatas(since);

            // null if error in parsing likely due to a error message from API
            if (OHLCReceived == null)
            {
                //Thread.Sleep(4000);
                return;
            }

            string LinesToAdd = "";
            foreach (List<string> ls in OHLCReceived.Datas)
            {
                // Foreach line, register in file and in the lsit
                OHLCData td = new OHLCData();
                int i = 0;
                foreach (string s in ls)
                {
                    RecordOHLCDataInList(i, s, td);
                    LinesToAdd += s + ",";
                    i++;
                    //Console.Write(s);
                }

                ListOfOHLCData.Add(td);
                LinesToAdd += Environment.NewLine;
            }

            //File.AppendAllText(filePath,LinesToAdd);
            using (StreamWriter writer = new StreamWriter(File.OpenWrite(filePath)))
            {
                var csv = new CsvWriter(writer);
                csv.WriteRecords(ListOfOHLCData);
            }

            since = OHLCReceived.Last;
            Double interval = GetServerTime().unixtime;
            //ListOftradingDatas.RemoveAll(a => a.UnixTime < (interval - IntervalInSecond));
        }
Ejemplo n.º 2
0
        public void RecordOHLCDataInList(int i, string value, OHLCData td)
        {
            // Create a NumberFormatInfo object and set some of its properties.

            switch (i)
            {
                case 0:
                    td.time = Convert.ToDouble(value, NumberProvider);
                    break;
                case 1:
                    td.open = Convert.ToDouble(value, NumberProvider);
                    break;
                case 2:
                    td.high = Convert.ToDouble(value, NumberProvider);
                    break;
                case 3:
                    td.low = Convert.ToDouble(value, NumberProvider);
                    break;
                case 4:
                    td.close = Convert.ToDouble(value, NumberProvider);
                    break;
                case 5:
                    td.vwap = value;
                    break;
                case 6:
                    td.volume = Convert.ToDouble(value, NumberProvider);
                    break;
                case 7:
                    td.count = Convert.ToInt32(value);
                    break;
            }
        }
Ejemplo n.º 3
0
        public OHLCData GetLastLineOHLCDataRecorded()
        {
            OHLCData OHLCLastData = new OHLCData();

            using (StreamReader reader = File.OpenText(CheckFileAndDirectoryOHLCData()))
            {
                var csv = new CsvReader(reader);
                var records = csv.GetRecords<OHLCData>();
                try
                {
                    OHLCLastData = records.OrderByDescending(a => a.time).FirstOrDefault();
                }
                catch (Exception)
                {
                    return null;
                }
            }

            return OHLCLastData;
        }