Every notice is written to the queue in the same transaction as what it tells, then sent every ten seconds. Each has a state: pending, sent, or failed with its error. Network failures and 429s are retried with growing pauses (Telegram's own wait when it gives one). Refusals are final. A notice that could not leave within a day is given up instead of arriving late. Every fill now also reaches the phone, and so do pause, resume and restart. Commands are read by long polling and obeyed only from the configured chat and only when fresh, so yesterday's /pausa never pauses today. They are /stato, /posizioni, /oggi, /pausa, /riprendi, /ferma (confirmed with /conferma within two minutes) and /aiuto. Restarting after "Ferma tutto", real money, limits and keys stay in the interface. Also added: - the heartbeat call every minute when an address is configured; - the morning summary at 08:00, caught up within four hours; - an optional hourly or evening status; - a Telegram section in Impostazioni: test-before-save, a test button, the queue's state and the last successful heartbeat; - on desktop, the first-run page recommends the heartbeat. Tests run against a fake Telegram server, including the commands through the real server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
3.4 KiB
C#
85 lines
3.4 KiB
C#
using Anubis.Core;
|
|
using Anubis.Platform;
|
|
|
|
namespace Anubis.Server;
|
|
|
|
/// <summary>
|
|
/// What the server process was asked to be, from its arguments and environment: Docker or desktop, which data
|
|
/// folder, demo mode. Tests pass a fake environment and clock through <see cref="ServerOverrides"/>.
|
|
/// </summary>
|
|
internal sealed record ServerOptions(PlatformKind Platform, string? DataDir, bool Demo, string[] AspNetArgs)
|
|
{
|
|
public static ServerOptions Parse(string[] args, IReadOnlyDictionary<string, string?> environment)
|
|
{
|
|
var rest = new List<string>();
|
|
PlatformKind? platform = null;
|
|
string? dataDir = null;
|
|
var demo = false;
|
|
for (var i = 0; i < args.Length; i++)
|
|
{
|
|
switch (args[i])
|
|
{
|
|
case "--platform" when i + 1 < args.Length:
|
|
platform = args[++i].Equals("docker", StringComparison.OrdinalIgnoreCase) ? PlatformKind.Docker : PlatformKind.Desktop;
|
|
break;
|
|
case "--data-dir" when i + 1 < args.Length:
|
|
dataDir = Path.GetFullPath(args[++i]);
|
|
break;
|
|
case "--demo":
|
|
demo = true;
|
|
break;
|
|
default:
|
|
rest.Add(args[i]);
|
|
break;
|
|
}
|
|
}
|
|
|
|
platform ??= (environment.GetValueOrDefault("ANUBIS_PLATFORM") ?? "").ToLowerInvariant() switch
|
|
{
|
|
"docker" => PlatformKind.Docker,
|
|
"desktop" => PlatformKind.Desktop,
|
|
_ => environment.GetValueOrDefault("DOTNET_RUNNING_IN_CONTAINER") == "true" ? PlatformKind.Docker : PlatformKind.Desktop,
|
|
};
|
|
return new ServerOptions(platform.Value, dataDir, demo, [.. rest]);
|
|
}
|
|
|
|
/// <summary>Reads the startup configuration of the chosen platform.</summary>
|
|
public StartupConfig LoadConfig(IReadOnlyDictionary<string, string?> environment)
|
|
{
|
|
if (Platform == PlatformKind.Docker)
|
|
{
|
|
return DockerPlatform.Load(environment, DataDir ?? "/data");
|
|
}
|
|
|
|
var data = DataDir is null ? DataDirectory.ForCurrentUser() : new DataDirectory(DataDir);
|
|
return DesktopPlatform.Load(data, ProtectedSecretKey.DefaultStore(data));
|
|
}
|
|
}
|
|
|
|
/// <summary>Test hooks: a fake environment, a manual clock, a cheaper password hash.</summary>
|
|
internal sealed record ServerOverrides
|
|
{
|
|
public IReadOnlyDictionary<string, string?>? Environment { get; init; }
|
|
|
|
public IClock? Clock { get; init; }
|
|
|
|
public int? PasswordIterations { get; init; }
|
|
|
|
/// <summary>How often the database is checked while running and retried while it is missing.</summary>
|
|
public TimeSpan? DatabaseCheckInterval { get; init; }
|
|
|
|
/// <summary>False turns market data off (tests without network); null follows demo mode and ANUBIS_MARKET_DATA.</summary>
|
|
public bool? MarketData { get; init; }
|
|
|
|
/// <summary>Answers the market data requests instead of the network (tests).</summary>
|
|
public HttpMessageHandler? MarketHttp { get; init; }
|
|
|
|
public Func<Anubis.Brokers.IWebSocketTransport>? MarketSockets { get; init; }
|
|
|
|
/// <summary>Answers the Telegram calls and the sign of life instead of the network; tests without it have no Telegram.</summary>
|
|
public HttpMessageHandler? TelegramHttp { get; init; }
|
|
|
|
/// <summary>True starts the accounts and the order managers in a test; off by default in tests.</summary>
|
|
public bool? Trading { get; init; }
|
|
}
|