-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
104 lines (86 loc) · 3.5 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RestSharp;
namespace CryptoChecker
{
public class Price
{
public int Time { get; set; }
public double Open { get; set; }
public double Close { get; set; }
public double High { get; set; }
public double Low { get; set; }
public double VolumeFrom { get; set; }
public double VolumeTo { get; set; }
}
internal class Program
{
private static List<Price> prices = new List<Price>();
public static DateTime UnixTimeStampToDateTime(double unixTimeStamp)
{
System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToLocalTime();
return dtDateTime;
}
public static int DateToTimeStamp(DateTime date)
{
return (int)(date.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
}
private static void Main(string[] args)
{
Console.WriteLine("Aro jan which cryptoCurrency do you want axper jan ?");
string crypto = Console.ReadLine();
Console.Write("Start from : ");
string timeStart = Console.ReadLine();
Console.Write("To : ");
string timeEnd = Console.ReadLine();
Console.Write("With interval in hours : ");
int interval = int.Parse(Console.ReadLine());
int startTimesStamp = DateToTimeStamp(DateTime.Parse(timeStart));
int endTimesStamp = DateToTimeStamp(DateTime.Parse(timeEnd));
while (endTimesStamp > startTimesStamp)
{
string uri =
$"https://min-api.cryptocompare.com/data/histohour?fsym={crypto}&tsym=USD&limit=2000&aggregate={interval}&toTs={endTimesStamp}";
var client = new RestClient(uri);
var request = new RestRequest(Method.GET);
request.AddHeader("X-CoinAPI-Key", "7A46F0F4-F003-46A5-8A72-2C4BAFF3077A");
IRestResponse response = client.Execute(request);
dynamic content = JsonConvert.DeserializeObject(response.Content);
var datas = content.Data as JArray;
foreach (var data in datas)
{
var price = data.ToObject<Price>();
prices.Add(price);
}
endTimesStamp -= 2000 * 3600;
}
prices = prices.Where(p => p.Time > startTimesStamp)
.Where(p => p.High > 0 && p.Close > 0)
.OrderBy(p => p.Time).ToList();
string json = JsonConvert.SerializeObject(prices, Formatting.Indented);
File.WriteAllText("Prices.json", json);
for (int i = 0; i < prices.Count - 1; ++i)
{
if (prices[i + 1].Time - prices[i].Time > interval * 3600)
{
Console.WriteLine(prices[i + 1].Time - prices[i].Time);
}
}
var csv = new StringBuilder();
foreach (var price in prices)
{
var newLine = $"{UnixTimeStampToDateTime(price.Time)},{price.Close}";
csv.Append(newLine);
csv.Append(Environment.NewLine);
}
File.WriteAllText("Prices.csv", csv.ToString());
}
}
}