internal static decimal BonusCalculation(MosaicConfigElement m, decimal amount)
        {
            var bonuses = ConfigurationManager.GetSection("MosaicBonusConfigElement") as MyBonusConfigSection;

            foreach (MosaicBonusConfigElement b in bonuses.Bonuses)
            {
                var start = DateTime.ParseExact(b.StartDateTime, "yyyy-MM-dd HH:mm:ss",
                                                System.Globalization.CultureInfo.InvariantCulture);

                var end = DateTime.ParseExact(b.EndDateTime, "yyyy-MM-dd HH:mm:ss",
                                              System.Globalization.CultureInfo.InvariantCulture);

                if (DateTime.Now.Ticks > start.Ticks && DateTime.Now.Ticks < end.Ticks && (m.MosaicNameSpace + ":" + m.MosaicID == b.TokenAssignedTo))
                {
                    return(amount += amount / 100 * decimal.Parse(b.BonusPercent));
                }
            }

            return(amount);
        }
        internal static long RateCalculation(long xem, int divisibility, MosaicConfigElement m)
        {
            decimal rate = 0.0M;

            UriBuilder uri = new UriBuilder()
            {
                Host  = "api.coinmarketcap.com",
                Path  = "/v1/ticker/nem",
                Query = "convert=USD"
            };

            var Con2 = new Connection(uri);

            var Http = (HttpWebRequest)WebRequest.Create(Con2.Uri.Uri.AbsoluteUri);

            Http.Accept = "application/json";

            var asyncResult = new ManualAsyncResult2();

            Http.BeginGetResponse(asyncResult.WrapHandler(ar =>
            {
                var response = Http.EndGetResponse(ar);

                Stream responseStream = response.GetResponseStream();

                var currencyData = JsonConvert.DeserializeObject <List <currenyData> >(new StreamReader(responseStream).ReadToEnd());

                rate = decimal.Parse(currencyData[0].price_usd);
            }), null);

            // wait for callback to complete
            asyncResult.AsyncWaitHandle.WaitOne();

            // calculate amount of xar to return
            var amount = xem / (decimal.Parse(m.MosaicCost) / rate);

            // round up to nearest decimal based on mosaic divisibility
            amount = (Math.Ceiling(amount / (decimal)Math.Pow(10, 6 - divisibility)));

            return((long)BonusCalculation(m, amount));
        }