Exemplo n.º 1
0
        public List <Models.TradeInfo> GetPairsInfo()
        {
            if (_tradesInfoList.Count > 0)
            {
                return(_tradesInfoList);
            }
            string tempUrl = "https://api.crex24.com/v2/public/tickers";

            try
            {
                WebRequest request = WebRequest.Create(tempUrl);
                request.Method = "GET";
                //request.ContentType = "application/x-www-form-urlencoded";
                request.ContentType = "application/json";

                // Get the response.
                WebResponse response = request.GetResponse();
                // Display the status.
                Console.WriteLine(((HttpWebResponse)response).StatusDescription);
                // Get the stream containing content returned by the server.
                Stream dataStream = response.GetResponseStream();

                StreamReader reader = new StreamReader(dataStream);

                string json = reader.ReadToEnd();
                List <Models.TradeInfoResponce> tradesInfo = JsonConvert.DeserializeObject <List <Models.TradeInfoResponce> >(json);

                //find all pairs
                foreach (var tradeItem in tradesInfo)
                {
                    if (tradeItem.ask.HasValue && tradeItem.bid.HasValue)

                    /*
                     * if (tradeItem.instrument.Length ==7 &&
                     *  (tradeItem.instrument.Contains("LTC") && tradeItem.instrument.Contains("BTC") ||
                     *  tradeItem.instrument.Contains("BTC") && tradeItem.instrument.Contains("ETC") ||
                     *  tradeItem.instrument.Contains("ETC") && tradeItem.instrument.Contains("ETH") ||
                     *  tradeItem.instrument.Contains("ETH") && tradeItem.instrument.Contains("LTC") ||
                     *  tradeItem.instrument.Contains("BTC") && tradeItem.instrument.Contains("ETH"))
                     *  )
                     */
                    {
                        Models.TradeInfo newItem = new Models.TradeInfo();
                        newItem.Symbol       = tradeItem.instrument;
                        newItem.PurchaseRate = tradeItem.ask.Value;
                        newItem.SellingRate  = tradeItem.bid.Value;
                        newItem.UpdatedDate  = tradeItem.timestamp;

                        _tradesInfoList.Add(newItem);
                    }
                }
            }
            catch (WebException)
            {
            }

            return(_tradesInfoList);
        }
Exemplo n.º 2
0
        public List <Models.TradeInfo> GetCurrenciesInfo()
        {
            List <Models.TradeInfo> result = new List <Models.TradeInfo>();

            string tempUrl = "https://api.crex24.com/v2/public/tickers";

            try
            {
                WebRequest request = WebRequest.Create(tempUrl);
                request.Method = "GET";
                //request.ContentType = "application/x-www-form-urlencoded";
                request.ContentType = "application/json";

                // Get the response.
                WebResponse response = request.GetResponse();
                // Display the status.
                Console.WriteLine(((HttpWebResponse)response).StatusDescription);
                // Get the stream containing content returned by the server.
                Stream dataStream = response.GetResponseStream();

                StreamReader reader = new StreamReader(dataStream);

                string json = reader.ReadToEnd();
                List <Models.TradeInfoResponce> tradesInfo = JsonConvert.DeserializeObject <List <Models.TradeInfoResponce> >(json);

                foreach (var tradeItem in tradesInfo)
                {
                    if (tradeItem.instrument.Contains("-USD") && tradeItem.bid.HasValue && tradeItem.ask.HasValue)
                    {
                        Models.TradeInfo newItem = new Models.TradeInfo();
                        newItem.Symbol       = tradeItem.instrument.Replace("-USD", "");
                        newItem.PurchaseRate = tradeItem.ask.Value;
                        newItem.SellingRate  = tradeItem.bid.Value;
                        newItem.UpdatedDate  = tradeItem.timestamp;
                        result.Add(newItem);
                    }
                }
            }
            catch (WebException)
            {
            }

            return(result.OrderByDescending(rp => rp.SellingRate).ToList());
        }
Exemplo n.º 3
0
        Models.TradeInfo AddItem(decimal curBuy, decimal curSell, decimal curRecom, bool kupil,
                                 string symbol1, string symbol2, DateTime procDate)
        {
            Models.TradeInfo newItem = new Models.TradeInfo();
            newItem.Symbol       = symbol1 + "/" + symbol2;
            newItem.PurchaseRate = curBuy;
            newItem.SellingRate  = curSell;
            newItem.UpdatedDate  = procDate;
            string tmpCoinChange = "Продал " + symbol1 + " за " + curSell.ToString();

            newItem.Comment = tmpCoinChange + ". Рекоммендация купить " + symbol1 + " за " + curRecom.ToString();
            if (kupil)
            {
                tmpCoinChange   = "Купил " + symbol1 + " за " + curBuy.ToString();
                newItem.Comment = tmpCoinChange + ". Рекоммендация продать " + symbol1 + " за " + curRecom.ToString();
            }

            return(newItem);
        }