Ejemplo n.º 1
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);
             */
        }
Ejemplo n.º 2
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"}
             *
             */
        }
Ejemplo n.º 3
0
        public List <AltCoinTraderDisplayData> GetAltCoinTraderData(decimal rateValue, decimal altCoinRate, decimal krakenRate)
        {
            try
            {
                //get the currency list for each item

                BusLayer.Currency currencyHelper = new Currency();
                DataLayer.MstCurrencyList.MstCurrencyListDataTable currListTbl = currencyHelper.GetCurrentListRows();

                //create a new table to store the data
                DataLayer.TrnAltCoinTraderValue.AltCoinTraderDisplayDataTable AltCoinTable = new DataLayer.TrnAltCoinTraderValue.AltCoinTraderDisplayDataTable();

                //foreach of the currency list items get the relevent current price
                foreach (DataLayer.MstCurrencyList.MstCurrencyListRow currListRow in currListTbl)
                {
                    try
                    {
                        //create a new row
                        DataLayer.TrnAltCoinTraderValue.AltCoinTraderDisplayRow newAltCoinTraderRow = AltCoinTable.NewAltCoinTraderDisplayRow();

                        newAltCoinTraderRow.DT_RowId   = currListRow.MstCurrencyListGuid.ToString();
                        newAltCoinTraderRow.CryptoCoin = currListRow.Code.ToUpper();
                        newAltCoinTraderRow.SortOrder  = currListRow.SortOrder;

                        AltCoinTable.AddAltCoinTraderDisplayRow(newAltCoinTraderRow);
                    }
                    catch (Exception ex)
                    {
                        //unable to get current list item
                    }
                }


                //values used for the coins fixed withdrawl fees
                FixedWithdrawalFees fwf = new FixedWithdrawalFees();

                //once we have added all the rows that we want, we need to go and get the ASk PRICE value from Kraken for that value
                //loop through each of the currency list items and get the their value based on the currency [USD]
                foreach (DataLayer.TrnAltCoinTraderValue.AltCoinTraderDisplayRow altCoinRow in AltCoinTable)
                {
                    try
                    {
                        DataLayer.TrnKrakenValue.TrnKrakenValueRow valueRow =
                            currencyHelper.GetLastKrakenDataForCurrecyListAndCurrency(1, Guid.Parse(altCoinRow.DT_RowId));

                        altCoinRow.AskPrice = valueRow.Ask.ToString();

                        //go and get the altcointrader data from the last screen scape, for this currency list item
                        DataLayer.TrnAltCoinTraderValue.AltCoinTraderSecurityRow securityRow = currencyHelper.GetLastSecurityRowForAltCoinTrader(Guid.Parse(altCoinRow.DT_RowId), (int)BusLayer.Currency.PrmSellBuy.Buy);

                        decimal feeWithRate = 0;

                        switch (altCoinRow.CryptoCoin)
                        {
                        case "DASH":
                            feeWithRate = fwf.DASH;
                            break;

                        case "ETH":
                            feeWithRate = fwf.ETH;
                            break;

                        case "LTC":
                            feeWithRate = fwf.LTC;
                            break;

                        case "BTC":
                            feeWithRate = fwf.XBT;
                            break;

                        case "XRP":
                            feeWithRate = fwf.XRP;
                            break;

                        case "ZEC":
                            feeWithRate = fwf.XRP;
                            break;

                        default:
                            break;
                        }

                        populateCalcValues(altCoinRow, securityRow, rateValue, altCoinRate, krakenRate, feeWithRate);

                        altCoinRow.AskPrice = Math.Round(valueRow.Ask, 2).ToString().Replace(",", ".");
                    }
                    catch (Exception ex)
                    {
                        //unable to get ask price from kraken data for --
                    }
                }


                if (AltCoinTable.Rows.Count > 0)
                {
                    return(AltCoinTable.AsEnumerable().Select(item => new AltCoinTraderDisplayData
                    {
                        DT_RowId = item["DT_RowId"].ToString(),
                        CryptoCoin = item["CryptoCoin"].ToString(),
                        AskPrice = item["AskPrice"].ToString(),
                        Less25k = item["Less25k"].ToString(),
                        OrderVolumeLess25k = item["OrderVolumeLess25k"].ToString(),
                        OrderCostLess25k = item["OrderCostLess25k"].ToString(),
                        MrgLess25k = item["MrgLess25k"].ToString(),
                        Btw25k50k = item["Btw25k50k"].ToString(),
                        OrderVolumeBtw25k50k = item["OrderVolumeBtw25k50k"].ToString(),
                        OrderCostBtw25k50k = item["OrderCostBtw25k50k"].ToString(),
                        MrgBtw25k50k = item["MrgBtw25k50k"].ToString(),
                        Btw50k100k = item["Btw50k100k"].ToString(),
                        OrderVolumeBtw50k100k = item["OrderVolumeBtw50k100k"].ToString(),
                        OrderCostBtw50k100k = item["OrderCostBtw50k100k"].ToString(),
                        MrgBtw50k100k = item["MrgBtw50k100k"].ToString(),
                        Btw100k150k = item["Btw100k150k"].ToString(),
                        OrderVolumeBtw100k150k = item["OrderVolumeBtw100k150k"].ToString(),
                        OrderCostBtw100k150k = item["OrderCostBtw100k150k"].ToString(),
                        MrgBtw100k150k = item["MrgBtw100k150k"].ToString(),
                        Btw150k200k = item["Btw150k200k"].ToString(),
                        OrderVolumeBtw150k200k = item["OrderVolumeBtw150k200k"].ToString(),
                        OrderCostBtw150k200k = item["OrderCostBtw150k200k"].ToString(),
                        MrgBtw150k200k = item["MrgBtw150k200k"].ToString(),
                        Grt200k = item["Grt200k"].ToString(),
                        OrderVolumeGrt200k = item["OrderVolumeGrt200k"].ToString(),
                        OrderCostGrt200k = item["OrderCostGrt200k"].ToString(),
                        MrgGrt200k = item["MrgGrt200k"].ToString()
                    }).ToList());
                }
                else
                {
                    //no rows were found so we return an empty object
                    return(null);
                }
            }
            catch (Exception exc)
            {
                throw new Exception("Error in Calculation Handler", exc);
            }
        }