Exemplo n.º 1
0
        public static async Task <HistDataResponse> GetMarketHistoryV2(string delta)
        {
            HttpRequestMessage mesg = new HttpRequestMessage()
            {
                RequestUri = new Uri("https://bittrex.com/Api/v2.0/pub/market/GetTicks?marketName=" + delta + "&tickInterval=fiveMin", UriKind.Absolute),
                Method     = HttpMethod.Get
            };

            HistDataResponse    history  = null;
            HttpResponseMessage response = await client.SendAsync(mesg);

            if (response.IsSuccessStatusCode)
            {
                history = await response.Content.ReadAsAsync <HistDataResponse>();
            }
            else if (response.StatusCode == System.Net.HttpStatusCode.ServiceUnavailable)
            {
                do
                {
                    Thread.Sleep(50);
                    response = await client.SendAsync(mesg);
                }while (response.StatusCode == System.Net.HttpStatusCode.ServiceUnavailable);
            }
            else
            {
                Console.WriteLine("FAIL:  " + response.ReasonPhrase);
            }

            history.MarketDelta = delta.Replace('-', '_');

            return(history);
        }
Exemplo n.º 2
0
        private void UpdateDataTable(HistDataResponse data, SQLiteCommand cmd)
        {
            //look for market. if !exist then CreateNewDataTable()
            cmd.CommandText = string.Format("SELECT CASE WHEN tbl_name = '{0}' THEN 1 ELSE 0 END FROM sqlite_master WHERE tbl_name = '{0}' AND type = 'table'", data.MarketDelta);
            if (!Convert.ToBoolean(cmd.ExecuteScalar()))
            {
                CreateNewDataTable(data, cmd);
                return;
            }

            cmd.CommandText = string.Format("SELECT * FROM {0} ORDER BY datetime(DateTime) DESC Limit 1", data.MarketDelta);
            DateTime dt = Convert.ToDateTime(cmd.ExecuteScalar());

            foreach (HistDataLine line in data.result)
            {
                if (line.T <= dt)
                {
                    continue;
                }
                else
                {
                    EnterSQLiteRow(line, cmd, data.MarketDelta);
                }
            }

            saved++;
            Console.Write("\rDOWNLOADING MARKETS: {0}/{1}", saved, totalCount);
        }
Exemplo n.º 3
0
        private async Task EnqueueData(string delta)
        {
            HistDataResponse histData = await BtrexREST.GetMarketHistoryV2(delta);

            if (histData.success != true)
            {
                Console.WriteLine("    !!!!ERR GET-HISTORY>>> " + histData.message);
                return;
            }

            DataQueue.Enqueue(histData);
        }
Exemplo n.º 4
0
        private void CreateNewDataTable(HistDataResponse data, SQLiteCommand cmd)
        {
            cmd.CommandText = string.Format("CREATE TABLE IF NOT EXISTS {0} (DateTime TEXT, Open TEXT, Close TEXT, Low TEXT, High TEXT, Volume TEXT)", data.MarketDelta);
            cmd.ExecuteNonQuery();

            foreach (HistDataLine line in data.result)
            {
                EnterSQLiteRow(line, cmd, data.MarketDelta);
            }

            saved++;
            Console.Write("\rDOWNLOADING MARKETS: {0}/{1}", saved, totalCount);
        }