Last active
April 25, 2025 07:57
-
-
Save anomal3/b309f0bded07fae3dc0854d0596660bc to your computer and use it in GitHub Desktop.
Не документированное Api Abcex. парсинг валюты USDT/ RUB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ApiAbcex | |
{ | |
private static string AbcexToken = ""; | |
public static async Task<double> GetCurrentRateFiat() | |
{ | |
var @return = string.Empty; | |
var response = await CustomHttpGetResponseAsync(AbcexToken); | |
if (response.StatusCode == HttpStatusCode.Unauthorized) | |
{ | |
var tokenResponse = await GetToken(); | |
var jsonTokens = await tokenResponse.Content.ReadAsStringAsync(); | |
JObject responseObject = JObject.Parse(jsonTokens); | |
string token = responseObject["token"]?.ToString(); | |
AbcexToken = token; | |
await GetCurrentRateFiat(); | |
return 0; | |
} | |
var json = await response.Content.ReadAsStringAsync(); | |
JArray dataArray = JArray.Parse(json); | |
foreach (var item in dataArray) | |
{ | |
string marketId = item["marketId"]?.ToString(); | |
string price = item["price"]?.ToString(); | |
if (marketId == "USDTRUB") | |
@return = price; | |
} | |
return double.Parse(@return); | |
} | |
private static async Task<HttpResponseMessage> CustomHttpGetResponseAsync(string token) | |
{ | |
using (HttpClient httpClient = new HttpClient()) | |
{ | |
httpClient.BaseAddress = new Uri("https://m.abcex.io/api/v1/markets/price-dynamics?lang=ru"); | |
httpClient.DefaultRequestHeaders.Authorization = | |
new AuthenticationHeaderValue("Bearer", token); | |
var response = await httpClient.GetAsync(httpClient.BaseAddress); | |
return response; | |
} | |
} | |
public static async Task<HttpResponseMessage> GetToken() | |
{ | |
using (HttpClient httpClient = new HttpClient()) | |
{ | |
httpClient.BaseAddress = new Uri("https://m.abcex.io/api/v1/auth/login?lang=ru"); | |
var Data = new | |
{ | |
username = "You login", | |
password = "You password", | |
auth2fa_code = "2666" | |
}; | |
var json = JsonConvert.SerializeObject(Data); | |
var content = new StringContent(json, Encoding.UTF8, "application/json"); | |
var response = await httpClient.PostAsync(httpClient.BaseAddress, content); | |
return response; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment