Skip to content

Commit

Permalink
endpoint name improvments
Browse files Browse the repository at this point in the history
  • Loading branch information
Svisstack committed Mar 28, 2024
1 parent d88237b commit 987f852
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
40 changes: 17 additions & 23 deletions data-api/csharp-ws/CoinAPI.WebSocket.Stats.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static async Task Main(string[] args)
await coconaApp.RunAsync<Program>();
}

public async Task MakeRequest([FromService] IConfiguration configuration, string endpoint_name = null,
public async Task MakeRequest([FromService] IConfiguration configuration, string endpoint_name = "wss://ws.coinapi.io/",
string subscribe_data_type = null, string asset = null, string symbol = null,
string exchange = null, string apikey = null, string type = "hello", bool supress_hb = false, string latency_type = "ce")
{
Expand All @@ -91,26 +91,21 @@ public async Task MakeRequest([FromService] IConfiguration configuration, string
return;
}

string endpointUri = null;
if (!string.IsNullOrWhiteSpace(endpoint_name))
// the user provided endpoint
if (Enum.GetNames<Endpoints>().ToList().Any(x => x == endpoint_name))
{
// the user provided endpoint
if (Enum.GetNames<Endpoints>().ToList().Any(x => x == endpoint_name))
{
// it's site name
endpointUri = Endpoints[endpoint_name];
}
else if (endpoint_name.StartsWith("ws://") || !endpoint_name.StartsWith("wss://"))
{
// its uri
endpointUri = endpoint_name;
}
else
{
// eveyrhting else is invalid
Serilog.Log.Error($"Invalid endpoint_name, valid values: {string.Join(",", Enum.GetNames<Endpoints>().ToList())} or ws:// or wss:// uri");
return;
}
// it's site name translate
endpoint_name = Endpoints[endpoint_name];
}
else if (endpoint_name.StartsWith("ws://") || endpoint_name.StartsWith("wss://"))
{
// its uri OK
}
else
{
// eveyrhting else is invalid
Serilog.Log.Error($"Invalid endpoint_name, valid values: {string.Join(",", Enum.GetNames<Endpoints>().ToList())} or ws:// or wss:// uri");
return;
}

var latencyTypes = Enum.GetNames<LatencyType>().ToList();
Expand All @@ -120,7 +115,7 @@ public async Task MakeRequest([FromService] IConfiguration configuration, string
return;
}

using (var wsClient = endpointUri == null ? new CoinApiWsClient() : new CoinApiWsClient(endpointUri))
using (var wsClient = new CoinApiWsClient(endpoint_name))
{
wsClient.SupressHeartbeat(supress_hb);
int msgCount = 0;
Expand Down Expand Up @@ -204,7 +199,6 @@ void ProcessMsg(DateTime? time_exchange, DateTime? time_coinapi)
if (!wsClient.ConnectedEvent.WaitOne(10000)) return;

var iterations = 0;
var endpoint = (string.IsNullOrEmpty(endpoint_name) ? "global" : Endpoints[endpoint_name]);
Serilog.Log.Information($"Time: {DateTime.UtcNow}");
var strbld = new StringBuilder();

Expand Down Expand Up @@ -234,7 +228,7 @@ void ProcessMsg(DateTime? time_exchange, DateTime? time_coinapi)

if (iterations % 10 == 0)
{
Serilog.Log.Information($"Endpoint {endpoint}, {iterations} iterations, {msgCount} messages received, {wsClient.TotalBytesReceived} bytes received, Error count {errorCount}");
Serilog.Log.Information($"Endpoint {endpoint_name}, {iterations} iterations, {msgCount} messages received, {wsClient.TotalBytesReceived} bytes received, Error count {errorCount}");
}
iterations++;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ dotnet run -- [options]

### Options

- `--endpoint_name <NAME>`: The name of the endpoint (emea, apac, ncsa). Default is the global endpoint.
- `--endpoint_name <NAME>`: The name of the endpoint (emea, apac, ncsa) or the uri like wss://ws.coinapi.io or ws://ws.coinapi.io etc. Default is the GeoDNS endpoint.
- `--subscribe_data_type <TYPE>`: The type of data to subscribe to (e.g., book5, book20, quote, trade). Required.
- `--asset <ASSET>`: The asset identifier to filter data by. Optional.
- `--symbol <SYMBOL>`: The symbol identifier to filter data by. Optional.
Expand Down

0 comments on commit 987f852

Please sign in to comment.