コード例 #1
0
        public string GetLastUpdatedAltCoinTraderPage(System.Web.SessionState.HttpSessionState session)
        {
            //go and get the data for the required sources.
            BusLayer.Currency currencyHelper = new BusLayer.Currency();
            DataLayer.TrnSourceUpdate.TrnSourceUpdateRow krakenSourceRow        = currencyHelper.GetLastTrnSourceUpdateRowForSource((int)BusLayer.Handler.CurrencySource.Sources.Kraken);
            DataLayer.TrnSourceUpdate.TrnSourceUpdateRow altcointraderSourceRow = currencyHelper.GetLastTrnSourceUpdateRowForSource((int)BusLayer.Handler.CurrencySource.Sources.Altcointrader);

            string returnString = krakenSourceRow.CreateDate.ToString("MM/dd/yyyy HH:mm:ss") + "|" + altcointraderSourceRow.CreateDate.ToString("MM/dd/yyyy HH:mm:ss");

            return(serializer.Serialize(new HandlerResponse(0, "Success", returnString)));
        }
コード例 #2
0
        public string GetBitCoin30secData(System.Web.SessionState.HttpSessionState session)
        {
            //Get list of saved data
            BusLayer.Currency currencyHelper = new BusLayer.Currency();
            BusLayer.BitCoin  bitcoinHelper  = new BusLayer.BitCoin();
            List <BusLayer.BitCoin.BitCoin30LiveView> bitcoinData = new List <BusLayer.BitCoin.BitCoin30LiveView>();

            bitcoinData = bitcoinHelper.Get30SecData("btc");


            return(serializer.Serialize(new HandlerResponse(0, "Success", bitcoinData)));
        }
コード例 #3
0
        public string GetAltCoinTraderData(System.Web.SessionState.HttpSessionState session, string param)
        {
            Dictionary <string, string> input = serializer.Deserialize <Dictionary <string, string> >(param);

            //check if we have a currency value passed through, else get the current value
            string usdZarRate    = input["USDRate"];
            string altCoinRate   = input["AltCoinRate"];
            string krakenFeeRate = input["KrakenRate"];

            decimal usdRate = 0;

            if (usdZarRate == string.Empty)
            {
            }
            else
            {
                usdRate = decimal.Parse(usdZarRate.Replace('.', ','));
            }

            decimal altfeeRate = 0;

            if (altCoinRate == string.Empty)
            {
            }
            else
            {
                altfeeRate = decimal.Parse(altCoinRate.Replace('.', ','));
            }

            decimal krakfeeRate = 0;

            if (krakenFeeRate == string.Empty)
            {
            }
            else
            {
                krakfeeRate = decimal.Parse(krakenFeeRate.Replace('.', ','));
            }

            //Get list of saved data
            BusLayer.Currency     currencyHelper = new BusLayer.Currency();
            BusLayer.Calculations calcHelper     = new BusLayer.Calculations();
            List <BusLayer.Calculations.AltCoinTraderDisplayData> altCoinData = new List <BusLayer.Calculations.AltCoinTraderDisplayData>();

            altCoinData = calcHelper.GetAltCoinTraderData(usdRate, altfeeRate, krakfeeRate);


            return(serializer.Serialize(new HandlerResponse(0, "Success", altCoinData)));
        }
コード例 #4
0
        private void GetData()
        {
            WebClient webClient = new WebClient();

            webClient.Headers.Add("user-agent", "Only a test!");
            BusLayer.Currency currencyHelper = new BusLayer.Currency();

            KrakenClient.KrakenClient client = new KrakenClient.KrakenClient();

            DataLayer.MstCurrencyList.MstCurrencyListDataTable currentLisTbl = currencyHelper.GetCurrentListRows();

            DataLayer.PrmCurrency.PrmCurrencyDataTable currencyTable = currencyHelper.GetCurrencyRows();

            try
            {
                foreach (DataLayer.MstCurrencyList.MstCurrencyListRow listRow in currentLisTbl)
                {
                    string currencyCode = listRow.Code;

                    if (currencyCode == "BTC")
                    {
                        currencyCode = "XBT";
                    }

                    foreach (DataLayer.PrmCurrency.PrmCurrencyRow currencyRow in currencyTable)
                    {
                        try
                        {
                            string newcurrencyCode = currencyCode + currencyRow.Currency;

                            Jayrock.Json.JsonObject js5on = client.GetTicker(new List <string> {
                                newcurrencyCode
                            });

                            string innerRes = string.Empty;
                            if (newcurrencyCode == "XBTUSD")
                            {
                                innerRes = "XXBTZUSD";
                            }
                            else if (newcurrencyCode == "XBTEUR")
                            {
                                innerRes = "XXBTZEUR";
                            }
                            else if (newcurrencyCode == "ETHUSD")
                            {
                                innerRes = "XETHZUSD";
                            }
                            else if (newcurrencyCode == "ETHEUR")
                            {
                                innerRes = "XETHZEUR";
                            }
                            else if (newcurrencyCode == "XRPUSD")
                            {
                                innerRes = "XXRPZUSD";
                            }
                            else if (newcurrencyCode == "XRPEUR")
                            {
                                innerRes = "XXRPZEUR";
                            }
                            else if (newcurrencyCode == "LTCUSD")
                            {
                                innerRes = "XLTCZUSD";
                            }
                            else if (newcurrencyCode == "LTCEUR")
                            {
                                innerRes = "XLTCZEUR";
                            }
                            else if (newcurrencyCode == "ZECUSD")
                            {
                                innerRes = "XZECZUSD";
                            }
                            else if (newcurrencyCode == "ZECEUR")
                            {
                                innerRes = "XZECZEUR";
                            }
                            else if (newcurrencyCode == "DASHUSD")
                            {
                                innerRes = "DASHUSD";
                            }
                            else if (newcurrencyCode == "DASHEUR")
                            {
                                innerRes = "DASHEUR";
                            }



                            if (innerRes != string.Empty)
                            {
                                Dictionary <string, object> values = JsonConvert.DeserializeObject <Dictionary <string, object> >(js5on["result"].ToString());

                                Dictionary <string, object> Innervalues = JsonConvert.DeserializeObject <Dictionary <string, object> >(values[innerRes].ToString());

                                //create the new row
                                DataLayer.TrnKrakenValue.TrnKrakenValueDataTable newTbl = new DataLayer.TrnKrakenValue.TrnKrakenValueDataTable();
                                DataLayer.TrnKrakenValue.TrnKrakenValueRow       newRow = newTbl.NewTrnKrakenValueRow();

                                newRow.TrnKrakenValueGuid  = Guid.NewGuid();
                                newRow.MstCurrencyListGuid = listRow.MstCurrencyListGuid;
                                newRow.Ask                 = decimal.Parse(JsonConvert.DeserializeObject <List <string> >(Innervalues["a"].ToString())[0], new CultureInfo("en-US"));
                                newRow.Bid                 = decimal.Parse(JsonConvert.DeserializeObject <List <string> >(Innervalues["b"].ToString())[0], new CultureInfo("en-US"));
                                newRow.CreateDate          = DateTime.Now;
                                newRow.PrmCurrencyId       = currencyRow.PrmCurrencyId;
                                newRow.PrmCurrencySourceId = 3;


                                newTbl.AddTrnKrakenValueRow(newRow);
                                currencyHelper.UpdateCurrencyValue(newRow);
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            //kraken is ask

            /*
             * XBTEUR
             * XBTUSD
             *
             * ETHEUR
             * ETHUSD
             *
             * XRPEUR
             * XRPUSD
             *
             *
             * LTC
             * ZEC
             * DASH
             *
             * <pair_name> = pair name
             * a = ask array(<price>, <whole lot volume>, <lot volume>),
             * b = bid array(<price>, <whole lot volume>, <lot volume>),
             * c = last trade closed array(<price>, <lot volume>),
             * v = volume array(<today>, <last 24 hours>),
             * p = volume weighted average price array(<today>, <last 24 hours>),
             * t = number of trades array(<today>, <last 24 hours>),
             * l = low array(<today>, <last 24 hours>),
             * h = high array(<today>, <last 24 hours>),
             * o = today's opening price
             *
             *
             *
             *
             *
             *
             * bitstamp
             * https://www.bitstamp.net/api/
             *
             * btcusd, btceur,
             * ethusd, etheur,
             * xrpusd, xrpeur
             *
             *
             * {"high": "1.74000",
             * "last": "1.68754",
             * "timestamp": "1516295176" ,  to use
             * "bid": "1.68001",  to use
             * "vwap": "1.33150",
             * "volume": "164572084.34820374",
             * "low": "0.94344",
             *      "ask": "1.68749",  to use
             * "open": "1.29849"}
             *
             */
        }
コード例 #5
0
        private void GetData()
        {
            WebClient webClient = new WebClient();

            webClient.Headers.Add("user-agent", "Only a test!");
            BusLayer.Currency currencyHelper = new BusLayer.Currency();

            DataLayer.MstCurrencyList.MstCurrencyListDataTable currentLisTbl = currencyHelper.GetCurrentListRows();

            DataLayer.PrmCurrency.PrmCurrencyDataTable currencyTable = currencyHelper.GetCurrencyRows();


            foreach (DataLayer.MstCurrencyList.MstCurrencyListRow listRow in currentLisTbl)
            {
                string currencyCode = listRow.Code;

                foreach (DataLayer.PrmCurrency.PrmCurrencyRow currencyRow in currencyTable)
                {
                    try
                    {
                        string newcurrencyCode = currencyCode + currencyRow.Currency;

                        string js5on = webClient.DownloadString("https://www.bitstamp.net/api/v2/ticker/" + newcurrencyCode.ToLower());

                        Dictionary <string, string> values = JsonConvert.DeserializeObject <Dictionary <string, string> >(js5on);

                        //create the new row
                        DataLayer.TrnBitStampValue.TrnBitStampValueDataTable newTbl = new DataLayer.TrnBitStampValue.TrnBitStampValueDataTable();
                        DataLayer.TrnBitStampValue.TrnBitStampValueRow       newRow = newTbl.NewTrnBitStampValueRow();

                        newRow.TrnBitStampValueGuid = Guid.NewGuid();
                        newRow.MstCurrencyListGuid  = listRow.MstCurrencyListGuid;
                        newRow.ask                 = decimal.Parse(values["ask"]);
                        newRow.bid                 = decimal.Parse(values["bid"]);
                        newRow.last_trade          = decimal.Parse(values["last"]);
                        newRow.timestamp           = values["timestamp"];
                        newRow.CreateDate          = DateTime.Now;
                        newRow.PrmCurrencyId       = currencyRow.PrmCurrencyId;
                        newRow.PrmCurrencySourceId = 3;


                        newTbl.AddTrnBitStampValueRow(newRow);
                        currencyHelper.UpdateCurrencyValue(newRow);
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }


            //kraken is ask

            /*
             * XBTEUR
             * XBTUSD
             *
             * ETHEUR
             * ETHUSD
             *
             * XRPEUR
             * XRPUSD
             *
             *
             * LTC
             * ZEC
             * DASH
             *
             * <pair_name> = pair name
             * a = ask array(<price>, <whole lot volume>, <lot volume>),
             * b = bid array(<price>, <whole lot volume>, <lot volume>),
             * c = last trade closed array(<price>, <lot volume>),
             * v = volume array(<today>, <last 24 hours>),
             * p = volume weighted average price array(<today>, <last 24 hours>),
             * t = number of trades array(<today>, <last 24 hours>),
             * l = low array(<today>, <last 24 hours>),
             * h = high array(<today>, <last 24 hours>),
             * o = today's opening price
             *
             *
             *
             *
             *
             *
             * bitstamp
             * https://www.bitstamp.net/api/
             *
             * btcusd, btceur,
             * ethusd, etheur,
             * xrpusd, xrpeur
             *
             *
             * {"high": "1.74000",
             * "last": "1.68754",
             * "timestamp": "1516295176" ,  to use
             * "bid": "1.68001",  to use
             * "vwap": "1.33150",
             * "volume": "164572084.34820374",
             * "low": "0.94344",
             *      "ask": "1.68749",  to use
             * "open": "1.29849"}
             *
             */

            //deserialse the object


            //loop through each of the values and save the data
            //DataLayer.TrnLunoValue.TrnLunoValueDataTable currencyTable = new DataLayer.TrnLunoValue.TrnLunoValueDataTable();

            /*foreach (var item in values)
             * {
             *
             *  List<Dictionary<string, string>> itemList = JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(item.Value.ToString());
             *
             *
             *  foreach (Dictionary<string, string> thisItem in itemList)
             *  {
             *      //get the current list item for the code
             *      //if the code exists it means we want to add the data, else we just continue to the next
             *      try
             *      {
             *          string searchCode = thisItem["pair"];
             *          if (searchCode == "XBTZAR")
             *              searchCode = "BTC";
             *
             *
             *          DataLayer.MstCurrencyList.MstCurrencyListRow currentListRow = currencyHelper.GetCurrentListRowForCode(searchCode);
             *
             *          //add a new row and save the data
             *          DataLayer.TrnLunoValue.TrnLunoValueRow newRow = currencyTable.NewTrnLunoValueRow();
             *
             *          newRow.TrnLunoValueGuid = Guid.NewGuid();
             *          newRow.MstCurrencyListGuid = currentListRow.MstCurrencyListGuid;
             *          newRow.timestamp = thisItem["timestamp"];
             *          newRow.bid = decimal.Parse(thisItem["bid"]);
             *          newRow.ask = decimal.Parse(thisItem["ask"]);
             *          newRow.last_trade = decimal.Parse(thisItem["last_trade"]);
             *          newRow.rolling_24_hour_volume = decimal.Parse(thisItem["rolling_24_hour_volume"]);
             *          newRow.pair = thisItem["pair"];
             *          newRow.CreateDate = DateTime.Now;
             *          newRow.PrmCurrencySourceId = (int)BusLayer.Handler.CurrencySource.Sources.Luno;
             *
             *          currencyTable.AddTrnLunoValueRow(newRow);
             *      }
             *      catch
             *      {
             *
             *      }
             *  }
             * }
             *
             * //update the table
             * currencyHelper.UpdateCurrencyValue(currencyTable);
             */
        }
コード例 #6
0
        private void GetData()
        {
            WebClient webClient = new WebClient();

            webClient.Headers.Add("user-agent", "Only a test!");

            string js5on = webClient.DownloadString("https://api.mybitx.com/api/1/tickers");

            //deserialse the object
            Dictionary <string, object> values = JsonConvert.DeserializeObject <Dictionary <string, object> >(js5on);

            BusLayer.Currency currencyHelper = new BusLayer.Currency();
            //loop through each of the values and save the data
            DataLayer.TrnLunoValue.TrnLunoValueDataTable currencyTable = new DataLayer.TrnLunoValue.TrnLunoValueDataTable();
            foreach (var item in values)
            {
                List <Dictionary <string, string> > itemList = JsonConvert.DeserializeObject <List <Dictionary <string, string> > >(item.Value.ToString());

                int totalBids = 0;
                int maxTotal  = 10;

                foreach (Dictionary <string, string> thisItem in itemList)
                {
                    //get the current list item for the code
                    //if the code exists it means we want to add the data, else we just continue to the next
                    try
                    {
                        string searchCode = thisItem["pair"];
                        if (searchCode == "XBTZAR")
                        {
                            searchCode = "BTC";
                        }


                        DataLayer.MstCurrencyList.MstCurrencyListRow currentListRow = currencyHelper.GetCurrentListRowForCode(searchCode);

                        decimal thisBid = Convert.ToDecimal(thisItem["bid"]);

                        int currentBid = Convert.ToInt32(thisBid);
                        totalBids += currentBid;

                        //if(totalBids >= maxTotal)
                        //{
                        //stop the counter now
                        //   break;
                        //}
                        //order data only - must take the ["Bid"] element and save the price and volume up to a max of 10 BTC coints

                        //add a new row and save the data
                        DataLayer.TrnLunoValue.TrnLunoValueRow newRow = currencyTable.NewTrnLunoValueRow();

                        newRow.TrnLunoValueGuid    = Guid.NewGuid();
                        newRow.MstCurrencyListGuid = currentListRow.MstCurrencyListGuid;
                        newRow.timestamp           = thisItem["timestamp"];
                        newRow.bid                    = decimal.Parse(thisItem["bid"]);
                        newRow.ask                    = decimal.Parse(thisItem["ask"]);
                        newRow.last_trade             = decimal.Parse(thisItem["last_trade"]);
                        newRow.rolling_24_hour_volume = decimal.Parse(thisItem["rolling_24_hour_volume"]);
                        newRow.pair                   = thisItem["pair"];
                        newRow.CreateDate             = DateTime.Now;
                        newRow.PrmCurrencySourceId    = (int)BusLayer.Handler.CurrencySource.Sources.Luno;

                        currencyTable.AddTrnLunoValueRow(newRow);
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }

            //update the table
            currencyHelper.UpdateCurrencyValue(currencyTable);
        }
コード例 #7
0
        private void GetData()
        {
            //the name of the current page we are attempting to get data from
            string currentCurrencyListItem = string.Empty;

            try
            {
                WebClient webClient = new WebClient();
                webClient.Headers.Add("user-agent", "Only a test!");


                string websiteUrl = "https://www.altcointrader.co.za/|https://www.altcointrader.co.za/xrp|https://www.altcointrader.co.za/eth|https://www.altcointrader.co.za/dash|https://www.altcointrader.co.za/ltc|https://www.altcointrader.co.za/zec";

                string[] websiteUrls = websiteUrl.Split('|');

                foreach (string url in websiteUrls)
                {
                    Guid securityKey = Guid.NewGuid();

                    new WebClient();
                    webClient.Headers.Add("user-agent", "Only a test!");
                    string js5on = webClient.DownloadString(url);

                    currentCurrencyListItem = url.Replace("https://www.altcointrader.co.za/", "").ToUpper();

                    if (currentCurrencyListItem == string.Empty)
                    {
                        currentCurrencyListItem = "BTC";
                    }

                    BusLayer.Currency currencyHelper = new BusLayer.Currency();

                    DataLayer.MstCurrencyList.MstCurrencyListRow currencyListRow = currencyHelper.GetCurrentListRowForCode(currentCurrencyListItem);

                    // This expression looks for a sub-string in the form of
                    // "<p>...<a...>...ItemText...</a> and returns the item text.
                    //string expression = @"<p>[^<]*<a[^>]*>(?<item>[^<]*)</a>";

                    //string ex = @"<div class='trade-orders orange-border'></div>";
                    string className     = "trade-table";
                    string globalPattern = String.Format("<table[^>]*?class=([\"'])[^>]*{0}[^>]*\\1[^>]*>(.*?)</table>", className);

                    // This executes the regular expression and returns all
                    // matches found.
                    MatchCollection matches =
                        Regex.Matches(
                            js5on,
                            globalPattern,
                            RegexOptions.Singleline |
                            RegexOptions.Multiline |
                            RegexOptions.IgnoreCase
                            );



                    //go through the first 2 tables only
                    int count = 0;

                    while (count < 2)
                    {
                        string currclassName = string.Empty;
                        if (count == 0)
                        {
                            currclassName = "orderUdSell";
                        }
                        else
                        {
                            currclassName = "orderUdBuy";
                        }

                        string currglobalPattern = String.Format("<tr[^>]*?class = ([\"'])[^>]*{0}[^>]*\\1[^>]*>(.*?)</tr>", currclassName);
                        string currentTable      = matches[count].ToString();

                        MatchCollection currMatches =
                            Regex.Matches(
                                currentTable,
                                currglobalPattern,
                                RegexOptions.Singleline |
                                RegexOptions.Multiline |
                                RegexOptions.IgnoreCase
                                );


                        foreach (var obj in currMatches)
                        {
                            string currentItem  = obj.ToString();
                            int    prmSellBuyId = 0;
                            //replace all the bad characters
                            if (count == 0)
                            {
                                prmSellBuyId = 1;
                                currentItem  = currentItem.Replace("\t", "").Replace("\r\n", "").Replace("<tr class = 'orderUdSell'>", "").Replace("</tr>", "");
                            }
                            else
                            {
                                prmSellBuyId = 2;
                                currentItem  = currentItem.Replace("\t", "").Replace("\r\n", "").Replace("<tr class = 'orderUdBuy'>", "").Replace("</tr>", "");
                            }
                            //[1] - Price
                            //[3] - Coin Amount
                            //[5] - Total
                            string[] spltRes = currentItem.Split('<');

                            string priceValue = string.Empty;
                            string coinValue  = string.Empty;
                            string totalValue = string.Empty;

                            if (count == 0)
                            {
                                priceValue = spltRes[1].Replace("td class = 'orderUdSPr'>", "");
                                coinValue  = spltRes[3].Replace("td class = 'orderUdSAm'>", "");
                                totalValue = spltRes[5].Replace("td>", "");
                            }
                            else
                            {
                                priceValue = spltRes[1].Replace("td class = 'orderUdBPr'>", "");
                                coinValue  = spltRes[3].Replace("td class = 'orderUdBAm'>", "");
                                totalValue = spltRes[5].Replace("td>", "");
                            }

                            System.IO.File.WriteAllText(@"c:\temp\values.txt", "Coin: " + coinValue + " Converted Coin:" + decimal.Parse(coinValue, new CultureInfo("en-US")));

                            //create the new row
                            DataLayer.TrnAltCoinTraderValue.TrnAltCoinTraderValueDataTable newTbl = new DataLayer.TrnAltCoinTraderValue.TrnAltCoinTraderValueDataTable();
                            DataLayer.TrnAltCoinTraderValue.TrnAltCoinTraderValueRow       newRow = newTbl.NewTrnAltCoinTraderValueRow();

                            newRow.TrnAltCoinTraderValueGuid = Guid.NewGuid();
                            newRow.SecurityKey         = securityKey;
                            newRow.MstCurrencyListGuid = currencyListRow.MstCurrencyListGuid;
                            newRow.CoinValue           = decimal.Parse(coinValue, new CultureInfo("en-US"));
                            newRow.PriceValue          = decimal.Parse(priceValue, new CultureInfo("en-US"));
                            newRow.TotalValue          = decimal.Parse(totalValue, new CultureInfo("en-US"));
                            newRow.CreateDate          = DateTime.Now;
                            newRow.PrmCurrencyId       = 3;// currencyRow.PrmCurrencyId;
                            newRow.PrmCurrencySourceId = 1;
                            newRow.PrmSellBuyId        = prmSellBuyId;

                            newTbl.AddTrnAltCoinTraderValueRow(newRow);
                            currencyHelper.UpdateCurrencyValue(newRow);
                        }



                        count++;
                    }
                }
            }
            catch (Exception ex)
            {
                //throw an exception with the code of the page that we are laoding
                throw new Exception("Unable to get page data for : " + currentCurrencyListItem, ex);
            }
        }