Ejemplo n.º 1
0
        /// <summary>
        /// Returns archive key storage for currency pair and specified interval
        /// </summary>
        /// <param name="pair"></param>
        /// <param name="interval"></param>
        /// <returns></returns>
        public string GetKey(string pair, OHLC.Interval interval)
        {
            if (pair == null)
            {
                return(null);
            }

            return(pair + (int)interval); //pair.Name
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Default interval = 1
        /// since = return committed OHLC data since given id (optional.  exclusive)
        ///
        /// The last entry in the OHLC array is for the current, not-yet-committed frame and will always be present, regardless of the value of "since".
        /// </summary>
        /// <param name="pair"></param>
        /// <param name="interval"></param>
        /// <param name="since"></param>
        /// <returns></returns>
        public OHLC GetOHLC(string pair, OHLC.Interval interval = OHLC.Interval._1m, string since = null)
        {
            string props = string.Format("pair={0}", pair);

            props += string.Format("&interval={0}", (int)interval);


            if (since != null)
            {
                props += string.Format("&since={0}", since);
            }

            string response = QueryPublic("OHLC", props);

            if (response == null)
            {
                return(null);
            }

            ObjResult result = JsonConvert.DeserializeObject <ObjResult>(response);

            if (result.Error == null || result.Error.Count > 0)
            {
                return(null);
            }

            OHLC ohlc = JsonConvert.DeserializeObject <OHLC>(result.Result.ToString());

            //OHLC ohlc = new OHLC();
            foreach (JProperty property in result.Result.Children())
            {
                try
                {
                    if (property.Name != pair)
                    {
                        continue;
                    }

                    ohlc.PairName = pair;

                    if (property.Value == null)
                    {
                        continue;
                    }

                    decimal[][] value = JsonConvert.DeserializeObject <decimal[][]>(property.Value.ToString());

                    List <OHLCEntry> entries = new List <OHLCEntry>();
                    foreach (decimal[] array in value)
                    {
                        if (array.IsNullOrEmpty())
                        {
                            continue;
                        }

                        OHLCEntry entry = new OHLCEntry();
                        entry.Entry = array;
                        entries.Add(entry);
                    }


                    ohlc.Entries = entries.ToArray();

                    break;
                }
                catch (Exception ex)
                {
                    ex.ToOutput();
                    continue;
                }
            }


            return(ohlc);
        }
Ejemplo n.º 3
0
        public ArchiveEntriesJson Get(string pair, OHLC.Interval interval)
        {
            string key = this.GetKey(pair, interval);

            return(this.Get(key));
        }
Ejemplo n.º 4
0
 public OHLC GetOHLC(string pair, OHLC.Interval interval, TickTime since)
 {
     return(this.GetOHLC(pair, interval, ((long)since.ToUnixTimeStamp()) + ""));
 }