Exemplo n.º 1
0
        public override bool GetTickersInfo()
        {
            if (Tickers.Count > 0)
            {
                return(true);
            }

            string address = "https://api.bitfinex.com/v1/symbols";

            byte[] bytes = null;
            try {
                bytes = GetDownloadBytes(address);
            }
            catch (Exception) {
                return(false);
            }
            if (bytes == null)
            {
                return(false);
            }

            string text = UTF8Encoding.Default.GetString(bytes);

            text = text.Replace('[', ' ');
            text = text.Replace(']', ' ');
            text = text.Replace('"', ' ');

            string[] tickers = text.Split(',');
            foreach (string item in tickers)
            {
                BitFinexTicker m            = new BitFinexTicker(this);
                string         currencyPair = item.Trim();

                m.MarketCurrency = currencyPair.Substring(0, 3).ToUpper();
                m.BaseCurrency   = currencyPair.Substring(3, 3).ToUpper();
                m.CurrencyPair   = "t" + currencyPair.ToUpper();
                m.MarketName     = m.CurrencyPair;
                m.Index          = Tickers.Count;
                Tickers.Add(m);
            }
            address = "https://api.bitfinex.com/v2/tickers?symbols=";
            foreach (BitFinexTicker ticker in Tickers)
            {
                address += ticker.CurrencyPair;
                if (Tickers.IndexOf(ticker) < Tickers.Count - 1)
                {
                    address += ",";
                }
            }
            TickersUpdateAddress = address;

            IsInitialized = true;
            return(true);
        }
Exemplo n.º 2
0
        public async void NextTikker()
        {
            string oldTick = Forward.StockName;

            Back    = Current;
            Current = Forward;
            Forward = null;

            await Task.Run(() =>
            {
                YahooApiInterface F = new YahooApiInterface();
                List <Stock> G      = new List <Stock>();

                int i = Tickers.IndexOf(oldTick) + 1;
                if (i == Tickers.Count)
                {
                    i = 0;
                }

                G = F.getYahooData(new List <string>()
                {
                    Tickers[i]
                }, new DateTime(2013, 01, 01));

                while (G[0].WeeklyHist == null || G[0].HourlyHist == null || G[0].DailyHist == null || G[0].MonthlyHist == null)
                {
                    i = Tickers.IndexOf(G[0].StockName);
                    Tickers.Remove(G[0].StockName);
                    if (i == Tickers.Count)
                    {
                        i = 0;
                    }
                    G = new List <Stock>();
                    G.AddRange(F.getYahooData(new List <string>()
                    {
                        Tickers[i]
                    }, new DateTime(2013, 01, 01)));
                }
                Forward = G[0];
            });
        }