Files
StockSharp/Configuration/SubscriptionConfig.cs
mika@stocksharp.com 6e7a7dae22 Move instrument lookups and persistence to async
Instrument lookups, configuration, credentials, CSV entities, snapshots and
the alert processing service are read and written asynchronously; the
blocking synchronous forms are obsolete wrappers.

IAsyncPersistable replaces IPersistable: every type that saves and loads its
settings has LoadAsync and SaveAsync only, and nested objects are read with
GetValueAsync, LoadEntireAsync and LoadAllAsync. The synchronous Load and Save
are the obsolete Ecng extensions. The MultiConnect sample keeps IPersistable
for two settings classes, because the settings window of the published
StockSharp.Xaml package takes it.

Copies that were made by saving and loading are made asynchronously.
IMessageAdapter, IIndicator, the risk, commission, PnL, latency, slippage and
position managers, IStorageBuffer, Strategy, DiagramElement, ICompositionModel
and its nodes get CloneAsync and no longer implement ICloneable; Clone is an
obsolete blocking wrapper. A strategy copy keeps every security and portfolio
parameter the original holds. Messages, FieldMapping, BankDetails and
WithdrawInfo are copied in memory. A CommissionRuleMessage shares its rule and
the emulator takes a copy of it. Envelope gets a constructor that takes all
three lines and CreateAsync.

ToBruteForce and ToBruteForceRandom become ToBruteForceAsync and
ToBruteForceRandomAsync and return IAsyncEnumerable; BruteForceOptimizer runs
over it and takes the next strategy through an asynchronous delegate.

Diagram elements keep their own state in SaveState, OnLoading and LoadState.
Undo restores an in-memory snapshot; a chart element holds its series and
axes in it by reference. An alert rule keeps its value in the form a message
carries it. A diagram strategy applies composition settings that were loaded
before the composition was set in SetCompositionAsync or at the start, and
saves them while they wait.

Strategies get an OnStartedAsync hook; diagram strategies resolve securities,
underlyings and strikes before the start so value processing never looks up
instruments. Paths.Serialize, SerializeInvariant, AppStartSettings.TrySave,
ICredentialsProvider.Save, ISnapshotSerializer.Serialize and the composition
registry gain async forms.

ICredentialsProvider.Delete becomes DeleteAsync, so loading, saving and
deleting the credentials wait for one another. Paths.InstalledVersion and
AppNameWithVersion are obsolete in favour of GetInstalledVersionAsync and
GetAppNameWithVersionAsync.

A file is opened for writing only after the last cancellation check, because
opening it empties it; a cancelled read reports the cancellation instead of
an empty result. A snapshot flush that failed leaves what it took due for the
next one.

The indicator templates for C#, F# and Python override LoadAsync and
SaveAsync.
2026-10-04 11:28:17 +03:00

94 lines
2.8 KiB
C#

namespace StockSharp.Configuration;
/// <summary>
/// Represents a persisted market data subscription configuration.
/// </summary>
public record SubscriptionConfig : IAsyncPersistable
{
/// <summary>
/// <see cref="SecurityId"/>
/// </summary>
public SecurityId? Security { get; set; }
/// <summary>
/// Market data type identifier (for example: Level1, MarketDepth, Trades, Candles).
/// </summary>
public DataType DataType { get; set; }
/// <summary>
/// Build mode for derived data (when data needs to be built from another source).
/// </summary>
public MarketDataBuildModes? BuildMode { get; set; }
/// <summary>
/// Source data type used to build the requested data (e.g., build candles from trades).
/// </summary>
public DataType BuildFrom { get; set; }
/// <summary>
/// Field used during building (for example, a price or volume field name).
/// </summary>
public Level1Fields? BuildField { get; set; }
/// <summary>
/// Optional start time (UTC) of the requested data interval.
/// </summary>
public DateTime? From { get; set; }
/// <summary>
/// Optional end time (UTC) of the requested data interval.
/// </summary>
public DateTime? To { get; set; }
/// <summary>
/// Optional maximum number of data items to request.
/// </summary>
public long? Count { get; set; }
/// <summary>
/// Optional maximum depth for order book data.
/// </summary>
public int? MaxDepth { get; set; }
Task IAsyncPersistable.LoadAsync(SettingsStorage storage, CancellationToken cancellationToken)
{
DataType load(string name)
{
var str = storage.GetValue<string>(name);
if (str.IsEmpty())
return null;
return DataType.FromSerializableString(str);
}
Security = storage.GetValue<string>(nameof(Security))?.ToSecurityId();
DataType = load(nameof(DataType));
BuildMode = storage.GetValue<MarketDataBuildModes?>(nameof(BuildMode));
BuildFrom = load(nameof(BuildFrom));
BuildField = storage.GetValue<Level1Fields?>(nameof(BuildField));
From = storage.GetValue<long?>(nameof(From))?.To<DateTime>().UtcKind();
To = storage.GetValue<long?>(nameof(To))?.To<DateTime>().UtcKind();
Count = storage.GetValue<long?>(nameof(Count));
MaxDepth = storage.GetValue<int?>(nameof(MaxDepth));
return Task.CompletedTask;
}
Task IAsyncPersistable.SaveAsync(SettingsStorage storage, CancellationToken cancellationToken)
{
storage
.Set(nameof(Security), Security?.ToStringId())
.Set(nameof(DataType), DataType?.ToSerializableString())
.Set(nameof(BuildMode), BuildMode)
.Set(nameof(BuildFrom), BuildFrom?.ToSerializableString())
.Set(nameof(BuildField), BuildField)
.Set(nameof(From), From?.To<long>())
.Set(nameof(To), To?.To<long>())
.Set(nameof(Count), Count)
.Set(nameof(MaxDepth), MaxDepth)
;
return Task.CompletedTask;
}
}