Example #1
0
        private void Yahoo(IAsyncResult Result)
        {
            try
            {
                HttpWebRequest myHttpWebRequest = (HttpWebRequest)Result.AsyncState;
                HttpWebResponse response = (HttpWebResponse)myHttpWebRequest.EndGetResponse(Result);

                string sEmitResponse = new StreamReader(response.GetResponseStream()).ReadToEnd();
                sEmitResponse = sEmitResponse.Replace("N/A", "0");
                //dumperror("yahoo" + sEmitResponse);
                List<YahooPairRaw> tmp = json.JsonDeserialize<YahooRequest>(sEmitResponse).query.results.rate;
                //Fiat = JsonDeserialize<YahooRequest>(sEmitResponse).query.results.rate;
                foreach (YahooPairRaw t in tmp)
                {
                    bool found = false;
                    if (t.id.ToLower().Contains("zar"))
                    {

                    }
                    for (int i = 0; i < Fiat.Count; i++)
                    {
                        if (t.id == Fiat[i].id)
                        {
                            double ask = 0;
                            double bid = 0;
                            double.TryParse(t.Ask, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out ask);
                            double.TryParse(t.Bid, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out bid);

                            Fiat[i] = new YahooPair() { Ask=ask, Bid=bid, id=t.id,Rate=t.Rate };
                            found = true;

                            break;
                        }

                    }
                    if (!found)
                    {

                        double ask = 0;
                        double bid = 0;
                        double.TryParse(t.Ask, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out ask);
                        double.TryParse(t.Bid, System.Globalization.NumberStyles.Any,System.Globalization.NumberFormatInfo.InvariantInfo, out bid);
                        Fiat.Add(new YahooPair() { Ask =ask, Bid = bid, id = t.id, Rate = t.Rate });
                    }
                }
            }
            catch (WebException e)
            {

            }
            catch (Exception e)
            {

            }
            yahooDone = true;
            TriggerEvent();
        }
Example #2
0
        public YahooPair GetFullDetails(string From, string To, double iamount)
        {
            YahooPair tmpPair = new YahooPair();

            YahooPair from = getCurrencyFullValue(From);
            YahooPair to = getCurrencyFullValue(To);
            if (from!=null&&to!=null)
            {
                tmpPair.Rate = (from.Rate / to.Rate)*iamount;
                tmpPair.Bid = (from.Bid / to.Bid)*iamount;
                tmpPair.Ask = (from.Ask / to.Ask)*iamount;
                tmpPair.id = (From + "-" + To);
            }
            return tmpPair;
        }