Ejemplo n.º 1
0
        public static string CheckTxidBalance(string _address, decimal _balance, out decimal _outBalance)
        {
            _outBalance = 0M;
            string _error = "";

            try
            {
                //get info
                _error = "get info";
                string        _url       = $"https://api.trxplorer.io/v2/account/{_address}";
                WebClientPlus _webClient = new WebClientPlus(10000);
                string        _result    = _webClient.DownloadString(_url);
                _webClient.Dispose();
                JObject _json = JObject.Parse(_result);

                //balance
                _error = "balance";
                string _value = _json["balance"] + "";
                _outBalance = Common.Change2Decimal(_value);
                if (!_outBalance.ToString().Contains("."))
                {
                    _outBalance = _outBalance / 1000000M;
                }
                if (_outBalance < _balance)
                {
                    return(_error);
                }

                return("");
            }
            catch (Exception)
            {
                return(_error);
            }
        }
Ejemplo n.º 2
0
        private bool Login()
        {
            using (WebClientPlus webClient = new WebClientPlus())
            {
                try 
                {
                    var dadosLogin = new NameValueCollection();
                    dadosLogin.Add("_method", "POST");
                    dadosLogin.Add("data[User][username]", Settings.Default["Login"].ToString());
                    dadosLogin.Add("data[User][password]", Settings.Default["Senha"].ToString());
                    dadosLogin.Add("data[lembrar]", "on");

                    webClient.IgnoreRedirects = true;
                    webClient.UploadValues("http://legendas.tv/login", "POST", dadosLogin);
                    var cookie = webClient.ResponseHeaders["Set-Cookie"];
                    cookieAuth = new Cookie("au", cookie.Substring(cookie.LastIndexOf("au=") + 3, cookie.IndexOf(";", cookie.LastIndexOf("au=")) - (cookie.LastIndexOf("au=") + 3)), "/", "legendas.tv");
                    return true;
                }
                catch
                {
                    MessageBox.Show("Ocorreu um erro ao logar no site do Legendas.tv");
                    return false;
                }
            }
        }
Ejemplo n.º 3
0
 public static bool Init()
 {
     try
     {
         if (Installed())
         {
             return(true);
         }
         using (var client = new WebClientPlus())
         {
             if (!Directory.Exists(@".\tmp"))
             {
                 LogManager.Log("wit.log", @".\tmp doesn't exist it will be created");
                 Directory.CreateDirectory(@".\tmp");
             }
             LogManager.Log("wit.log", "Downloading WIT ...");
             client.DownloadFile(WIT_URL, @".\tmp\wit.zip");
             LogManager.Log("wit.log", "Extracting WIT ...");
             ZipFile.ExtractToDirectory(@".\tmp\wit.zip", @".");
             LogManager.Log("wit.log", "Renaming folder to wit ...");
             Directory.Move(@".\wit-v3.03a-r8245-cygwin", @".\wit");
             LogManager.Log("wit.log", "Cleaning ...");
             File.Delete(@".\tmp\wit.zip");
             LogManager.Log("wit.log", "Done!");
             return(true);
         }
     }
     catch (Exception ex)
     {
         LogManager.Log("wit_err.log", ex.Message + "\r\n" + ex.StackTrace);
         return(false);
     }
 }
Ejemplo n.º 4
0
        private void BooksRunner(object _object)
        {
            string _pair  = _object.ToString();
            string _pairA = _pair.Contains("_") ? _pair.Split('_')[0] : _pair;
            string _url   = $"/public/orderbook/{_pairA}";

            if (this.BooksLimit != "")
            {
                _url += $"?count={this.BooksLimit}";
            }

            this.Books[_pair, MarketSide.Ask] = new BookItems(MarketSide.Ask);
            this.Books[_pair, MarketSide.Bid] = new BookItems(MarketSide.Bid);

            string _result = "";

            while (this.Running)
            {
                Thread.Sleep(1000);

                try
                {
                    WebClientPlus _client = new WebClientPlus(5000);
                    _result = _client.DownloadString($"{base.HttpUrl}{_url}");
                    _client.Dispose();

                    JObject _json = JObject.Parse(_result);

                    BookItems _asks = new BookItems(MarketSide.Ask);
                    BookItems _bids = new BookItems(MarketSide.Bid);

                    this.Books.Timestamp = _json["data"]["timestamp"].Value <long>();

                    foreach (var _item in _json["data"]["asks"])
                    {
                        decimal _price  = _item["price"].Value <decimal>();
                        decimal _amount = _item["quantity"].Value <decimal>();
                        _asks.Insert(_price.ToString(), Math.Abs(_price), _amount);
                    }
                    foreach (var _item in _json["data"]["bids"])
                    {
                        decimal _price  = _item["price"].Value <decimal>();
                        decimal _amount = _item["quantity"].Value <decimal>();
                        _bids.Insert(_price.ToString(), Math.Abs(_price), _amount);
                    }

                    this.Books[_pair, MarketSide.Ask] = _asks;
                    this.Books[_pair, MarketSide.Bid] = _bids;
                }
                catch (Exception _ex)
                {
                    this.OnLog($"GetBooks Error:{_result}");
                    this.OnLog($"GetBooks Error:{_ex.ToString()}");
                }
            }
        }
Ejemplo n.º 5
0
        public static string CheckTxidBalance(string _address, decimal _balance, out decimal _outBalance)
        {
            _outBalance = 0M;
            string _error = "";

            try
            {
                //get info
                _error = "get info";
                string        _url       = $"https://data.ripple.com/v2/accounts/{_address}/balances";
                WebClientPlus _webClient = new WebClientPlus(10000);
                string        _result    = _webClient.DownloadString(_url);
                _webClient.Dispose();
                JObject _json   = JObject.Parse(_result);
                JArray  _jArray = JArray.Parse(_json["balances"].ToString());
                JToken  _jToken = null;
                foreach (var _item in _jArray)
                {
                    string _currency = _item["currency"].Value <string>();
                    if (_currency.ToLower() != "xrp")
                    {
                        continue;
                    }
                    _jToken = _item;
                    break;
                }
                if (_jToken == null)
                {
                    return(_error);
                }

                //balance
                _error = "balance";
                string _value = _jToken["value"].Value <string>();
                //_outBalance = Common.Change2Decimal(_value);
                _outBalance = decimal.Parse(_value);
                //if (!_outBalance.ToString().Contains("."))
                //{
                //    //_outBalance = _outBalance / 1000000000000000000M;
                //    _outBalance = _outBalance / 1000000M;
                //}
                if (_outBalance < _balance)
                {
                    return(_error);
                }

                return("");
            }
            catch (Exception _ex)
            {
                Console.WriteLine(_ex.Message);
                return(_error);
            }
        }
Ejemplo n.º 6
0
        public static string CheckTxidBalance(string _txid, int _index, string _address, decimal _balance, out decimal _outBalance)
        {
            _outBalance = 0M;
            string _error = "";

            try
            {
                //get info
                _error = "get info";
                string        _url       = $"https://bch-chain.api.btc.com/v3/tx/{_txid}?verbose=3";
                WebClientPlus _webClient = new WebClientPlus(10000);
                string        _result    = _webClient.DownloadString(_url);
                _webClient.Dispose();
                JObject _json   = JObject.Parse(_result);
                JToken  _jToken = _json["data"]["outputs"][_index];

                //address
                _error = "address";
                string _cashAddr = _jToken["addresses"][0].Value <string>().Trim();
                _cashAddr = Change2NewAddress(_cashAddr);
                if (_cashAddr != _address.Trim())
                {
                    return(_error);
                }

                //balance
                _error = "balance";
                string _value = _jToken["value"].Value <string>();
                _outBalance = decimal.Parse(_value);
                if (!_value.Contains("."))
                {
                    _outBalance = _outBalance / 100000000M;
                }
                if (_outBalance != _balance)
                {
                    return(_error);
                }

                //spent
                _error = "spent";
                if (_jToken["spent_by_tx"].HasValues || _jToken["spent_by_tx_position"].Value <string>().Trim() != "-1")
                {
                    return(_error);
                }

                return("");
            }
            catch (Exception)
            {
                return(_error);
            }
        }
Ejemplo n.º 7
0
        private void BooksRunner(object _object)
        {
            string _pair = _object.ToString();
            string _url  = $"/api/v1/depth?symbol={_pair}&limit=10";

            this.Books[_pair, MarketSide.Ask] = new BookItems(MarketSide.Ask);
            this.Books[_pair, MarketSide.Bid] = new BookItems(MarketSide.Bid);

            string _result = "";

            while (this.Running)
            {
                Thread.Sleep(1000);

                try
                {
                    WebClientPlus _client = new WebClientPlus(5000);
                    _result = _client.DownloadString($"{base.HttpUrl}{_url}");
                    _client.Dispose();

                    JObject _json = JObject.Parse(_result);

                    BookItems _asks = new BookItems(MarketSide.Ask);
                    BookItems _bids = new BookItems(MarketSide.Bid);

                    this.Books.Timestamp = DateTimePlus.DateTime2JSTime(DateTime.UtcNow);

                    foreach (var _item in _json["asks"])
                    {
                        decimal _price  = _item[0].Value <decimal>();
                        decimal _amount = _item[1].Value <decimal>();
                        _asks.Insert(_price.ToString(), Math.Abs(_price), _amount);
                    }
                    foreach (var _item in _json["bids"])
                    {
                        decimal _price  = _item[0].Value <decimal>();
                        decimal _amount = _item[1].Value <decimal>();
                        _bids.Insert(_price.ToString(), Math.Abs(_price), _amount);
                    }

                    this.Books[_pair, MarketSide.Ask] = _asks;
                    this.Books[_pair, MarketSide.Bid] = _bids;
                }
                catch (Exception _ex)
                {
                    this.OnLog($"GetBooks Error:{_result}");
                    this.OnLog($"GetBooks Error:{_ex.ToString()}");
                }
            }
        }
Ejemplo n.º 8
0
 public static JObject GetTxidInfo(string _txid)
 {
     try
     {
         string        _url       = $"https://chain.api.btc.com/v3/tx/{_txid}?verbose=3";
         WebClientPlus _webClient = new WebClientPlus(10000);
         string        _result    = _webClient.DownloadString(_url);
         JObject       _json      = JObject.Parse(_result);
         return(_json);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Ejemplo n.º 9
0
 public static string Change2NewAddress(string _address)
 {
     try
     {
         WebClientPlus _client = new WebClientPlus(10000);
         string        _return = _client.DownloadString($"https://cashaddr.bitcoincash.org/convert?address={_address}");
         _client.Dispose();
         JObject _json = JObject.Parse(_return);
         return(_json["cashaddr"].Value <string>().Trim());
     }
     catch (Exception)
     {
         return("");
     }
 }
Ejemplo n.º 10
0
 public static string GetCurrentHeight()
 {
     try
     {
         string        _url       = "https://api.blockchair.com/bitcoin-cash/stats";
         WebClientPlus _webClient = new WebClientPlus(10000);
         string        _result    = _webClient.DownloadString(_url);
         _webClient.Dispose();
         JObject _json = JObject.Parse(_result);
         return(_json["data"]["blocks"].Value <string>());
     }
     catch (Exception)
     {
         return("");
     }
 }
Ejemplo n.º 11
0
 public static string GetCurrentHeight()
 {
     try
     {
         string        _url       = "https://apilist.tronscan.org/api/system/status";
         WebClientPlus _webClient = new WebClientPlus(10000);
         string        _result    = _webClient.DownloadString(_url);
         _webClient.Dispose();
         JObject _json = JObject.Parse(_result);
         return(_json["database"]["block"].Value <string>());
     }
     catch (Exception)
     {
         return("");
     }
 }
Ejemplo n.º 12
0
 public static string GetCurrentHeight()
 {
     try
     {
         string        _url       = "https://api.blockcypher.com/v1/btc/main";
         WebClientPlus _webClient = new WebClientPlus(10000);
         string        _result    = _webClient.DownloadString(_url);
         _webClient.Dispose();
         JObject _json = JObject.Parse(_result);
         return(_json["height"].Value <string>());
     }
     catch (Exception)
     {
         return("");
     }
 }
Ejemplo n.º 13
0
 public static string GetCurrentHeight()
 {
     try
     {
         //string _url = "https://xmr.tokenview.com/api/blocks/xmr/1/1";
         string        _url       = "https://monerohash.com/api/stats?_=" + DateTimePlus.DateTime2JSTime(DateTime.UtcNow).ToString() + DateTime.UtcNow.Millisecond.ToString();
         WebClientPlus _webClient = new WebClientPlus(10000);
         string        _result    = _webClient.DownloadString(_url);
         _webClient.Dispose();
         JObject _json = JObject.Parse(_result);
         //return _json["data"][0]["block_no"].Value<string>();
         return(_json["network"]["height"].Value <string>());
     }
     catch (Exception)
     {
         return("");
     }
 }
Ejemplo n.º 14
0
 public static string GetCurrentHeight()
 {
     try
     {
         string        _url       = "https://api.etherscan.io/api?module=proxy&action=eth_blockNumber&apikey=YourApiKeyToken";
         WebClientPlus _webClient = new WebClientPlus(10000);
         string        _result    = _webClient.DownloadString(_url);
         _webClient.Dispose();
         JObject _json = JObject.Parse(_result);
         _result = _json["result"].Value <string>();
         int _height = Convert.ToInt32(_result, 16);
         return(_height.ToString());
     }
     catch (Exception)
     {
         return("");
     }
 }
Ejemplo n.º 15
0
 public static string GetCurrentHeight()
 {
     try
     {
         //string _url = "https://data.ripple.com/v2/health/importer?verbose=true";
         string        _url       = "https://data.ripple.com/v2/ledgers/";
         WebClientPlus _webClient = new WebClientPlus(10000);
         string        _result    = _webClient.DownloadString(_url);
         _webClient.Dispose();
         JObject _json = JObject.Parse(_result);
         //return _json["last_validated_ledger"].Value<string>();
         return(_json["ledger"]["ledger_index"].Value <string>());
     }
     catch (Exception)
     {
         return("");
     }
 }
Ejemplo n.º 16
0
        public override async Task <MemeInfo> RandomAsync()
        {
            WebClientPlus wc;
            string        html;

            try
            {
                wc   = new WebClientPlus();
                html = await wc.DownloadStringTaskAsync(_uris[UriType.Random]);
            }
            catch (WebException ex)
            {
                throw new ServiceOrConnectionException("Could not load the page", ex);
            }

            IConfiguration   config   = Configuration.Default;
            IBrowsingContext context  = BrowsingContext.New(config);
            IDocument        document = await context.OpenAsync(req => req.Content(html).Address(_baseUrl));

            IElement picDiv = document.DocumentElement.QuerySelector("#main_container .pic");

            IHtmlImageElement img =
                (IHtmlImageElement)picDiv.QuerySelector(".pic_image img");

            IHtmlHeadingElement h =
                (IHtmlHeadingElement)picDiv.QuerySelector("h1.picture");

            if (img == null || h == null)
            {
                throw new NotFoundException("Either \"img\" or \"h1\" tag could not be found");
            }

            return(new MemeInfo
            {
                ViewURI = wc.ResponseURI.ToString(),
                URI = img.Source,
                Alt = img.AlternativeText,
                Name = h.TextContent
            });
        }
Ejemplo n.º 17
0
        public static string CheckTxidBalance(string _address, decimal _balance, out decimal _outBalance)
        {
            _outBalance = 0M;
            string _error = "";

            try
            {
                //get info
                _error = "get info";
                //string _url = $"http://api.ethplorer.io/getAddressInfo/0x32Be343B94f860124dC4fEe278FDCBD38C102D88?apiKey=freekey";
                //string _url = $"https://api.blockcypher.com/v1/eth/main/addrs/{_address}/balance";
                string        _url       = $"https://api.etherscan.io/api?module=account&action=balance&address={_address}&tag=latest&apikey=YourApiKeyToken";
                WebClientPlus _webClient = new WebClientPlus(10000);
                string        _result    = _webClient.DownloadString(_url);
                _webClient.Dispose();
                JObject _json = JObject.Parse(_result);

                //balance
                _error = "balance";
                string _value = _json["result"] + "";
                _outBalance = decimal.Parse(_value);
                if (!_value.Contains("."))
                {
                    _outBalance = _outBalance / 1000000000000000000M;
                }
                if (_outBalance < _balance)
                {
                    return(_error);
                }

                return("");
            }
            catch (Exception)
            {
                return(_error);
            }
        }
Ejemplo n.º 18
0
        public async void BuscaLegenda(Episodio episodio)
        {
            string urlLegenda = "http://legendas.tv/util/carrega_legendas_busca/{0}/1/d";
            string urlDownload = "http://legendas.tv/downloadarquivo/{0}";

            HtmlAgilityPack.HtmlDocument html = new HtmlAgilityPack.HtmlDocument();

            using (WebClientPlus webClient = new WebClientPlus())
            {
                try
                {
                    webClient.OutboundCookies.Add(cookieAuth);
                    var htmlString = await webClient.DownloadStringTaskAsync(String.Format(urlLegenda, episodio.Nome));
                    html.LoadHtml(htmlString);

                    string idLegenda = String.Empty;

                    var links = html.DocumentNode.SelectNodes("//p//a[ contains (@href, 'download') ]");

                    if (links == null)
                    {
                        episodio.Download = "Erro";
                        episodio.Status = "Legenda não encontrada.";
                    }
                    else
                    {
                        foreach (var link in links)
                        {
                            idLegenda = link.Attributes["href"].Value.Replace("/download/", "");
                            idLegenda = idLegenda.Substring(0, idLegenda.IndexOf('/'));
                        }

                        var uriDownload = new Uri(String.Format(urlDownload, idLegenda));
                        var nomeArquivoDownload = String.Format("{0}{1}.rar", pastaDownloads, idLegenda);

                        episodio.ArquivoDownload = nomeArquivoDownload;

                        if (!File.Exists(nomeArquivoDownload))
                        {
                            webClient.DownloadFileAsync(uriDownload, nomeArquivoDownload, episodio);
                            webClient.DownloadFileCompleted += webClient_DownloadFileCompleted;
                            webClient.DownloadProgressChanged += webClient_DownloadProgressChanged;
                        }
                        else
                        {
                            episodio.Download = "100";
                            ExtrairLegenda(episodio);
                        }

                        dgvEpisodios.FirstDisplayedScrollingRowIndex = dgvEpisodios.Rows.Count - 1;
                        dgvEpisodios.Update();
                    }
                }
                catch
                {
                    episodio.Download = "Erro";
                    episodio.Status = "Ocorreu um erro na busca da legenda.";
                }
            }
        }
Ejemplo n.º 19
0
        public static string CheckTxidBalance(string _txid, int _index, string _address, decimal _balance, out decimal _outBalance)
        {
            _outBalance = 0M;
            string _error = "";

            try
            {
                //get info
                _error = "get info";
                //string _url = $"https://chain.so/api/v2/get_tx_outputs/ltc/{_txid}";
                string        _url       = $"https://litecoinblockexplorer.net/api/tx/{_txid}";
                WebClientPlus _webClient = new WebClientPlus(10000);
                string        _result    = _webClient.DownloadString(_url);
                _webClient.Dispose();
                JObject _json   = JObject.Parse(_result);
                JArray  _jArray = JArray.Parse(_json["vout"].ToString());
                JToken  _jToken = null;
                foreach (var _item in _jArray)
                {
                    int _n = _item["n"].Value <int>();
                    if (_n != _index)
                    {
                        continue;
                    }
                    _jToken = _item;
                    break;
                }
                if (_jToken == null)
                {
                    return(_error);
                }

                //address
                _error = "address";
                string _cashAddr = _jToken["scriptPubKey"]["addresses"][0].Value <string>().Trim();
                if (_cashAddr != _address.Trim())
                {
                    return(_error);
                }

                //balance
                _error = "balance";
                string _value = _jToken["value"].Value <string>();
                _outBalance = decimal.Parse(_value);
                if (!_value.Contains("."))
                {
                    _outBalance = _outBalance / 100000000M;
                }
                if (_outBalance != _balance)
                {
                    return(_error);
                }

                //spent
                _error = "spent";
                if (_jToken["spentTxId"].HasValues || _jToken["spentIndex"].HasValues || _jToken["spentHeight"].HasValues)
                {
                    return(_error);
                }

                return("");
            }
            catch (Exception)
            {
                return(_error);
            }
        }
Ejemplo n.º 20
0
        private void BooksRunner(object _object)
        {
            string _pair = _object.ToString();
            string _url  = $"/v1.1/public/getorderbook?market={_pair}&type=both";

            this.Books[_pair, MarketSide.Ask] = new BookItems(MarketSide.Ask);
            this.Books[_pair, MarketSide.Bid] = new BookItems(MarketSide.Bid);

            string _result = "";

            while (this.Running)
            {
                Thread.Sleep(1000);

                try
                {
                    WebClientPlus _client = new WebClientPlus(5000);
                    _result = _client.DownloadString($"{this.HttpUrl}{_url}");
                    _client.Dispose();

                    JObject _json = JObject.Parse(_result);

                    BookItems _asks = new BookItems(MarketSide.Ask);
                    BookItems _bids = new BookItems(MarketSide.Bid);

                    this.Books.Timestamp = DateTimePlus.DateTime2JSTime(DateTime.UtcNow);

                    foreach (var _item in _json["result"]["sell"])
                    {
                        decimal _price  = _item["Rate"].Value <decimal>();
                        decimal _amount = _item["Quantity"].Value <decimal>();
                        _asks.Insert(_price.ToString(), Math.Abs(_price), _amount);
                    }
                    foreach (var _item in _json["result"]["buy"])
                    {
                        decimal _price  = _item["Rate"].Value <decimal>();
                        decimal _amount = _item["Quantity"].Value <decimal>();
                        _bids.Insert(_price.ToString(), Math.Abs(_price), _amount);
                    }

                    BookItems _asksLimit = new BookItems(MarketSide.Ask);
                    BookItems _bidsLimit = new BookItems(MarketSide.Bid);
                    foreach (var _item in _asks.OrderBy(b => b.Value.Price).Take(10))
                    {
                        decimal _price  = _item.Value.Price;
                        decimal _amount = _item.Value.Amount;
                        _asksLimit.Insert(_price.ToString(), Math.Abs(_price), _amount);
                    }
                    foreach (var _item in _bids.OrderByDescending(b => b.Value.Price).Take(10))
                    {
                        decimal _price  = _item.Value.Price;
                        decimal _amount = _item.Value.Amount;
                        _bidsLimit.Insert(_price.ToString(), Math.Abs(_price), _amount);
                    }

                    this.Books[_pair, MarketSide.Ask] = _asksLimit;
                    this.Books[_pair, MarketSide.Bid] = _bidsLimit;
                }
                catch (Exception _ex)
                {
                    this.OnLog($"GetBooks Error:{_result}");
                    this.OnLog($"GetBooks Error:{_ex.ToString()}");
                }
            }
        }
Ejemplo n.º 21
0
 public void BeforeEachTest() => _wc = new WebClientPlus();
Ejemplo n.º 22
0
        private void BooksRunner(object _object)
        {
            string _pair = _object.ToString();
            string _url  = $"/api/spot/v3/instruments/{_pair}/book?size=10";

            this.Books[_pair, MarketSide.Ask] = new BookItems(MarketSide.Ask);
            this.Books[_pair, MarketSide.Bid] = new BookItems(MarketSide.Bid);

            string _result = "";

            while (this.Running)
            {
                Thread.Sleep(1000);

                try
                {
                    WebClientPlus _client = new WebClientPlus(10000);
                    _result = _client.DownloadString($"{this.HttpUrl}{_url}");
                    _client.Dispose();

                    JObject _json = JObject.Parse(_result);

                    BookItems _asks = new BookItems(MarketSide.Ask);
                    BookItems _bids = new BookItems(MarketSide.Bid);

                    this.Books.Timestamp = DateTimePlus.DateTime2JSTime(DateTime.UtcNow);

                    foreach (var _item in _json["asks"])
                    {
                        decimal _price  = decimal.Parse(_item[0].Value <string>(), System.Globalization.NumberStyles.Float);
                        decimal _amount = decimal.Parse(_item[1].Value <string>(), System.Globalization.NumberStyles.Float);
                        _asks.Insert(_price.ToString(), Math.Abs(_price), _amount);
                    }
                    foreach (var _item in _json["bids"])
                    {
                        decimal _price  = decimal.Parse(_item[0].Value <string>(), System.Globalization.NumberStyles.Float);
                        decimal _amount = decimal.Parse(_item[1].Value <string>(), System.Globalization.NumberStyles.Float);
                        _bids.Insert(_price.ToString(), Math.Abs(_price), _amount);
                    }

                    BookItems _asksLimit = new BookItems(MarketSide.Ask);
                    BookItems _bidsLimit = new BookItems(MarketSide.Bid);
                    foreach (var _item in _asks.OrderBy(b => b.Value.Price).Take(10))
                    {
                        decimal _price  = _item.Value.Price;
                        decimal _amount = _item.Value.Amount;
                        _asksLimit.Insert(_price.ToString(), Math.Abs(_price), _amount);
                    }
                    foreach (var _item in _bids.OrderByDescending(b => b.Value.Price).Take(10))
                    {
                        decimal _price  = _item.Value.Price;
                        decimal _amount = _item.Value.Amount;
                        _bidsLimit.Insert(_price.ToString(), Math.Abs(_price), _amount);
                    }

                    this.Books[_pair, MarketSide.Ask] = _asksLimit;
                    this.Books[_pair, MarketSide.Bid] = _bidsLimit;
                }
                catch (Exception _ex)
                {
                    this.OnLog($"GetBooks Error:{_result}");
                    this.OnLog($"GetBooks Error:{_ex.ToString()}");
                }
            }
        }
Ejemplo n.º 23
0
        private void BooksRunner(object _object)
        {
            string _pair = _object.ToString();
            string _url  = $"/{_pair}/depth";

            this.Books[_pair, MarketSide.Ask] = new BookItems(MarketSide.Ask);
            this.Books[_pair, MarketSide.Bid] = new BookItems(MarketSide.Bid);

            string _result = "";

            while (this.Running)
            {
                Thread.Sleep(1000);

                try
                {
                    WebClientPlus _client = new WebClientPlus(5000);
                    _result = _client.DownloadString($"{this.UrlPublic}{_url}");
                    _client.Dispose();

                    JObject _json = JObject.Parse(_result);

                    BookItems _asks = new BookItems(MarketSide.Ask);
                    BookItems _bids = new BookItems(MarketSide.Bid);

                    this.Books.Timestamp = _json["data"]["timestamp"].Value <long>();

                    foreach (var _item in _json["data"]["asks"])
                    {
                        decimal _price  = _item[0].Value <decimal>();
                        decimal _amount = _item[1].Value <decimal>();
                        _asks.Insert(_price.ToString(), Math.Abs(_price), _amount);
                    }
                    foreach (var _item in _json["data"]["bids"])
                    {
                        decimal _price  = _item[0].Value <decimal>();
                        decimal _amount = _item[1].Value <decimal>();
                        _bids.Insert(_price.ToString(), Math.Abs(_price), _amount);
                    }

                    BookItems _asksLimit = new BookItems(MarketSide.Ask);
                    BookItems _bidsLimit = new BookItems(MarketSide.Bid);
                    foreach (var _item in _asks.OrderBy(b => b.Value.Price).Take(10))
                    {
                        decimal _price  = _item.Value.Price;
                        decimal _amount = _item.Value.Amount;
                        _asksLimit.Insert(_price.ToString(), Math.Abs(_price), _amount);
                    }
                    foreach (var _item in _bids.OrderByDescending(b => b.Value.Price).Take(10))
                    {
                        decimal _price  = _item.Value.Price;
                        decimal _amount = _item.Value.Amount;
                        _bidsLimit.Insert(_price.ToString(), Math.Abs(_price), _amount);
                    }

                    this.Books[_pair, MarketSide.Ask] = _asksLimit;
                    this.Books[_pair, MarketSide.Bid] = _bidsLimit;
                }
                catch (Exception _ex)
                {
                    this.OnLog($"GetBooks Error:{_result}");
                    this.OnLog($"GetBooks Error:{_ex.ToString()}");
                }
            }
        }