Exemplo n.º 1
0
        public double GetRate(string start = "1BTC", string end = "<")
        {
            var parser   = new HtmlParser();
            var document = parser.ParseDocument(content);

            var urls = document.GetElementsByTagName("a");

            foreach (IElement url in urls)
            {
                if (url.GetAttribute("href") != "/btc2qiwi/")
                {
                    continue;
                }
                string content = url
                                 .InnerHtml
                                 .ToUpper()
                                 .Replace(" ", "");

                int startPos  = content.IndexOf(start.ToUpper()) + start.Length;
                int endPos    = content.IndexOf(end.ToUpper(), startPos);
                int amountLen = endPos - startPos;

                string draftAmount = content.Substring(startPos, amountLen);
                string strAmount   = Regex.Match(draftAmount, @"\d+\,?\d+").Value;

                return(MoneyHelper.ToDouble(strAmount.Replace(",", "")));
            }

            return(0);
        }
Exemplo n.º 2
0
        public (double, double) GetRate()
        {
            double rate = 0, balance = 0;

            this.current = httpRequest.Get(BASE_URL + PAIR);
            string html   = this.current.ToString();
            Parser parser = new Parser(html);

            rate = MoneyHelper.ToDouble(parser.GetValueInput("sum1"));
            string draftBalance = parser.GetContent("span_get_max")
                                  .ToLower()
                                  .Replace("max.", "")
                                  .Replace("max", "")
                                  .Replace(":", "")
                                  .Replace("btc", "")
                                  .Trim();

            balance = MoneyHelper.ToDouble(draftBalance);

            return(rate, balance);
        }
Exemplo n.º 3
0
        public double GetAmount(string className, string currency)
        {
            var parser   = new HtmlParser();
            var document = parser.ParseDocument(content);
            var elements = document.GetElementsByClassName(className);

            foreach (var element in elements)
            {
                string elemContent = element.TextContent.ToLower();
                if (elemContent.IndexOf(currency.ToLower().Trim()) == -1)
                {
                    continue;
                }

                string pattern   = @"\d+\.\d+";
                Regex  regex     = new Regex(pattern);
                string numberStr = regex.Match(elemContent).ToString();

                return(MoneyHelper.ToDouble(numberStr));
            }

            return(-1);
        }
Exemplo n.º 4
0
        public List <DetailedCashflowRangeItem> GetDetailedCashflowsWithNotionalSchedule(
            ILogger logger, ICoreCache cache,
            String nameSpace,
            IBusinessCalendar fixingCalendar,
            IBusinessCalendar paymentCalendar,
            CapFloorLegParametersRange_Old legParametersRange,
            List <DateTimeDoubleRangeItem> notionalValueItems,
            ValuationRange valuationRange)
        {
            //Check if the calendars are null. If not build them!
            var list1 = notionalValueItems.Select(item => new Pair <DateTime, decimal>(item.DateTime, Convert.ToDecimal(item.Value))).ToList();
            NonNegativeSchedule       notionalScheduleFpML = NonNegativeScheduleHelper.Create(list1);
            Currency                  currency             = CurrencyHelper.Parse(legParametersRange.Currency);
            NonNegativeAmountSchedule amountSchedule       = NonNegativeAmountScheduleHelper.Create(notionalScheduleFpML, currency);
            InterestRateStream        interestRateStream   = GetCashflowsScheduleWithNotionalSchedule(fixingCalendar, paymentCalendar, legParametersRange, amountSchedule);
            //Add the principal exchanges to the cashflows.
            var principalExchangeList = list1.Select(cashflow => new PrincipalExchange
            {
                adjustedPrincipalExchangeDate = cashflow.First, adjustedPrincipalExchangeDateSpecified = true, principalExchangeAmount = cashflow.Second, principalExchangeAmountSpecified = true
            }).ToArray();

            interestRateStream.cashflows.principalExchange = principalExchangeList;
            UpdateCashflowsWithAmounts(logger, cache, nameSpace, interestRateStream, legParametersRange, valuationRange);
            var list = new List <DetailedCashflowRangeItem>();

            foreach (PaymentCalculationPeriod paymentCalculationPeriod in interestRateStream.cashflows.paymentCalculationPeriod)
            {
                var detailedCashflowRangeItem = new DetailedCashflowRangeItem();
                detailedCashflowRangeItem.PaymentDate    = paymentCalculationPeriod.adjustedPaymentDate;
                detailedCashflowRangeItem.StartDate      = PaymentCalculationPeriodHelper.GetCalculationPeriodStartDate(paymentCalculationPeriod);
                detailedCashflowRangeItem.EndDate        = PaymentCalculationPeriodHelper.GetCalculationPeriodEndDate(paymentCalculationPeriod);
                detailedCashflowRangeItem.NumberOfDays   = PaymentCalculationPeriodHelper.GetNumberOfDays(paymentCalculationPeriod);
                detailedCashflowRangeItem.FutureValue    = MoneyHelper.ToDouble(paymentCalculationPeriod.forecastPaymentAmount);
                detailedCashflowRangeItem.PresentValue   = MoneyHelper.ToDouble(paymentCalculationPeriod.presentValueAmount);
                detailedCashflowRangeItem.DiscountFactor = (double)paymentCalculationPeriod.discountFactor;
                detailedCashflowRangeItem.NotionalAmount = (double)PaymentCalculationPeriodHelper.GetNotionalAmount(paymentCalculationPeriod);
                detailedCashflowRangeItem.CouponType     = GetCouponType(paymentCalculationPeriod);
                detailedCashflowRangeItem.Rate           = (double)PaymentCalculationPeriodHelper.GetRate(paymentCalculationPeriod);
                CalculationPeriod      calculationPeriod      = PaymentCalculationPeriodHelper.GetCalculationPeriods(paymentCalculationPeriod)[0];
                FloatingRateDefinition floatingRateDefinition = XsdClassesFieldResolver.CalculationPeriodGetFloatingRateDefinition(calculationPeriod);
                switch (detailedCashflowRangeItem.CouponType.ToLower())
                {
                case "cap":
                {
                    Strike strike = floatingRateDefinition.capRate[0];
                    detailedCashflowRangeItem.StrikeRate = (double)strike.strikeRate;
                    break;
                }

                case "floor":
                {
                    Strike strike = floatingRateDefinition.floorRate[0];
                    detailedCashflowRangeItem.StrikeRate = (double)strike.strikeRate;
                    break;
                }

                default:
                {
                    string message =
                        String.Format("Specified coupon type : '{0}' is not supported. Please use one of these: 'cap, floor'", detailedCashflowRangeItem.CouponType.ToLower());
                    throw new NotSupportedException(message);
                }
                }
                //  If  floating rate - retrieve the spread.
                //
                detailedCashflowRangeItem.Spread = (double)PaymentCalculationPeriodHelper.GetSpread(paymentCalculationPeriod);
                var fixingDate = new DateTime();
                var tempDate   = PaymentCalculationPeriodHelper.GetFirstFloatingFixingDate(paymentCalculationPeriod);
                if (tempDate != null)
                {
                    fixingDate = (DateTime)tempDate;
                }
                detailedCashflowRangeItem.FixingDate = fixingDate;
                detailedCashflowRangeItem.Currency   = "Not Specified";
                if (currency != null)
                {
                    detailedCashflowRangeItem.Currency = currency.Value;
                }
                list.Add(detailedCashflowRangeItem);
            }
            return(list);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("no args");
                return;
            }

            Settings settings = new Settings()
            {
                data       = SettingsData.Load(),
                proxyItems = ProxySettings.Load()
            };
            DB                db                = new DB();
            StorageModel      storageModel      = new StorageModel(db).MigrateUp();
            EmailStorageModel emailStorageModel = new EmailStorageModel(storageModel);
            EmailStack        emailStack        = new EmailStack(emailStorageModel, settings.data.allowEmails);
            ProxyStorageModel proxyStorageModel = new ProxyStorageModel(storageModel);
            ProxySettingsItem proxy             = null;
            KonvertImDriver   driver            = new KonvertImDriver();

            switch (args[ACTION_ID])
            {
            case "--create":
                for (int nTry = 0; nTry < settings.data.cntTryOnFault; nTry++)
                {
                    try
                    {
                        if (settings.proxyItems != null)
                        {
                            ProxyStack proxyStack = new ProxyStack(settings.proxyItems, proxyStorageModel);
                            while (--MAX_CNT_CHECK_PROXY > 0)
                            {
                                try
                                {
                                    var tester = new KonvertImDriver();
                                    proxy = proxyStack.Next();
                                    tester.httpRequest.Proxy = proxy.CreateProxyClient();

                                    if (tester.CheckIsWork())
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        proxy = null;
                                    }
                                }
                                catch (Exception) { }
                            }
                        }

                        if (proxy != null)
                        {
                            driver.httpRequest.Proxy = proxy.CreateProxyClient();
                        }

                        driver.LoadMainPage();

                        double amountRUB  = MoneyHelper.ToDouble(args[1]);
                        double amountBTC  = amountRUB * (driver.GetRate() / 5000);
                        string phone      = PhoneHelper.PhoneReplacer(args[2]);
                        string addressBTC = args[3];
                        string email      = new String(phone.Where(Char.IsDigit).ToArray()) + emailStack.Next();

                        driver.Create(amountRUB, amountBTC, phone, addressBTC, email);
                        string             orderId;
                        CreateResponseType response = driver.ParseFinalPage(out orderId);
                        response.btc_amount = amountBTC.ToString();
                        response.email      = KonvertImDriver.TICKET_URL.Replace("{order}", orderId);
                        response.ip         = proxy == null ? "local" : proxy.ip;

                        if (!response.IsValid())
                        {
                            throw new Exception();
                        }

                        Console.Write(response.toJson());
                        return;
                    }
                    catch (Exception) { }
                }
                break;
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            //args = "--create 5500 +79062614762 3DQjZmcaiCJ9sKCkLk1QZ9CdLv5btKzrHb".Split(' ');
            try
            {
                Settings settings = new Settings()
                {
                    data       = SettingsData.Load(),
                    proxyItems = ProxySettings.Load()
                };
                DB                 db                = new DB();
                StorageModel       storageModel      = new StorageModel(db).MigrateUp();
                EmailStorageModel  emailStorageModel = new EmailStorageModel(storageModel);
                EmailStack         emailStack        = new EmailStack(emailStorageModel, settings.data.allowEmails);
                ProxyStorageModel  proxyStorageModel = new ProxyStorageModel(storageModel);
                ProxySettingsItem  proxy             = null;
                MineExchangeDriver driver            = new MineExchangeDriver();

                if (args.Length == 0)
                {
                    Console.WriteLine("no args");
                    return;
                }

                switch (args[ACTION_ID])
                {
                case "--rate":
                    (double, double)rateList = driver.GetRate();
                    Console.WriteLine(new RateResponseType()
                    {
                        rate    = rateList.Item1,
                        balance = rateList.Item2
                    }
                                      .toJson());
                    break;

                case "--create":
                    for (int nTry = 0; nTry < settings.data.cntTryOnFault; nTry++)
                    {
                        try
                        {
                            if (settings.proxyItems != null)
                            {
                                ProxyStack proxyStack = new ProxyStack(settings.proxyItems, proxyStorageModel);
                                while (--MAX_CNT_CHECK_PROXY > 0)
                                {
                                    try
                                    {
                                        var tester = new MineExchangeDriver();
                                        proxy = proxyStack.Next();
                                        tester.httpRequest.Proxy = proxy.CreateProxyClient();

                                        if (tester.CheckIsWork())
                                        {
                                            break;
                                        }
                                        else
                                        {
                                            proxy = null;
                                        }
                                    }
                                    catch (Exception) { }
                                }
                            }

                            if (proxy != null)
                            {
                                driver.httpRequest.Proxy = proxy.CreateProxyClient();
                            }

                            double amountRUB  = MoneyHelper.ToDouble(args[1]);
                            string phone      = PhoneHelper.PhoneReplacer(args[2]);
                            string addressBTC = args[3];

                            string email = new String(
                                phone.Where(Char.IsDigit).ToArray()
                                ) + emailStack.Next();

                            var urlCreate = driver.GetUrlForCreate(email,
                                                                   amountRUB,
                                                                   phone.Replace(" ", "").Replace("+", ""),
                                                                   addressBTC);
                            double amountBTC    = 0;
                            var    urlFianlPage = driver.GetUrlFinalPage(urlCreate, out amountBTC);
                            var    recvisits    = driver.GetRecvisitsOnFinalPage(urlFianlPage);

                            RequestPaymentResponseType response = new RequestPaymentResponseType()
                            {
                                account    = PhoneHelper.PhoneReplacer(recvisits.extra_account),
                                comment    = recvisits.extra_comment,
                                email      = email,
                                btc_amount = amountBTC,
                                ip         = proxy == null ? "local" : proxy.ip
                            };

                            if (!response.IsValid())
                            {
                                throw new Exception();
                            }

                            Console.WriteLine(response.toJson());
                            return;
                        }
                        catch (Exception) { }
                    }
                    break;
                }
            } catch (Exception) { }
        }
Exemplo n.º 7
0
        public double GetRate()
        {
            Parser parser = new Parser(current.ToString());

            return(MoneyHelper.ToDouble(parser.GetPlaceholder("btc_amount")));
        }