feat(core): update DTOs, Trade Republic client, Yahoo scrapers, and dynamic settings
This commit is contained in:
@@ -3,7 +3,7 @@ using System.Collections.Concurrent;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FinlyticCore.Models.TradeRepublic;
|
||||
using FinlyticCore.Dtos.TradeRepublic;
|
||||
using FinlyticCore.Util;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@@ -165,46 +165,60 @@ public class TradeRepublicClient : ManagedWebSocket
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnMessageReceived(string message)
|
||||
protected override void OnMessageReceived(string message)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(message)) return;
|
||||
|
||||
_logger.LogDebug("[{Channel}] TR WS Recv: {Message}", "TradeRepublicChannel", message);
|
||||
|
||||
var trimmed = message.Trim();
|
||||
|
||||
int subId;
|
||||
string type;
|
||||
string payload;
|
||||
|
||||
_logger.LogDebug("Trade republic response: " + message);
|
||||
|
||||
if (trimmed.Equals("connected", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(message)) return;
|
||||
|
||||
_logger.LogDebug("[{Channel}] TR WS Recv: {Message}", "TradeRepublicChannel", message);
|
||||
|
||||
// Trade Republic message formats:
|
||||
// "34 connected" -> subId = 34, type = "connected", payload = "connected"
|
||||
// "22A {...}" or "22A{...}" -> subId = 22, type = "A", payload = "{...}"
|
||||
subId = -1;
|
||||
type = "connected";
|
||||
payload = trimmed;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ziffern am Anfang zählen (Sub-ID)
|
||||
var digitLen = 0;
|
||||
while (digitLen < message.Length && char.IsDigit(message[digitLen]))
|
||||
while (digitLen < trimmed.Length && char.IsDigit(trimmed[digitLen]))
|
||||
{
|
||||
digitLen++;
|
||||
}
|
||||
|
||||
// Keine Ziffer am Anfang (Reines System-Event/Error ohne ID)
|
||||
if (digitLen == 0)
|
||||
{
|
||||
SystemMessageReceived?.Invoke(message);
|
||||
SystemMessageReceived?.Invoke(trimmed);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!int.TryParse(message.Substring(0, digitLen), out var subId))
|
||||
if (!int.TryParse(trimmed.Substring(0, digitLen), out subId))
|
||||
{
|
||||
SystemMessageReceived?.Invoke(message);
|
||||
SystemMessageReceived?.Invoke(trimmed);
|
||||
return;
|
||||
}
|
||||
|
||||
var remainder = message.Substring(digitLen).TrimStart();
|
||||
string type;
|
||||
string payload;
|
||||
var remainder = trimmed.Substring(digitLen).TrimStart();
|
||||
|
||||
if (remainder.StartsWith("connected"))
|
||||
// 2. FALL: "34 connected" oder "34connected"
|
||||
if (remainder.StartsWith("connected", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
subId = -1; // Mapping auf deine interne -1 für InitAsync
|
||||
type = "connected";
|
||||
payload = remainder;
|
||||
}
|
||||
else if (remainder.Length > 0)
|
||||
{
|
||||
// Type is usually a single character like 'A' or 'E'
|
||||
// The JSON payload (or ack) starts immediately after or after a space
|
||||
// Standard Trade Republic Data Push (z.B. "22A {...}")
|
||||
type = remainder[0].ToString();
|
||||
payload = remainder.Substring(1).TrimStart();
|
||||
}
|
||||
@@ -213,21 +227,23 @@ public class TradeRepublicClient : ManagedWebSocket
|
||||
type = "ack";
|
||||
payload = string.Empty;
|
||||
}
|
||||
|
||||
var received = new ReceivedMessage(subId, type, payload);
|
||||
|
||||
if (_pendingRequests.TryGetValue(subId, out var tcs))
|
||||
{
|
||||
tcs.TrySetResult(received);
|
||||
}
|
||||
|
||||
if (_tickerSubscriptions.TryGetValue(subId, out var handler))
|
||||
{
|
||||
handler(payload);
|
||||
}
|
||||
|
||||
UnhandledMessageReceived?.Invoke(received);
|
||||
}
|
||||
|
||||
var received = new ReceivedMessage(subId, type, payload);
|
||||
|
||||
// Löst jetzt garantiert dein TaskCompletionSource(-1) in InitAsync auf!
|
||||
if (_pendingRequests.TryGetValue(subId, out var tcs))
|
||||
{
|
||||
tcs.TrySetResult(received);
|
||||
}
|
||||
|
||||
if (_tickerSubscriptions.TryGetValue(subId, out var handler))
|
||||
{
|
||||
handler(payload);
|
||||
}
|
||||
|
||||
UnhandledMessageReceived?.Invoke(received);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user