示例#1
0
 public Logic()
 {
     currencies = new CryptoDelivery_Currencies.Currencies();
 }
示例#2
0
        public string ReturnCurrencyRankToAnother(System.Net.WebClient client, Options.Currency ToCurrency,
            Currencies.ExchangeType exchangeType)
        {
            try
            {
                switch (exchangeType)
                {
                    case Currencies.ExchangeType.Kraken:
                        {
                            if (ToCurrency == Options.Currency.CNY)
                                return client.DownloadString(USDtoCNY);
                            else if (ToCurrency == Options.Currency.PLN)
                                return client.DownloadString(USDtoPLN);
                            else if (ToCurrency == Options.Currency.GBP)
                                return client.DownloadString(USDtoGBP);

                            break;
                        }
                    case Currencies.ExchangeType.Btce:
                        {
                            if (ToCurrency == Options.Currency.CNY)
                                return client.DownloadString(USDtoCNY);
                            else if (ToCurrency == Options.Currency.PLN)
                                return client.DownloadString(USDtoPLN);
                            else if (ToCurrency == Options.Currency.GBP)
                                return client.DownloadString(USDtoGBP);

                            break;
                        }

                    case Currencies.ExchangeType.Bitstamp:
                        {
                            if (ToCurrency == Options.Currency.CNY)
                                return client.DownloadString(USDtoCNY);
                            else if (ToCurrency == Options.Currency.EUR)
                                return client.DownloadString(USDtoEUR);
                            else if (ToCurrency == Options.Currency.PLN)
                                return client.DownloadString(USDtoPLN);
                            else if (ToCurrency == Options.Currency.GBP)
                                return client.DownloadString(USDtoGBP);
                            break;
                        }
                    case Currencies.ExchangeType.Bitcurex:
                        {
                            if (ToCurrency == Options.Currency.USD)
                                return client.DownloadString(EURtoUSD);
                            else if (ToCurrency == Options.Currency.CNY)
                                return client.DownloadString(EURtoCNY);
                            else if (ToCurrency == Options.Currency.GBP)
                                return client.DownloadString(EURtoGBP);
                            break;
                        }
                    case Currencies.ExchangeType.BtcChina:
                        {
                            if (ToCurrency == Options.Currency.USD)
                                return client.DownloadString(CNYtoUSD);
                            else if(ToCurrency== Options.Currency.EUR)
                                return client.DownloadString(CNYtoEUR);
                            else if(ToCurrency== Options.Currency.GBP)
                                return client.DownloadString(CNYtoGBP);
                            else if (ToCurrency == Options.Currency.PLN)
                                return client.DownloadString(CNYtoPLN);
                            break;

                        }
                    default:
                        break;
                }
            }
            catch (Exception e)
            {
                try
                {
                    //alternative to realtime values
                    return GetValueFromEuropeanCentralBank(ToCurrency, exchangeType);
                }
                catch (Exception error)
                {
                    Log.Error(error);
                }
                Log.Error(e);
            }
            return null;
        }
示例#3
0
 public string PrepareJsonResponseForRecalculation(IList<Cube> currenciesList, Currencies.ExchangeType exchangeType, 
     Options.Currency currency)
 {
     var curr = currency.ToString();
     Cube destCurr = currenciesList.First(x => (x.currency == curr));
     var from = "";
     string result = "";
     double generalRate;
     if (exchangeType == Currencies.ExchangeType.Bitcurex)
     {
         from = "EUR";
         generalRate = Convert.ToDouble(destCurr.rate.Replace('.', ','));
     }
     else if (exchangeType == Currencies.ExchangeType.BtcChina)
     {
         from = "CNY";
         //przelicz waluty
         Cube cny = currenciesList.First(x => (x.currency == "CNY"));
         double cnyRate = Convert.ToDouble(cny.rate.Replace('.', ','));
         double destCurrRate = Convert.ToDouble(destCurr.rate.Replace('.', ','));
         generalRate = destCurrRate / cnyRate;
     }
     else
     {
         from = "USD";
         //przelicz waluty
         Cube usd = currenciesList.First(x => (x.currency == "USD"));
         double usdRate = Convert.ToDouble(usd.rate.Replace('.', ','));
         double destCurrRate = Convert.ToDouble(destCurr.rate.Replace('.', ','));
         generalRate = destCurrRate / usdRate;
     }
     _rateList = currenciesList;
     _lastUpdateTime = DateTime.Now;
     //prepare response
     JsonObjectECB ecb = new JsonObjectECB();
     ecb.from = from;
     ecb.rate = generalRate;
     ecb.to = destCurr.currency;
     result = JsonConvert.SerializeObject(ecb);
     return result;
 }
示例#4
0
        public string GetResponseInSpecificCurrency(System.Net.WebClient client, Options.Currency currency,
    Currencies.ExchangeType exchangeType, Currencies.CoinType coinType)
        {
            try
            {
                if (coinType == Currencies.CoinType.Bitcoin)
                {
                    switch (exchangeType)
                    {
                        case Currencies.ExchangeType.LilionTransfer:
                            {
                                switch (currency)
                                {
                                    case Options.Currency.CNY:
                                        return client.DownloadString(lilionTransferUSD); // needs recalculation
                                    case Options.Currency.GBP:
                                        return client.DownloadString(lilionTransferGBP);
                                    case Options.Currency.PLN:
                                        return client.DownloadString(lilionTransferPLN);
                                    case Options.Currency.USD:
                                        return client.DownloadString(lilionTransferUSD);
                                    case Options.Currency.EUR:
                                        return client.DownloadString(lilionTransferEUR);
                                }
                                break;
                            }

                        case Currencies.ExchangeType.MTGOX:
                            {
                                switch (currency)
                                {
                                    case Options.Currency.CNY:
                                        return client.DownloadString(mtgoxBTCCNY);
                                    case Options.Currency.GBP:
                                        return client.DownloadString(mtgoxBTCGBP);
                                    case Options.Currency.PLN:
                                        return client.DownloadString(mtgoxBTCPLN);
                                    case Options.Currency.USD:
                                        return client.DownloadString(mtgoxBTCUSD);
                                    case Options.Currency.EUR:
                                        return client.DownloadString(mtgoxBTCEUR);

                                }
                                break;
                            }

                        case Currencies.ExchangeType.Bitcurex:
                            {
                                switch (currency)
                                {
                                    case Options.Currency.PLN:
                                        return client.DownloadString(bitcurexPLN);
                                    case Options.Currency.EUR:
                                        return client.DownloadString(bitcurexEUR);
                                    default:
                                        return client.DownloadString(bitcurexEUR);
                                }
                            }
                        case Currencies.ExchangeType.Kraken:
                            {
                                switch (currency)
                                {
                                    case Options.Currency.EUR:
                                        return client.DownloadString(krakenBTCEUR);
                                    case Options.Currency.USD:
                                        return client.DownloadString(krakenBTCUSD);
                                    default:
                                        return client.DownloadString(krakenBTCUSD);
                                }
                            }

                        case Currencies.ExchangeType.Btce:
                            {
                                switch (currency)
                                {
                                    case Options.Currency.USD:
                                        return client.DownloadString(btceBTCUSD);
                                    case Options.Currency.EUR:
                                        return client.DownloadString(btceBTCEUR);
                                    default:
                                        return client.DownloadString(btceBTCUSD);
                                }
                            }
                        case Currencies.ExchangeType.Bitstamp:
                        default:
                            return client.DownloadString(bitstampUSD);
                    }
                }
                #region litecoin
                if (coinType == Currencies.CoinType.Litecoin)
                {
                    switch (exchangeType)
                    {
                        case Currencies.ExchangeType.Kraken:
                            {
                                switch (currency)
                                {
                                    case Options.Currency.EUR:
                                        return client.DownloadString(krakenLTCEUR);
                                    case Options.Currency.USD:
                                        return client.DownloadString(krakenLTCUSD);
                                    default:
                                        return client.DownloadString(krakenLTCUSD);
                                }
                            }
                        case Currencies.ExchangeType.Btce:
                            {
                                switch (currency)
                                {
                                    case Options.Currency.EUR:
                                        return client.DownloadString(btceLTCEUR);
                                    case Options.Currency.USD:
                                        return client.DownloadString(btceLTCUSD);
                                    default:
                                        return client.DownloadString(btceLTCUSD);
                                }
                            }
                        default:
                            break;
                    }
                }
            #endregion
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
            return null;
        }
示例#5
0
 //Alternative method
 public string GetValueFromEuropeanCentralBank(Options.Currency currency,
     Currencies.ExchangeType exchangeType)
 {
     if (_rateList.Count == 0 || _lastUpdateTime.AddHours(6) < DateTime.Now)
     {
         var oEuropeanCentralBank = new XmlEuropeanCentralBank();
         oEuropeanCentralBank.DeserializeXml();
         return PrepareJsonResponseForRecalculation(oEuropeanCentralBank.curreniesList, exchangeType, currency);
     }
     return PrepareJsonResponseForRecalculation(_rateList, exchangeType, currency);
 }
示例#6
0
        public void UpdateValue(Currencies.CoinType coinType, Currencies.ExchangeType exchange,
            CryptoDelivery_Logic.Logic background, CryptoDelivery_Logic.Logic backgroundOld, Label labelTo, Label labelFrom, Label labelLast)
        {
            Currencies.Currency currency = background.currencies.GetCurrencyValue(coinType, exchange);
            Currencies.Currency currencyOld = backgroundOld.currencies.GetCurrencyValue(coinType, exchange);

            var value_from = Double.Parse(currency.value_from);
            var value_to = Double.Parse(currency.value_to);
            var value_from_old = double.Parse(currencyOld.value_from);
            var value_to_old = double.Parse(currencyOld.value_to);

            if (value_from > value_from_old)
                labelFrom.ForeColor = Color.LimeGreen;
            else if (value_from < value_from_old)
                labelFrom.ForeColor = Color.Red;

            if (value_to > value_to_old)
                labelTo.ForeColor = Color.LimeGreen;
            else if (value_to < value_to_old)
                labelTo.ForeColor = Color.Red;

            if (currency.value_from.Equals("-1"))
            {
                labelFrom.Text = "N/A";
                labelFrom.ForeColor = Color.Black;
            }
            else
            {
                labelFrom.Text = currency.value_from;
            }

            if (currency.value_to.Equals("-1"))
            {
                labelTo.Text = "N/A";
                labelTo.ForeColor = Color.Black;
            }
            else
            {
                labelTo.Text = currency.value_to;
            }

            if (labelLast != null)
            {
                var value_last = double.Parse(currency.value_last);
                var value_last_old = double.Parse(currencyOld.value_last);
                if (value_last > value_last_old)
                    labelLast.ForeColor = Color.LimeGreen;
                else if (value_last < value_last_old)
                    labelLast.ForeColor = Color.Red;

                if (currency.value_last.Equals("-1"))
                {
                    labelLast.Text = "N/A";
                    labelLast.ForeColor = Color.Black;
                }
                else
                {
                    labelLast.Text = currency.value_last;
                }
            }
        }