StockSharp.Configuration is a .NET Standard library that centralizes various configuration facilities used by the StockSharp trading platform. It provides classes for storing application paths, loading settings, managing user credentials, and constructing message adapters.
The assembly is titled S#.Configuration and described as "Configuration components."
- System paths – the
Pathsclass defines all important directories and files used by StockSharp. Paths are initialized fromPathsHolderand configuration files, as shown below:【F:Configuration/Paths.cs†L14-L26】var companyPath = PathsHolder.CompanyPath ?? ConfigManager.TryGet<string>("companyPath"); CompanyPath = companyPath.IsEmpty() ? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "StockSharp") : companyPath.ToFullPathIfNeed(); CredentialsFile = Path.Combine(CompanyPath, $"credentials{DefaultSettingsExt}"); PlatformConfigurationFile = Path.Combine(AppDataPath, $"platform_config{DefaultSettingsExt}");
- Start‑up settings –
AppStartSettingsstores language preference and online/offline mode and can be loaded or saved from the platform configuration file:【F:Configuration/AppStartSettings.cs†L4-L41】public class AppStartSettings : IPersistable { public string Language { get; set; } = LocalizedStrings.ActiveLanguage; public bool Online { get; set; } = true; public static AppStartSettings TryLoad() { var configFile = Paths.PlatformConfigurationFile; if (configFile.IsEmptyOrWhiteSpace() || !configFile.IsConfigExists()) return null; return configFile.Deserialize<SettingsStorage>()?.Load<AppStartSettings>(); } }
- Credentials management – the
ICredentialsProviderinterface allows loading, saving and deleting ofServerCredentials. The default implementation persists credentials inPaths.CredentialsFile:【F:Configuration/ICredentialsProvider.cs†L4-L25】public interface ICredentialsProvider { bool TryLoad(out ServerCredentials credentials); void Save(ServerCredentials credentials, bool keepSecret); void Delete(); }
class DefaultCredentialsProvider : ICredentialsProvider {
-
}
private readonly Lock _lock = new(); private ServerCredentials _credentials; bool ICredentialsProvider.TryLoad(out ServerCredentials credentials) { using (_lock.EnterScope()) { if(_credentials != null) { credentials = _credentials.Clone(); return credentials.CanAutoLogin(); } var file = Paths.CredentialsFile; credentials = null; if (file.IsConfigExists()) { credentials = new ServerCredentials(); credentials.LoadIfNotNull(file.Deserialize<SettingsStorage>()); _credentials = credentials.Clone(); } return credentials?.CanAutoLogin() == true; } }【F:Configuration/DefaultCredentialsProvider.cs†L3-L38】 - Invariant serialization –
InvariantCultureSerializersaves configuration files using the invariant culture and UTF‑8 encoding, enabling culture‑independent settings:【F:Configuration/InvariantCultureSerializer.cs†L3-L23】public static class InvariantCultureSerializer { public static void SerializeInvariant(this SettingsStorage settings, string fileName, bool bom = true) { if (settings is null) throw new ArgumentNullException(nameof(settings)); Do.Invariant(() => settings.Serialize(fileName, bom)); } }
- Message adapter discovery –
InMemoryMessageAdapterProviderscans all local assemblies forIMessageAdapterimplementations and can create adapters on demand:【F:Configuration/InMemoryMessageAdapterProvider.cs†L5-L51】public class InMemoryMessageAdapterProvider : IMessageAdapterProvider { public InMemoryMessageAdapterProvider(IEnumerable<IMessageAdapter> currentAdapters, Type transportAdapter = null) { CurrentAdapters = currentAdapters ?? throw new ArgumentNullException(nameof(currentAdapters)); var idGenerator = new IncrementalIdGenerator(); PossibleAdapters = [.. GetAdapters().Select(t => { try { return t.CreateAdapter(idGenerator); } catch (Exception ex) { ex.LogError(); return null; } }).WhereNotNull()]; } }
- Utility helpers – the
Pathsclass also exposes methods for serialization, backup management and building links to StockSharp documentation and store pages.
- Configure global paths before accessing
Pathsby settingPathsHolder.CompanyPathandPathsHolder.AppDataPathif your application uses custom directories. - Load or create application start settings with
AppStartSettings.TryLoadand save them usingTrySave. - Implement
ICredentialsProvideror useDefaultCredentialsProviderto persist server credentials securely. - Use
InvariantCultureSerializerwhen you need stable serialization irrespective of system locale. - Create an instance of
InMemoryMessageAdapterProviderto dynamically discover available message adapters.