Exemplo n.º 1
0
        public List <GlobalPrice> GetFeed()
        {
            ArrayList          quotes = _api.getData();
            List <GlobalPrice> feed   = new List <GlobalPrice>();

            if (_api.getStatus().Equals("OK"))
            {
                IEnumerator itr = quotes.GetEnumerator();
                while (itr.MoveNext())
                {
                    Hashtable quote    = (Hashtable)(itr.Current);
                    DateTime  dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
                    dateTime = dateTime.AddSeconds(Convert.ToDouble(quote["time"])).ToLocalTime();
                    feed.Add(new GlobalPrice
                    {
                        Ask         = Convert.ToDecimal(quote["ask"]),
                        Bid         = Convert.ToDecimal(quote["bid"]),
                        Open        = Convert.ToDecimal(quote["open"]),
                        High        = Convert.ToDecimal(quote["high"]),
                        Low         = Convert.ToDecimal(quote["low"]),
                        Close       = Convert.ToDecimal(quote["close"]),
                        CaptureTime = dateTime,
                    });
                }
            }
            else
            {
                throw new Exception(_api.getErrorMessage());
            }

            return(feed);
        }
Exemplo n.º 2
0
        private bool RequestNewData(BarSize barSize, List <string> symbols, out Dictionary <string, Hashtable> data)
        {
            StringBuilder sb = new StringBuilder();

            foreach (var symbol in symbols)
            {
                if (sb.Length > 0)
                {
                    sb.Append(",");
                }

                sb.Append(symbol);
            }

            _api.setTimeout(30);
            _api.setSymbol(sb.ToString());
            _api.setInterval(_intervalCache[barSize]);
            _api.setPeriods(1);
            ArrayList quotes = _api.getData();

            if (_api.getStatus().Equals("OK"))
            {
                Dictionary <string, Hashtable> locData = new Dictionary <string, Hashtable>();

                foreach (var quoteTmp in quotes)
                {
                    Hashtable quote = (Hashtable)quoteTmp;
                    locData.Add((string)quote["symbol"], quote);
                }

                data = locData;
                return(true);
            }

            LogError("getData");
            data = null;
            return(false);
        }
Exemplo n.º 3
0
    // ''
    // ''  Get the data and print it to System.Console
    // ''
    private static void printData(feedapi fxfeed)
    {
        //
        //   Fetch the Data
        //
        ArrayList quotes = fxfeed.getData();

        Console.WriteLine("-------- Quotes --------");
        if (fxfeed.getStatus().Equals("OK"))
        {
            Console.WriteLine(("Number of Quotes: " + fxfeed.getNumQuotes()));
            Console.WriteLine(("Copyright: " + fxfeed.getCopyright()));
            Console.WriteLine(("Website: " + fxfeed.getWebsite()));
            Console.WriteLine(("License: " + fxfeed.getLicense()));
            Console.WriteLine(("Redistribution: " + fxfeed.getRedistribution()));
            Console.WriteLine(("AccessPeriod: " + fxfeed.getAccessPeriod()));
            Console.WriteLine(("AccessPerPeriod: " + fxfeed.getAccessPerPeriod()));
            Console.WriteLine(("AccessThisPeriod: " + fxfeed.getAccessThisPeriod()));
            Console.WriteLine(("AccessRemainingThisPeriod: " + fxfeed.getAccessPeriodRemaining()));
            Console.WriteLine(("AccessPeriodBegan: " + fxfeed.getAccessPeriodBegan()));
            Console.WriteLine(("NextAccessPeriodStarts: " + fxfeed.getAccessPeriodStarts()));

            //
            //   Get an Iterator object for the quotes ArrayList using iterator() method.
            //
            IEnumerator itr = quotes.GetEnumerator();

            //
            //   Iterate through the ArrayList iterator
            //
            Console.WriteLine("----------------------------------------");
            Console.WriteLine("Iterating through Quotes...");
            Console.WriteLine("----------------------------------------");
            while (itr.MoveNext())
            {
                Hashtable quote = ((Hashtable)(itr.Current));
                Console.WriteLine(("Quote Symbol: " + quote["symbol"]));
                Console.WriteLine(("Title: " + quote["title"]));
                Console.WriteLine(("Time: " + quote["time"]));

                if ((fxfeed.getInterval() == 1))
                {
                    if (fxfeed.getPrice().Equals("bid,ask"))
                    {
                        Console.WriteLine(("Bid: " + quote["bid"]));
                        Console.WriteLine(("Ask: " + quote["ask"]));
                    }
                    else
                    {
                        Console.WriteLine(("Price: " + quote["price"]));
                    }
                }
                else
                {
                    Console.WriteLine(("Open: " + quote["open"]));
                    Console.WriteLine(("High: " + quote["high"]));
                    Console.WriteLine(("Low: " + quote["low"]));
                    Console.WriteLine(("Close: " + quote["close"]));
                }
                Console.WriteLine("");
            }
        }
        else
        {
            Console.WriteLine(("Status: " + fxfeed.getStatus()));
            Console.WriteLine(("ErrorCode: " + fxfeed.getErrorCode()));
            Console.WriteLine(("ErrorMessage: " + fxfeed.getErrorMessage()));
        }
    }
Exemplo n.º 4
0
    // ''  
    // ''  Get the data and print it to System.Console
    // ''   
    private static void printData(feedapi fxfeed) {
        //     
        //   Fetch the Data
        //      
        ArrayList quotes = fxfeed.getData();
        Console.WriteLine("-------- Quotes --------");
        if (fxfeed.getStatus().Equals("OK")) {
            Console.WriteLine(("Number of Quotes: " + fxfeed.getNumQuotes()));
            Console.WriteLine(("Copyright: " + fxfeed.getCopyright()));
            Console.WriteLine(("Website: " + fxfeed.getWebsite()));
            Console.WriteLine(("License: " + fxfeed.getLicense()));
            Console.WriteLine(("Redistribution: " + fxfeed.getRedistribution()));
            Console.WriteLine(("AccessPeriod: " + fxfeed.getAccessPeriod()));
            Console.WriteLine(("AccessPerPeriod: " + fxfeed.getAccessPerPeriod()));
            Console.WriteLine(("AccessThisPeriod: " + fxfeed.getAccessThisPeriod()));
            Console.WriteLine(("AccessRemainingThisPeriod: " + fxfeed.getAccessPeriodRemaining()));
            Console.WriteLine(("AccessPeriodBegan: " + fxfeed.getAccessPeriodBegan()));
            Console.WriteLine(("NextAccessPeriodStarts: " + fxfeed.getAccessPeriodStarts()));

            //       
            //   Get an Iterator object for the quotes ArrayList using iterator() method.
            //        
            IEnumerator itr = quotes.GetEnumerator();

            //       
            //   Iterate through the ArrayList iterator
            //        
            Console.WriteLine("----------------------------------------");
            Console.WriteLine("Iterating through Quotes...");
            Console.WriteLine("----------------------------------------");
            while (itr.MoveNext()){
                Hashtable quote = ((Hashtable)(itr.Current));
                Console.WriteLine(("Quote Symbol: " + quote["symbol"]));
                Console.WriteLine(("Title: " + quote["title"]));
                Console.WriteLine(("Time: " + quote["time"]));

                if ((fxfeed.getInterval() == 1)) {
                    if (fxfeed.getPrice().Equals("bid,ask")) {
                        Console.WriteLine(("Bid: " + quote["bid"]));
                        Console.WriteLine(("Ask: " + quote["ask"]));
                    }
                    else {
                        Console.WriteLine(("Price: " + quote["price"]));
                    }
                }
                else {
                    Console.WriteLine(("Open: " + quote["open"]));
                    Console.WriteLine(("High: " + quote["high"]));
                    Console.WriteLine(("Low: " + quote["low"]));
                    Console.WriteLine(("Close: " + quote["close"]));
                }
                Console.WriteLine("");
            }
        }
        else {
            Console.WriteLine(("Status: " + fxfeed.getStatus()));
            Console.WriteLine(("ErrorCode: " + fxfeed.getErrorCode()));
            Console.WriteLine(("ErrorMessage: " + fxfeed.getErrorMessage()));
        }
    }