Skip to content

Commit 809fc80

Browse files
committed
allow set endpoints directly
1 parent 8b37350 commit 809fc80

File tree

1 file changed

+21
-5
lines changed
  • data-api/csharp-ws/CoinAPI.WebSocket.Stats.Console

1 file changed

+21
-5
lines changed

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,36 @@ public async Task MakeRequest([FromService] IConfiguration configuration, string
9191
return;
9292
}
9393

94-
var endpointNames = Enum.GetNames<Endpoints>().ToList();
95-
if (!string.IsNullOrWhiteSpace(endpoint_name) && !endpointNames.Any(x => x == endpoint_name))
94+
string endpointUri = null;
95+
if (!string.IsNullOrWhiteSpace(endpoint_name))
9696
{
97-
Serilog.Log.Error($"Invalid endpoint_name, valid values: {string.Join(",", endpointNames)}");
98-
return;
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+
}
99114
}
115+
100116
var latencyTypes = Enum.GetNames<LatencyType>().ToList();
101117
if (!string.IsNullOrWhiteSpace(latency_type) && !latencyTypes.Any(x => x == latency_type))
102118
{
103119
Serilog.Log.Error($"Invalid latency_type, valid values: {string.Join(",", latencyTypes)}");
104120
return;
105121
}
106122

107-
using (var wsClient = string.IsNullOrWhiteSpace(endpoint_name) ? new CoinApiWsClient() : new CoinApiWsClient(Endpoints[endpoint_name]))
123+
using (var wsClient = endpointUri == null ? new CoinApiWsClient() : new CoinApiWsClient(endpointUri))
108124
{
109125
wsClient.SupressHeartbeat(supress_hb);
110126
int msgCount = 0;

0 commit comments

Comments
 (0)