Exemple #1
0
        void ReadCoin(Enumeraveis.Moedas moeda)
        {
            String  JSON  = Request(moeda, "ticker", richTicker);
            JObject JCoin = JsonConvert.DeserializeObject <JObject>(JSON);
            Ticker  tick  = JsonConvert.DeserializeObject <Ticker>(JCoin["ticker"].ToString());

            minValue = tick.low;
            maxValue = tick.high;

            String s = Request(Enumeraveis.Moedas.BTC, "trades", richTrade);

            JArray JTrades = JsonConvert.DeserializeObject <JArray>(s);

            foreach (object item in JTrades)
            {
                Negociacoes trade        = JsonConvert.DeserializeObject <Negociacoes>(item.ToString());
                BitCoinData _bitCoinData = new BitCoinData();
                _bitCoinData.Date        = trade.date;
                _bitCoinData.Transaction = trade.tid;
                _bitCoinData.Amount      = (float)trade.amount;
                _bitCoinData.Price       = (float)trade.price;
                _bitCoinData.Type        = (trade.type == "sell") ? 1 : 0;

                input.Add(_bitCoinData);

                if (richTrade.InvokeRequired)
                {
                    richTrade.Invoke(new Action(() => richTrade.Text += "\r\n"));
                }
                else
                {
                    richTrade.Text += Convert.ToInt32(_bitCoinData.Date) +
                                      _bitCoinData.Price + ", " +
                                      _bitCoinData.Amount + ", " +
                                      _bitCoinData.Transaction + "\r\n";
                }
            }

            #region Criação da Base de Teste diária
            if (!File.Exists(TrainBitcoinDataPath))
            {
                btnMercadoBitCoin_Click(this, new EventArgs());
                // Create a file to write to.
                using (StreamWriter sw = File.CreateText(TrainBitcoinDataPath))
                {
                    Console.WriteLine(maxValue);
                }
            }


            #endregion
        }
Exemple #2
0
        public string HttpGetForTrades(string URI, RichTextBox textBox)
        {
            WebClient cliente = new WebClient();

            cliente.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
            string s = string.Empty;


            int    since   = sinceParam;
            string helpURI = URI;

            for (int i = 0; i < lerJSONs; i++)
            {
                URI = helpURI + "?since=" + since;

                Stream       data   = cliente.OpenRead(URI);
                StreamReader reader = new StreamReader(data);
                s = reader.ReadToEnd();
                JArray      trades       = JsonConvert.DeserializeObject <JArray>(s);
                BitCoinData _bitCoinData = new BitCoinData();

                foreach (object item in trades)
                {
                    Negociacoes trade = JsonConvert.DeserializeObject <Negociacoes>(item.ToString());
                    _bitCoinData             = new BitCoinData();
                    _bitCoinData.Date        = trade.date;
                    _bitCoinData.Transaction = trade.tid;
                    _bitCoinData.Amount      = (float)trade.amount;
                    _bitCoinData.Price       = (float)trade.price;
                    _bitCoinData.Type        = (trade.type == "sell") ? 1 : 0;

                    input.Add(_bitCoinData);
                }
                if (textBox.InvokeRequired)
                {
                    textBox.Invoke(new Action(() => textBox.Text += s + "\r\n"));
                }
                else
                {
                    textBox.Text += s + "\r\n";
                }
                since = Convert.ToInt32(_bitCoinData.Transaction);
                data.Close();
                reader.Close();
            }
            return(s);
        }