Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 31 additions & 28 deletions src/ExchangeSharp/API/Exchanges/Digifinex/ExchangeDigifinexAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ public partial class ExchangeDigifinexAPI : ExchangeAPI
private string[] Urls =
{
"openapi.digifinex.com",
"openapi.digifinex.vip",
"openapi.digifinex.vip", // these other URLs don't work anymore
"openapi.digifinex.xyz",
};

private string fastestUrl = null;
private int failedUrlCount;
private int successUrlCount;

public override string BaseUrl { get; set; } = "https://openapi.digifinex.vip/v3";
public override string BaseUrlWebSocket { get; set; } = "wss://openapi.digifinex.vip/ws/v1/";
public override string BaseUrl { get; set; } = "https://openapi.digifinex.com/v3";
public override string BaseUrlWebSocket { get; set; } = "wss://openapi.digifinex.com/ws/v1/";
private int websocketMessageId = 0;
private string timeWindow;
private TaskCompletionSource<int> inited = new TaskCompletionSource<int>();
Expand All @@ -40,30 +40,31 @@ private ExchangeDigifinexAPI()
}

private void GetFastestUrl()
{
var client = new HttpClient();
foreach (var url in Urls)
{
var u = url;
client.GetAsync($"https://{u}").ContinueWith((t) =>
{
if (t.Exception != null)
{
var count = Interlocked.Increment(ref failedUrlCount);
if (count == Urls.Length)
inited.SetException(new APIException("All digifinex URLs failed."));
return;
}
if (Interlocked.Increment(ref successUrlCount) == 1)
{
fastestUrl = u;
//Console.WriteLine($"Fastest url {GetHashCode()}: {u}");
BaseUrl = $"https://{u}/v3";
BaseUrlWebSocket = $"wss://{u}/ws/v1/";
inited.SetResult(1);
}
});
}
{
//var client = new HttpClient();
//foreach (var url in Urls)
//{
// var u = url;
// client.GetAsync($"https://{u}").ContinueWith((t) =>
// {
// if (t.Exception != null)
// {
// var count = Interlocked.Increment(ref failedUrlCount);
// if (count == Urls.Length)
// inited.SetException(new APIException("All digifinex URLs failed."));
// return;
// }
// if (Interlocked.Increment(ref successUrlCount) == 1)
// {
// fastestUrl = u;
// //Console.WriteLine($"Fastest url {GetHashCode()}: {u}");
// BaseUrl = $"https://{u}/v3";
// BaseUrlWebSocket = $"wss://{u}/ws/v1/";
// inited.SetResult(1);
// }
// });
//}
inited.SetResult(1);
}

#region ProcessRequest
Expand Down Expand Up @@ -463,7 +464,8 @@ protected override async Task<IWebSocket> OnGetTradesWebSocketAsync(Func<KeyValu
}
else if (marketSymbols == null || marketSymbols.Length == 0)
{
marketSymbols = (await GetMarketSymbolsAsync()).ToArray();
marketSymbols = (await GetMarketSymbolsAsync()).Take(30).ToArray();
Logger.Warn("subscribing to the first 30 symbols");
}
return await ConnectPublicWebSocketAsync(string.Empty, async (_socket, msg) =>
{
Expand All @@ -486,6 +488,7 @@ protected override async Task<IWebSocket> OnGetTradesWebSocketAsync(Func<KeyValu
// "id": null
// }
JToken token = JToken.Parse(CryptoUtility.DecompressDeflate((new ArraySegment<byte>(msg, 2, msg.Length - 2)).ToArray()).ToStringFromUTF8());
// doesn't send error msgs - just disconnects
if (token["method"].ToStringLowerInvariant() == "trades.update")
{
var args = token["params"];
Expand Down