-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
221 lines (153 loc) · 9.91 KB
/
Program.cs
File metadata and controls
221 lines (153 loc) · 9.91 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
using System;
using System.Net.Http; // WebRequest yerine bunu kullan
using System.Threading.Tasks;
using Newtonsoft.Json; // JSON için
namespace criptoCurrent
{
internal class Program
{
// HttpClient'ı bir kez oluşturup tekrar kullanmak en iyisidir
private static readonly HttpClient client = new HttpClient();
// Main metodunu 'async Task' yapıyoruz ki 'await' kullanabilelim
static async Task Main(string[] args)
{
Console.WriteLine("Fİyat Takipçisi Başlatıldı...");
Console.WriteLine("-------------------------------------");
// Sonsuz döngü yerine her 5 saniyede bir çalıştıralım
while (true)
{
try
{
// TrBinance API'sinden BTC fiyatını çek
await GetCryptoPrice("BTCUSDT");
// Diğerlerini de çekmek istersen (yorumu kaldır):
// await GetCryptoPrice("ETHUSDT");
// await GetCryptoPrice("XRPUSDT");
// await GetCryptoPrice("BNBUSDT");
}
catch (Exception ex)
{
Console.WriteLine($"HATA: {ex.Message}");
}
// API'yi sürekli meşgul etmemek için 5 saniye bekle
await Task.Delay(5000);
}
}
/// <summary>
/// Belirtilen sembol için TrBinance API'sinden fiyatı çeker.
/// </summary>
/// <param name="symbol">Örn: "BTCUSDT", "ETHUSDT"</param>
private static async Task GetCryptoPrice(string symbol)
{
// Bu, TrBinance'in (veya global Binance'in) resmi fiyat API uç noktasıdır
string apiUrl = $"https://api.trbinance.com/api/v3/ticker/price?symbol={symbol}";
// API'ye GET isteği gönder
HttpResponseMessage response = await client.GetAsync(apiUrl);
if (response.IsSuccessStatusCode)
{
// API'den gelen JSON yanıtını oku
string jsonString = await response.Content.ReadAsStringAsync();
// Gelen JSON'ı ({"symbol":"BTCUSDT","price":"65000.12"}) işle
var apiResponse = JsonConvert.DeserializeObject<BinanceTicker>(jsonString);
// Fiyatı yazdır
Console.WriteLine($"{DateTime.Now} * {apiResponse.Symbol} Fiyatı: {apiResponse.Price}");
}
else
{
// API hatası varsa bildir
Console.WriteLine($"Hata: {symbol} fiyatı çekilemedi. Status: {response.StatusCode}");
}
}
}
/// <summary>
/// API'den gelen JSON yanıtını temsil eden basit bir sınıf.
/// </summary>
public class BinanceTicker
{
public string Symbol { get; set; }
public string Price { get; set; }
}
}
/*
for (int i = 0; ; i++)
{
WebRequest ETH_USDT_request = HttpWebRequest.Create("https://www.trbinance.com/trade/ETH_USDT");
WebResponse ETH_USDT_response = ETH_USDT_request.GetResponse();
StreamReader ReadResponse_ETH = new StreamReader(ETH_USDT_response.GetResponseStream());
string sourceCodes_ETH = ReadResponse_ETH.ReadToEnd();
int ContentStartIndex_ETH = sourceCodes_ETH.IndexOf("<span data-v-e1725664>") + 22;
int ContentEndIndex_ETH = sourceCodes_ETH.Substring(ContentStartIndex_ETH).IndexOf("</span>");
DateTime bugun = DateTime.Now;
Console.WriteLine(bugun + " *SXP now: " + sourceCodes_ETH.Substring(ContentStartIndex_ETH, ContentEndIndex_ETH));
//
WebRequest BTC_USDT_request = HttpWebRequest.Create("https://www.trbinance.com/trade/BTC_USDT");
WebResponse BTC_USDT_response = BTC_USDT_request.GetResponse();
StreamReader ReadResponse_BTC = new StreamReader(BTC_USDT_response.GetResponseStream());
string sourceCodes_BTC = ReadResponse_BTC.ReadToEnd();
int ContentStartIndex_BTC = sourceCodes_BTC.IndexOf("<span data-v-e1725664>") + 22;
int ContentEndIndex_BTC = sourceCodes_BTC.Substring(ContentStartIndex_BTC).IndexOf("</span>");
DateTime bugun1 = DateTime.Now;
Console.WriteLine(bugun1 + " *BTC now: " + sourceCodes_BTC.Substring(ContentStartIndex_BTC, ContentEndIndex_BTC));
//new
// BTC = BTC * sourceCodes_BTC.Substring(ContentStartIndex_BTC, ContentEndIndex_BTC);
//
WebRequest SXP_USDT_request = HttpWebRequest.Create("https://www.trbinance.com/trade/SXP_USDT");
WebResponse SXP_USDT_response = SXP_USDT_request.GetResponse();
StreamReader ReadResponse_SXP = new StreamReader(SXP_USDT_response.GetResponseStream());
string sourceCodes_SXP = ReadResponse_SXP.ReadToEnd();
int ContentStartIndex_SXP = sourceCodes_SXP.IndexOf("<span data-v-e1725664>") + 22;
int ContentEndIndex_SXP = sourceCodes_SXP.Substring(ContentStartIndex_SXP).IndexOf("</span>");
DateTime bugun2 = DateTime.Now;
Console.WriteLine(bugun2 + " *SXP now: " + sourceCodes_SXP.Substring(ContentStartIndex_SXP, ContentEndIndex_SXP));
//
WebRequest BNB_USDT_request = HttpWebRequest.Create("https://www.trbinance.com/trade/BNB_USDT");
WebResponse BNB_USDT_response = BNB_USDT_request.GetResponse();
StreamReader ReadResponse_BNB = new StreamReader(BNB_USDT_response.GetResponseStream());
string sourceCodes_BNB = ReadResponse_BNB.ReadToEnd();
int ContentStartIndex_BNB = sourceCodes_BNB.IndexOf("<span data-v-e1725664>") + 22;
int ContentEndIndex_BNB = sourceCodes_BNB.Substring(ContentStartIndex_BNB).IndexOf("</span>");
DateTime bugun3 = DateTime.Now;
Console.WriteLine(bugun3 + " *BNB now: " + sourceCodes_BNB.Substring(ContentStartIndex_BNB, ContentEndIndex_BNB));
//
WebRequest XRP_USDT_request = HttpWebRequest.Create("https://www.trbinance.com/trade/XRP_USDT");
WebResponse XRP_USDT_response = XRP_USDT_request.GetResponse();
StreamReader ReadResponse_XRP = new StreamReader(XRP_USDT_response.GetResponseStream());
string sourceCodes_XRP = ReadResponse_XRP.ReadToEnd();
int ContentStartIndex_XRP = sourceCodes_XRP.IndexOf("<span data-v-e1725664>") + 22;
int ContentEndIndex_XRP = sourceCodes_XRP.Substring(ContentStartIndex_XRP).IndexOf("</span>");
DateTime bugun4 = DateTime.Now;
Console.WriteLine(bugun4 + " *XRP now: " + sourceCodes_XRP.Substring(ContentStartIndex_XRP, ContentEndIndex_XRP));
//
WebRequest CAKE_BUSD_request = HttpWebRequest.Create("https://www.trbinance.com/trade/CAKE_BUSD");
WebResponse CAKE_BUSD_response = CAKE_BUSD_request.GetResponse();
StreamReader ReadResponse_CAKE = new StreamReader(CAKE_BUSD_response.GetResponseStream());
string sourceCodes_CAKE = ReadResponse_CAKE.ReadToEnd();
int ContentStartIndex_CAKE = sourceCodes_CAKE.IndexOf("<span data-v-e1725664>") + 22;
int ContentEndIndex_CAKE = sourceCodes_CAKE.Substring(ContentStartIndex_CAKE).IndexOf("</span>");
DateTime bugun5 = DateTime.Now;
Console.WriteLine(bugun4 + " *CAKE now: " + sourceCodes_CAKE.Substring(ContentStartIndex_CAKE, ContentEndIndex_CAKE));
string[] BTC_DB = sourceCodes_BTC.Substring(ContentStartIndex_BTC, ContentEndIndex_BTC).Split(new char[' ']);
for (int p = 0; p < BTC_DB.Length; p++)
{
Console.WriteLine(BTC_DB[p]); // correct value
}
string[] XRP_DB = sourceCodes_XRP.Substring(ContentStartIndex_XRP, ContentEndIndex_XRP).Split(new char[' ']);
for (int o = 0; o < XRP_DB.Length; o++)
{
Console.WriteLine(XRP_DB[o]); // correct value
}
string[] BNB_DB = sourceCodes_BNB.Substring(ContentStartIndex_BNB, ContentEndIndex_BNB).Split(new char[' ']);
for (int u = 0; u < BNB_DB.Length; u++)
{
Console.WriteLine(BNB_DB[u]); // correct value
}
string[] CAKE_DB = sourceCodes_CAKE.Substring(ContentStartIndex_CAKE, ContentEndIndex_CAKE).Split(new char[' ']);
for (int y = 0; y < CAKE_DB.Length; y++)
{
Console.WriteLine(CAKE_DB[y]); // correct value
}
Console.WriteLine();
Console.WriteLine("TOTAL:");
Console.WriteLine();
}
*/