Beispiel #1
0
 public OptionsWindow()
 {
     InitializeComponent();
     if(_options==null)
         _options = new CryptoDelivery_Data.Options();
     SetOptions();
 }
Beispiel #2
0
 public CryptoDelivery(Auth.ServerPackage package)
 {
     _authPackage = package;
     InitializeComponent();
     _background = new Logic();
     _oldbackground = new Logic();
     _options = new Options();
     toolStripStatusInfo.Text = "Ready";
     notifyIcon.Visible = true;
     Worker1.WorkerSupportsCancellation = true;
     LoadOptions();
     UpdateToolStripStatusCurrency();
     btn_GetValues_Click(new object(),new EventArgs());
     InitTimerValidation();
 }
Beispiel #3
0
 public void LoadOptions()
 {
     try
     {
         string path = AppDomain.CurrentDomain.BaseDirectory;
         System.Xml.Serialization.XmlSerializer reader =
             new System.Xml.Serialization.XmlSerializer(typeof (Options));
         System.IO.StreamReader file = new System.IO.StreamReader(path + "\\options.xml");
         Options op = new Options();
         op = (Options) reader.Deserialize(file);
         _options = op;
     }
     catch (FileNotFoundException e)
     {
         SaveOptions();
     }
     catch (Exception e)
     {
         Log.Error(e);
     }
 }
Beispiel #4
0
 public OptionsWindow(CryptoDelivery_Data.Options op)
 {
     InitializeComponent();
     _options = op;
     SetOptions();
 }
Beispiel #5
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;
        }
Beispiel #6
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;
 }
Beispiel #7
0
        public void GetValuesFromMtGox(Options.Currency curr)
        {
            string json;
            try
            {
                var webClient = new System.Net.WebClient();
                json = GetResponseInSpecificCurrency(webClient, curr, Currencies.ExchangeType.MTGOX, Currencies.CoinType.Bitcoin);
                if (String.IsNullOrEmpty(json))
                    throw new ExchangeException("Response from Mtgox was not received.");
                Currencies.Currency currencyValue = currencies.GetCurrencyValue(Currencies.CoinType.Bitcoin,
                    Currencies.ExchangeType.MTGOX);

                JsonMtGOX.RootObject mtgoxData = JsonConvert.DeserializeObject<JsonMtGOX.RootObject>(json);

                string bidstring = [email protected]('.', ',').Remove(8);
                string askstring = [email protected]('.', ',').Remove(8);
                string laststring = [email protected]('.', ',').Remove(8);
                double bid = Double.Parse(bidstring);
                double ask = Double.Parse(askstring);
                double last = Double.Parse(laststring);
                currencyValue.value_to = bid.ToString(DisplayFormat);
                currencyValue.value_from = ask.ToString(DisplayFormat);
                currencyValue.value_last = last.ToString(DisplayFormat);
                currencies.SetCurrencyValue(Currencies.CoinType.Bitcoin, Currencies.ExchangeType.MTGOX, currencyValue);
            }
            catch (Exception e)
            {
                if(e is ExchangeException)
                    Log.ExchangeFails(e,false);
                else
                    Log.Error(e);
                currencies.SetCurrencyValue(Currencies.CoinType.Bitcoin, Currencies.ExchangeType.MTGOX,
                    new Currencies.Currency());
                return;
            }
        }
Beispiel #8
0
        public void ComputeDifferencesBTC(Options options, decimal diff = 100)
        {
            IDictionary<string, double> arraySell = new Dictionary<string, double>();
            IDictionary<string, double> arrayBuy = new Dictionary<string, double>();
            String returnedString = "";
            _listOfArbitragesBTC = new List<PercentOfArbitrage>();

            foreach (Currencies.ExchangeType exchangeType in (Currencies.ExchangeType[])Enum.GetValues(typeof(Currencies.ExchangeType)))
            {
                Currencies.Currency currency = currencies.GetCurrencyValue(Currencies.CoinType.Bitcoin, exchangeType);
                double value_to_numeric = double.Parse(currency.value_to);
                double value_from_numeric = double.Parse(currency.value_from);
                String name = exchangeType.ToString();
                if (value_to_numeric > 0.0)
                {
                    if (name.Equals("BtcChina"))
                        name = "Btccn";
                    if (name.Equals("LilionTransfer"))
                    {
                        name = "Lilion";
                        arrayBuy.Add(name, value_to_numeric);
                        continue;
                    }
                    arraySell.Add(name, value_to_numeric);

                }
                if (value_from_numeric > 0.0)
                {
                    if (name.Equals("BtcChina"))
                        name = "Btccn";
                    if (name.Equals("LilionTransfer"))
                    {
                        name = "Lilion";
                        arraySell.Add(name, value_from_numeric);
                        continue;
                    }
                    arrayBuy.Add(name, value_from_numeric);
                }
            }

            foreach (var buyElem in arrayBuy)
            {
                foreach (var sellElem in arraySell)
                {
                    if (buyElem.Key == sellElem.Key)
                        continue;
                    if ((buyElem.Value - sellElem.Value) / sellElem.Value * 100 > (double)diff)
                    {
                        double percent = Math.Abs(Math.Round(buyElem.Value * 100 / sellElem.Value - 100, 0));
                        //if (returnedString == "")
                        //    returnedString = "\nBTC:\n";
                        //if (buyElem.Key == "Kraken" || buyElem.Key == "Btce" || buyElem.Key == "Lilion")
                        //    returnedString += String.Format("{1}\t- {3}\t -> {0}        \t- {2}\t= {4}%\n", buyElem.Key,
                        //    sellElem.Key, Math.Round(buyElem.Value, 0), Math.Round(sellElem.Value, 0), percent);
                        //else
                        //    returnedString += String.Format("{1}\t- {3}\t -> {0}\t- {2}\t= {4}%\n", buyElem.Key,
                        //    sellElem.Key, Math.Round(buyElem.Value, 0), Math.Round(sellElem.Value, 0), percent);
                        PercentOfArbitrage poa = new PercentOfArbitrage();
                        poa.from = buyElem.Key;
                        poa.fromValue = buyElem.Value;
                        poa.to = sellElem.Key;
                        poa.toValue = sellElem.Value;
                        poa.percentage = percent;
                        if (_listOfArbitragesBTC.Contains(poa) == false)
                        {
                            _listOfArbitragesBTC.Add(poa);
                        }

                    }
                    if ((sellElem.Value - buyElem.Value) / buyElem.Value < (double)options.alertWhenLessThan && sellElem.Key.Equals("MTGOX") && buyElem.Key.Equals("Bitcurex"))
                    {
                        currencies.AlertEqual_mtgoxAndBitcurex = true;
                    }
                    else if (sellElem.Key.Equals("MTGOX") && buyElem.Key.Equals("Bitcurex"))
                    {
                        currencies.AlertEqual_mtgoxAndBitcurex = false;
                    }
                }
            }
            IEnumerable<PercentOfArbitrage> orderPercentOfArbitrages =_listOfArbitragesBTC.OrderByDescending(x => x.percentage);
            foreach (var item in orderPercentOfArbitrages)
            {
                if (returnedString == "")
                    returnedString = "\nBTC:\n";
                if (item.from == "Kraken" || item.from == "Btce" || item.from == "Lilion" || item.from == "Btccn")
                    returnedString += String.Format("{1}\t- {3}\t -> {0}        \t- {2}\t= {4}%\n", item.from,
                    item.to, Math.Round(item.fromValue, 0), Math.Round(item.toValue, 0), item.percentage);
                else
                    returnedString += String.Format("{1}\t- {3}\t -> {0}\t- {2}\t= {4}%\n", item.from,
                    item.to, Math.Round(item.fromValue, 0), Math.Round(item.toValue, 0), item.percentage);
            }
            currencies.BtcArbitrageInfo = returnedString;
            if (_recentListOfArbitragesBTC.Count() == orderPercentOfArbitrages.Count())
                foreach (var element in _listOfArbitragesBTC)
                {
                    if (_recentListOfArbitragesBTC.Contains(element) == true)
                    {
                        showBaloon = false;
                        continue;
                    }
                    else
                    {
                        showBaloon = true;
                        break;
                    }
                }
            _recentListOfArbitragesBTC = orderPercentOfArbitrages;
        }
Beispiel #9
0
        public void GetValuesFromBtce(Options.Currency curr)
        {
            #region Bitcoin

            string json = null;
            try
            {
                var webClient = new System.Net.WebClient();
                json = GetResponseInSpecificCurrency(webClient, curr, Currencies.ExchangeType.Btce,
                    Currencies.CoinType.Bitcoin);
                if (String.IsNullOrEmpty(json))
                    throw new ExchangeException("Response from BTCE was not received.");
                JsonBtce.RootObject btceData = JsonConvert.DeserializeObject<JsonBtce.RootObject>(json);

                Currencies.Currency currencyValue = currencies.GetCurrencyValue(Currencies.CoinType.Bitcoin,
                    Currencies.ExchangeType.Btce);

                if (curr == Options.Currency.USD || curr == Options.Currency.EUR)
                {
                    currencyValue.value_from = btceData.ticker.buy.ToString(DisplayFormat);
                    currencyValue.value_to = btceData.ticker.sell.ToString(DisplayFormat);
                    currencyValue.value_last = btceData.ticker.last.ToString(DisplayFormat);
                }
                else
                {
                    //reacalculate value
                    var webClientExchangeRate = new System.Net.WebClient();
                    var currencyJson = ReturnCurrencyRankToAnother(webClientExchangeRate, curr, Currencies.ExchangeType.Btce);
                    var rate = JsonConvert.DeserializeObject<CurrencyExchangeRate>(currencyJson);
                    double bid = btceData.ticker.buy * rate.rate;
                    double ask = btceData.ticker.sell * rate.rate;
                    double last = btceData.ticker.last * rate.rate;

                    currencyValue.value_from = bid.ToString(DisplayFormat);
                    currencyValue.value_to = ask.ToString(DisplayFormat);
                    currencyValue.value_last = last.ToString(DisplayFormat);
                }

                currencies.SetCurrencyValue(Currencies.CoinType.Bitcoin, Currencies.ExchangeType.Btce, currencyValue);
            }
            catch (Exception e)
            {
                if (e is ExchangeException)
                    Log.ExchangeFails(e, false);
                else
                    Log.Error(e);
                currencies.SetCurrencyValue(Currencies.CoinType.Bitcoin, Currencies.ExchangeType.Btce,
                    new Currencies.Currency());
                return;
            }

            #endregion

            #region Litecoin

            json = null;
            try
            {
                var webClient = new System.Net.WebClient();
                json = GetResponseInSpecificCurrency(webClient, curr, Currencies.ExchangeType.Btce,
                    Currencies.CoinType.Litecoin);
                if (String.IsNullOrEmpty(json))
                    throw new ExchangeException("Response from BTCE was not received.");
                JsonBtce.RootObject btceData = JsonConvert.DeserializeObject<JsonBtce.RootObject>(json);

                Currencies.Currency currencyValue = currencies.GetCurrencyValue(Currencies.CoinType.Litecoin,
                    Currencies.ExchangeType.Btce);

                if (curr == Options.Currency.USD || curr == Options.Currency.EUR)
                {
                    currencyValue.value_from = btceData.ticker.buy.ToString(DisplayFormat);
                    currencyValue.value_to = btceData.ticker.sell.ToString(DisplayFormat);
                    currencyValue.value_last = btceData.ticker.last.ToString(DisplayFormat);
                }
                else
                {
                    //reacalculate value
                    var webClientExchangeRate = new System.Net.WebClient();
                    var currencyJson = ReturnCurrencyRankToAnother(webClientExchangeRate, curr,
                        Currencies.ExchangeType.Btce);
                    var rate = JsonConvert.DeserializeObject<CurrencyExchangeRate>(currencyJson);
                    double bid = btceData.ticker.buy * rate.rate;
                    double ask = btceData.ticker.sell * rate.rate;
                    double last = btceData.ticker.last * rate.rate;

                    currencyValue.value_from = ask.ToString(DisplayFormat);
                    currencyValue.value_to = bid.ToString(DisplayFormat);
                    currencyValue.value_last = last.ToString(DisplayFormat);
                }

                currencies.SetCurrencyValue(Currencies.CoinType.Litecoin, Currencies.ExchangeType.Btce, currencyValue);
            }
            catch (Exception e)
            {
                if(e is ExchangeException)
                    Log.ExchangeFails(e,false);
                else
                {
                    Log.Error(e);
                }

                currencies.SetCurrencyValue(Currencies.CoinType.Litecoin, Currencies.ExchangeType.Btce,
                    new Currencies.Currency());
                return;
            }

            #endregion
        }
Beispiel #10
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;
        }
Beispiel #11
0
        public void GetValuesFromBtcChina(Options.Currency curr)
        {
            //CurrencyExchangeRate rate;
            #region Bitcoin
            string json;
            try
            {
                double from, to, last = 0;
                var webClient = new System.Net.WebClient();
                Currencies.Currency currencyValue = currencies.GetCurrencyValue(Currencies.CoinType.Bitcoin, Currencies.ExchangeType.BtcChina);
                json = webClient.DownloadString(btcnBTCCNY);
                if (String.IsNullOrEmpty(json))
                    throw new ExchangeException("Response in specific currency was not received.");
                JsonBtchina.RootObject btcchinaData = JsonConvert.DeserializeObject<JsonBtchina.RootObject>(json);

                btcchinaData.ticker.buy = btcchinaData.ticker.buy.Replace('.', ',');
                btcchinaData.ticker.sell = btcchinaData.ticker.sell.Replace('.', ',');
                btcchinaData.ticker.last = btcchinaData.ticker.last.Replace('.', ',');

                if (curr == CryptoDelivery_Data.Options.Currency.CNY)
                {
                    from = Double.Parse(btcchinaData.ticker.buy);
                    to = Double.Parse(btcchinaData.ticker.sell);
                    last = Double.Parse(btcchinaData.ticker.last);
                }
                else
                {
                    //reacalculate value
                    var webClientExchangeRate = new System.Net.WebClient();
                    var currencyJson = ReturnCurrencyRankToAnother(webClientExchangeRate, curr, Currencies.ExchangeType.BtcChina);
                    CurrencyExchangeRate rate = JsonConvert.DeserializeObject<CurrencyExchangeRate>(currencyJson);
                    from = Double.Parse(btcchinaData.ticker.buy) * rate.rate;
                    to = Double.Parse(btcchinaData.ticker.sell) * rate.rate;
                    last = Double.Parse(btcchinaData.ticker.last) * rate.rate;
                }
                currencyValue.value_from = from.ToString(DisplayFormat);
                currencyValue.value_to = to.ToString(DisplayFormat);
                currencyValue.value_last = last.ToString(DisplayFormat);

            }
            catch (Exception e)
            {
                if (e is ExchangeException)
                    Log.ExchangeFails(e, false);
                else
                    Log.Error(e);
                currencies.SetCurrencyValue(Currencies.CoinType.Bitcoin, Currencies.ExchangeType.BtcChina,
                    new Currencies.Currency());
                return;
            }
            #endregion

            #region Litecoin

            json = "";
            try
            {
                double from, to, last = 0;
                var webClient = new System.Net.WebClient();
                Currencies.Currency currencyValue = currencies.GetCurrencyValue(Currencies.CoinType.Litecoin, Currencies.ExchangeType.BtcChina);
                json = webClient.DownloadString(btcnLTCCNY);
                if (String.IsNullOrEmpty(json))
                    throw new ExchangeException("Response in specific currency was not received.");
                JsonBtchina.RootObject btcchinaData = JsonConvert.DeserializeObject<JsonBtchina.RootObject>(json);

                btcchinaData.ticker.buy = btcchinaData.ticker.buy.Replace('.', ',');
                btcchinaData.ticker.sell = btcchinaData.ticker.sell.Replace('.', ',');
                btcchinaData.ticker.last = btcchinaData.ticker.last.Replace('.', ',');

                if (curr == CryptoDelivery_Data.Options.Currency.CNY)
                {
                    from = Double.Parse(btcchinaData.ticker.buy);
                    to = Double.Parse(btcchinaData.ticker.sell);
                    last = Double.Parse(btcchinaData.ticker.last);
                }
                else
                {
                    ////reacalculate value
                    var webClientExchangeRate = new System.Net.WebClient();
                    var currencyJson = ReturnCurrencyRankToAnother(webClientExchangeRate, curr, Currencies.ExchangeType.BtcChina);
                    CurrencyExchangeRate rate = JsonConvert.DeserializeObject<CurrencyExchangeRate>(currencyJson);
                    from = Double.Parse(btcchinaData.ticker.buy) * rate.rate;
                    to = Double.Parse(btcchinaData.ticker.sell) * rate.rate;
                    last = Double.Parse(btcchinaData.ticker.last) * rate.rate;
                }
                currencyValue.value_from = from.ToString(DisplayFormat);
                currencyValue.value_to = to.ToString(DisplayFormat);
                currencyValue.value_last = last.ToString(DisplayFormat);

            }
            catch (Exception e)
            {
                if (e is ExchangeException)
                    Log.ExchangeFails(e, false);
                else
                    Log.Error(e);
                currencies.SetCurrencyValue(Currencies.CoinType.Litecoin, Currencies.ExchangeType.BtcChina,
                    new Currencies.Currency());
                return;
            }
            #endregion
        }
Beispiel #12
0
        public void GetValuesFromBitstamp(Options.Currency curr)
        {
            string json = null;
            try
            {
                var webClient = new System.Net.WebClient();
                json = webClient.DownloadString(bitstampUSD);
                if (String.IsNullOrEmpty(json))
                    throw new Exception("Response from Bitstamp was not received.");
                JsonBitstamp.RootObject bitstampData = JsonConvert.DeserializeObject<JsonBitstamp.RootObject>(json);

                Currencies.Currency currencyValue = currencies.GetCurrencyValue(Currencies.CoinType.Bitcoin,
                    Currencies.ExchangeType.Bitstamp);

                double bid, ask, last;
                string bidstring, askstring, laststring;
                if (curr == Options.Currency.USD)
                {
                    bidstring = bitstampData.bid.Replace('.', ',');
                    askstring = bitstampData.ask.Replace('.', ',');
                    laststring = bitstampData.last.Replace('.', ',');
                    bid = Double.Parse(bidstring);
                    ask = Double.Parse(askstring);
                    last = Double.Parse(laststring);
                }
                else
                {
                    //reacalculate value
                    var webClientExchangeRate = new System.Net.WebClient();
                    var currencyJson = ReturnCurrencyRankToAnother(webClientExchangeRate, curr, Currencies.ExchangeType.Bitstamp);
                    CurrencyExchangeRate rate = JsonConvert.DeserializeObject<CurrencyExchangeRate>(currencyJson);
                    bidstring = bitstampData.bid.Replace('.', ',');
                    askstring = bitstampData.ask.Replace('.', ',');
                    laststring = bitstampData.last.Replace('.', ',');
                    bid = Double.Parse(bidstring) * rate.rate;
                    ask = Double.Parse(askstring) * rate.rate;
                    last = Double.Parse(laststring) * rate.rate;
                }

                currencyValue.value_from = bid.ToString(DisplayFormat);
                currencyValue.value_to = ask.ToString(DisplayFormat);
                currencyValue.value_last = last.ToString(DisplayFormat);
                currencies.SetCurrencyValue(Currencies.CoinType.Bitcoin, Currencies.ExchangeType.Bitstamp, currencyValue);
            }
            catch (Exception e)
            {
                if(e is ExchangeException)
                    Log.ExchangeFails(e,false);
                else
                    Log.Error(e);
                currencies.SetCurrencyValue(Currencies.CoinType.Bitcoin, Currencies.ExchangeType.Bitstamp,
                    new Currencies.Currency());
                return;
            }
        }
Beispiel #13
0
        public void GetValuesFromBitcurex(Options.Currency curr)
        {
            string json;
            try
            {

                var webClient = new System.Net.WebClient();
                Currencies.Currency currencyValue = currencies.GetCurrencyValue(Currencies.CoinType.Bitcoin, Currencies.ExchangeType.Bitcurex);
                if (curr == CryptoDelivery_Data.Options.Currency.PLN)
                {
                    json = webClient.DownloadString(bitcurexPLN);
                    if (String.IsNullOrEmpty(json))
                        throw new ExchangeException("Response in specific currency was not received.");
                    JsonBitcurex.RootObject bitcurexData = JsonConvert.DeserializeObject<JsonBitcurex.RootObject>(json);

                    currencyValue.value_from = bitcurexData.buy.ToString(DisplayFormat);
                    currencyValue.value_to = bitcurexData.sell.ToString(DisplayFormat);
                    currencyValue.value_last = bitcurexData.last.ToString(DisplayFormat);
                }
                else
                {

                    json = webClient.DownloadString(bitcurexEUR);
                    if (String.IsNullOrEmpty(json))
                        throw new ExchangeException("Response in specific currency was not received.");
                    JsonBitcurex.RootObject bitcurexData = JsonConvert.DeserializeObject<JsonBitcurex.RootObject>(json);
                    if (curr == Options.Currency.EUR)
                    {
                        currencyValue.value_from = (bitcurexData.buy).ToString(DisplayFormat);
                        currencyValue.value_to = (bitcurexData.sell).ToString(DisplayFormat);
                        currencyValue.value_last = (bitcurexData.last).ToString(DisplayFormat);
                    }
                    else
                    {
                        var webClientExchangeRate = new System.Net.WebClient();
                        string currencyJson = ReturnCurrencyRankToAnother(webClientExchangeRate, curr, Currencies.ExchangeType.Bitcurex);
                        CurrencyExchangeRate rate = JsonConvert.DeserializeObject<CurrencyExchangeRate>(currencyJson);
                        currencyValue.value_from = (bitcurexData.buy * rate.rate).ToString(DisplayFormat);
                        currencyValue.value_to = (bitcurexData.sell * rate.rate).ToString(DisplayFormat);
                        currencyValue.value_last = (bitcurexData.last * rate.rate).ToString(DisplayFormat);
                    }
                }
                currencies.SetCurrencyValue(Currencies.CoinType.Bitcoin, Currencies.ExchangeType.Bitcurex, currencyValue);
            }
            catch (Exception e)
            {
                if(e is ExchangeException)
                    Log.ExchangeFails(e,false);
                else
                    Log.Error(e);
                currencies.SetCurrencyValue(Currencies.CoinType.Bitcoin, Currencies.ExchangeType.Bitcurex,
                    new Currencies.Currency());
                return;
            }
        }
Beispiel #14
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);
 }
Beispiel #15
0
 public Options UpdateUser(Options options)
 {
     options.accountLocked = package.locked;
     return options;
 }
Beispiel #16
0
 public ServerPackage ValidateUser(Options options = null)
 {
     try
     {
         var uniqueId = getUniqueID();
         WebClient client = new WebClient();
         var Server = "http://cryptocurrencyworld.eu/crypto/webservice.php";
         var data = String.Format("cpuid={0}", uniqueId);
         var response = client.UploadString(Server, "POST", data);
         const string a = "45287112549354892144548565456541";
         const string b = "5AUjfdWTz9g57dbVGSVLBb2bZycT18Hi";
         var c = response;
         var temp = read(ParsBytes(c), b, a);
         var deseralizedResponse = JsonConvert.DeserializeObject<JsonResponse>(temp);
         ServerPackage sp = new ServerPackage();
         if (uniqueId != deseralizedResponse.cpuid)
         {
             throw new Exception("incorrect uniqueId in relation to id which was get from server.");
         }
         else
         {
             sp.cpuid = uniqueId;
         }
         sp.locked = Convert.ToBoolean(deseralizedResponse.locked);
         sp.date_added = Convert.ToDateTime(deseralizedResponse.date_added);
         sp.date_expired = Convert.ToDateTime(deseralizedResponse.date_expired);
         sp.date_current_on_server = Convert.ToDateTime(deseralizedResponse.date_current_on_server);
         sp.wallet = deseralizedResponse.wallet;
         TimeSpan ts = sp.date_expired - sp.date_current_on_server;
         if (ts.TotalDays < 0)
         {
             sp.validationResult = ValidationResult.expired;
             sp.locked = true;
         }
         else if (ts.TotalDays > 0 && sp.locked==false)
         {
             sp.validationResult = ValidationResult.actual;
             sp.locked = false;
         }
         return sp;
     }
     catch (Exception e)
     {
         bool timeout = e is WebException;
         Log.Error(e,timeout);
         if (timeout == true)
             return null;
     }
     return new ServerPackage();
 }
Beispiel #17
0
        public void GetValuesFromKraken(Options.Currency curr)
        {
            #region Bitcoin

            string json = null;
            try
            {
                var webClient = new System.Net.WebClient();
                Currencies.Currency currencyValue = currencies.GetCurrencyValue(Currencies.CoinType.Bitcoin,
                    Currencies.ExchangeType.Kraken);
                json = GetResponseInSpecificCurrency(webClient, curr, Currencies.ExchangeType.Kraken,
                    Currencies.CoinType.Bitcoin);
                if (String.IsNullOrEmpty(json))
                    throw new ExchangeException("Response from Kraken was not received.");
                string bids = "", asks = "", lasts = "";
                if (curr != Options.Currency.EUR)
                {
                    JsonKrakenBTCUSD.RootObject krakenData = JsonConvert.DeserializeObject<JsonKrakenBTCUSD.RootObject>(json);
                    bids = krakenData.result.XXBTZUSD.b[0].Replace('.', ',');
                    asks = krakenData.result.XXBTZUSD.a[0].Replace('.', ',');
                    lasts = krakenData.result.XXBTZUSD.c[0].Replace('.', ',');
                }
                else
                {
                    JsonKrakenBTCEUR.RootObject krakenData = JsonConvert.DeserializeObject<JsonKrakenBTCEUR.RootObject>(json);
                    krakenData = JsonConvert.DeserializeObject<JsonKrakenBTCEUR.RootObject>(json);
                    bids = krakenData.result.XXBTZEUR.b[0].Replace('.', ',');
                    asks = krakenData.result.XXBTZEUR.a[0].Replace('.', ',');
                    lasts = krakenData.result.XXBTZEUR.c[0].Replace('.', ',');
                }

                double bid, ask, last;
                //add || EUR in other case there is need to send request about current rank from USD currency to other
                if (curr == Options.Currency.USD || curr == Options.Currency.EUR)
                {
                    bid = double.Parse(bids);
                    ask = double.Parse(asks);
                    last = double.Parse(lasts);
                }
                else
                {
                    //reacalculate value
                    var webClientExchangeRate = new System.Net.WebClient();
                    var currencyJson = ReturnCurrencyRankToAnother(webClientExchangeRate, curr, Currencies.ExchangeType.Kraken);

                    var rate = JsonConvert.DeserializeObject<CurrencyExchangeRate>(currencyJson);
                    bid = double.Parse(bids) * rate.rate;
                    ask = double.Parse(asks) * rate.rate;
                    last = double.Parse(lasts) * rate.rate;
                }

                currencyValue.value_from = bid.ToString(DisplayFormat);
                currencyValue.value_to = ask.ToString(DisplayFormat);
                currencyValue.value_last = last.ToString(DisplayFormat);
                currencies.SetCurrencyValue(Currencies.CoinType.Bitcoin, Currencies.ExchangeType.Kraken, currencyValue);
            }
            catch (Exception e)
            {
                if(e is ExchangeException)
                    Log.ExchangeFails(e,false);
                else
                    Log.Error(e);
                currencies.SetCurrencyValue(Currencies.CoinType.Bitcoin, Currencies.ExchangeType.Kraken,
                    new Currencies.Currency());
                return;
            }

            #endregion

            #region Litecoin

            json = null;
            try
            {
                var webClient = new System.Net.WebClient();
                json = GetResponseInSpecificCurrency(webClient, curr, Currencies.ExchangeType.Kraken,
                    Currencies.CoinType.Litecoin);
                if (String.IsNullOrEmpty(json))
                    throw new ExchangeException("Response from Kraken was not received.");
                JsonKrakenLTC.RootObject krakenData = JsonConvert.DeserializeObject<JsonKrakenLTC.RootObject>(json);
                Currencies.Currency currencyValue = currencies.GetCurrencyValue(Currencies.CoinType.Litecoin,
                    Currencies.ExchangeType.Kraken);

                string bidstring = krakenData.result.XLTCZUSD.b[0].Replace('.', ',');
                string askstring = krakenData.result.XLTCZUSD.a[0].Replace('.', ',');
                string laststring = krakenData.result.XLTCZUSD.c[0].Replace('.', ',');
                double bid, ask, last;
                if (curr == Options.Currency.USD || curr == Options.Currency.EUR)
                {
                    bid = double.Parse(bidstring);
                    ask = double.Parse(askstring);
                    last = double.Parse(laststring);
                }
                else
                {
                    //reacalculate value
                    var webClientExchangeRate = new System.Net.WebClient();
                    var currencyJson = ReturnCurrencyRankToAnother(webClientExchangeRate, curr, Currencies.ExchangeType.Kraken);
                    var rate = JsonConvert.DeserializeObject<CurrencyExchangeRate>(currencyJson);
                    bid = double.Parse(bidstring) * rate.rate;
                    ask = double.Parse(askstring) * rate.rate;
                    last = double.Parse(laststring) * rate.rate;
                }

                currencyValue.value_from = bid.ToString(DisplayFormat);
                currencyValue.value_to = ask.ToString(DisplayFormat);
                currencyValue.value_last = last.ToString(DisplayFormat);
                currencies.SetCurrencyValue(Currencies.CoinType.Litecoin, Currencies.ExchangeType.Kraken, currencyValue);
            }
            catch (Exception e)
            {
                if(e is ExchangeException)
                    Log.ExchangeFails(e,false);
                else
                    Log.Error(e);
                currencies.SetCurrencyValue(Currencies.CoinType.Litecoin, Currencies.ExchangeType.Kraken,
                    new Currencies.Currency());
                return;
            }

            #endregion
        }
Beispiel #18
0
        public void GetCurrentCurrencies(CryptoDelivery_Data.Options op)
        {
            try
            {
                DisplayFormat = op.ValueFormat;
                options = op;
                #region Getting values

                ThreadsFinisherCounter = 0;
                var lilionThread = new Thread(new ThreadStart(PerformLilionOnDifferentThread));
                var mtgoxThread = new Thread(new ThreadStart(PerformMtgoxOnDifferentThread));
                var bitcurexThread = new Thread(new ThreadStart(PerformBitcurexOnDifferentThread));
                var bitstampThread = new Thread(new ThreadStart(PerformBitstampOnDifferentThread));
                var krakenThread = new Thread(new ThreadStart(PerformKrakenOnDifferentThread));
                var btceThread = new Thread(new ThreadStart(PerformBtceOnDifferentThread));
                var btccThread = new Thread(new ThreadStart(PerformBtcnOnDifferentThread));
                btceThread.Start();
                bitstampThread.Start();
                krakenThread.Start();
                bitcurexThread.Start();
                mtgoxThread.Start();
                lilionThread.Start();
                btccThread.Start();

                while (ThreadsFinisherCounter<7)
                {}

                #endregion

                #region Arbitrage

                if (op.EnabledArbitrageBtc == true || op.alertsEnabled==true)
                {
                    ComputeDifferencesBTC(op,op.ArbitrageProfitBtc);
                }
                if (op.EnabledArbitrageLtc == true)
                {
                    ComputeDifferencesLTC(op.ArbitrageProfitLtc);
                }

                #endregion
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Beispiel #19
0
        public void GetValuesFromLilionTransfer(Options.Currency curr)
        {
            string json;
            try
            {
                var webClient = new System.Net.WebClient();
                json = GetResponseInSpecificCurrency(webClient, curr, Currencies.ExchangeType.LilionTransfer,
                    Currencies.CoinType.Bitcoin);
                if (String.IsNullOrEmpty(json))
                    throw new ExchangeException("Response in specific currency was not received.");
                List<JsonLilion> lilionData = JsonConvert.DeserializeObject<List<JsonLilion>>(json);
                foreach (var currency in lilionData)
                {
                    if (currency.name == "BitCoin")
                    {
                        Currencies.Currency currencyValue = currencies.GetCurrencyValue(Currencies.CoinType.Bitcoin,
                            Currencies.ExchangeType.LilionTransfer);
                        double valueFrom, valueTo;
                        if (curr == Options.Currency.CNY)
                        {
                            var webClientExchangeRate = new System.Net.WebClient();
                            var currencyJson = webClientExchangeRate.DownloadString(USDtoCNY);
                            CurrencyExchangeRate rate = JsonConvert.DeserializeObject<CurrencyExchangeRate>(currencyJson);
                            valueFrom = 1 / (currency.from) * rate.rate;
                            valueTo = 1 / (currency.to) * rate.rate;
                        }
                        else
                        {
                            valueFrom = 1 / currency.from;
                            valueTo = 1 / currency.to;
                        }
                        if (Double.IsInfinity(valueFrom))
                        {
                            throw new Exception();
                        }
                        if (Double.IsInfinity(valueTo))
                        {
                            throw new Exception();
                        }
                        currencyValue.value_from = valueFrom.ToString(DisplayFormat);
                        currencyValue.value_to = valueTo.ToString(DisplayFormat);
                        currencies.SetCurrencyValue(Currencies.CoinType.Bitcoin, Currencies.ExchangeType.LilionTransfer,
                            currencyValue);
                        continue;
                    }
                    else if (currency.name == "LiteCoin")
                    {
                        Currencies.Currency currencyValue = currencies.GetCurrencyValue(Currencies.CoinType.Litecoin,
                            Currencies.ExchangeType.LilionTransfer);

                        double valueFrom, valueTo;
                        if (curr == Options.Currency.CNY)
                        {
                            var webClientExchangeRate = new System.Net.WebClient();
                            var currencyJson = webClientExchangeRate.DownloadString(USDtoCNY);
                            CurrencyExchangeRate rate = JsonConvert.DeserializeObject<CurrencyExchangeRate>(currencyJson);
                            valueFrom = 1 / (currency.from) * rate.rate;
                            valueTo = 1 / (currency.to) * rate.rate;
                        }
                        else
                        {
                            valueFrom = 1 / currency.from;
                            valueTo = 1 / currency.to;
                        }
                        if (Double.IsInfinity(valueFrom))
                        {
                            throw new Exception();
                        }
                        if (Double.IsInfinity(valueTo))
                        {
                            throw new Exception();
                        }

                        currencyValue.value_from = valueFrom.ToString(DisplayFormat);
                        currencyValue.value_to = valueTo.ToString(DisplayFormat);
                        currencies.SetCurrencyValue(Currencies.CoinType.Litecoin, Currencies.ExchangeType.LilionTransfer,
                            currencyValue);
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                if(e is ExchangeException)
                    Log.ExchangeFails(e,false);
                else
                    Log.Error(e);
                currencies.SetCurrencyValue(Currencies.CoinType.Bitcoin, Currencies.ExchangeType.LilionTransfer,
                    new Currencies.Currency());
                currencies.SetCurrencyValue(Currencies.CoinType.Litecoin, Currencies.ExchangeType.LilionTransfer,
                    new Currencies.Currency());
                return;
            }
        }