Skip to content

Commit fcd6cfb

Browse files
committed
endpoint name improvments
1 parent 809fc80 commit fcd6cfb

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

data-api/csharp-ws/CoinAPI.WebSocket.Stats.Console/Program.cs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static async Task Main(string[] args)
8080
await coconaApp.RunAsync<Program>();
8181
}
8282

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

94-
string endpointUri = null;
95-
if (!string.IsNullOrWhiteSpace(endpoint_name))
94+
// the user provided endpoint
95+
if (Enum.GetNames<Endpoints>().ToList().Any(x => x == endpoint_name))
9696
{
97-
// the user provided endpoint
98-
if (Enum.GetNames<Endpoints>().ToList().Any(x => x == endpoint_name))
99-
{
100-
// it's site name
101-
endpointUri = Endpoints[endpoint_name];
102-
}
103-
else if (endpoint_name.StartsWith("ws://") || !endpoint_name.StartsWith("wss://"))
104-
{
105-
// its uri
106-
endpointUri = endpoint_name;
107-
}
108-
else
109-
{
110-
// eveyrhting else is invalid
111-
Serilog.Log.Error($"Invalid endpoint_name, valid values: {string.Join(",", Enum.GetNames<Endpoints>().ToList())} or ws:// or wss:// uri");
112-
return;
113-
}
97+
// it's site name translate
98+
endpoint_name = Endpoints[endpoint_name];
99+
}
100+
else if (endpoint_name.StartsWith("ws://") || endpoint_name.StartsWith("wss://"))
101+
{
102+
// its uri OK
103+
}
104+
else
105+
{
106+
// eveyrhting else is invalid
107+
Serilog.Log.Error($"Invalid endpoint_name, valid values: {string.Join(",", Enum.GetNames<Endpoints>().ToList())} or ws:// or wss:// uri");
108+
return;
114109
}
115110

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

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

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

@@ -234,7 +228,7 @@ void ProcessMsg(DateTime? time_exchange, DateTime? time_coinapi)
234228

235229
if (iterations % 10 == 0)
236230
{
237-
Serilog.Log.Information($"Endpoint {endpoint}, {iterations} iterations, {msgCount} messages received, {wsClient.TotalBytesReceived} bytes received, Error count {errorCount}");
231+
Serilog.Log.Information($"Endpoint {endpoint_name}, {iterations} iterations, {msgCount} messages received, {wsClient.TotalBytesReceived} bytes received, Error count {errorCount}");
238232
}
239233
iterations++;
240234

data-api/csharp-ws/CoinAPI.WebSocket.Stats.Console/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ dotnet run -- [options]
5454

5555
### Options
5656

57-
- `--endpoint_name <NAME>`: The name of the endpoint (emea, apac, ncsa). Default is the global endpoint.
57+
- `--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.
5858
- `--subscribe_data_type <TYPE>`: The type of data to subscribe to (e.g., book5, book20, quote, trade). Required.
5959
- `--asset <ASSET>`: The asset identifier to filter data by. Optional.
6060
- `--symbol <SYMBOL>`: The symbol identifier to filter data by. Optional.

0 commit comments

Comments
 (0)