refactor: Add IDataStreamFactory(s) for spatial arb streams
This commit is contained in:
1 parent
256f7025a2
commit
6e1e5d4bbf
6 files changed
+132
-8
No files matched your search
@@ -13,10 +13,12 @@ public static class DataStreamCoreServices {
|
||||
services.AddSingleton<IPubTableBroker, PubTableBroker>();
|
||||
|
||||
public static IServiceCollection AddViewStreamDatabase(this IServiceCollection services) =>
|
||||
services.AddSingleton<IWorker, ViewStreamDatabase>(sp => {
|
||||
ViewStreamDatabase.SetGlobalInstance(new ViewStreamDatabase());
|
||||
return ViewStreamDatabase.instance;
|
||||
});
|
||||
services
|
||||
.AddSingleton(sp => {
|
||||
ViewStreamDatabase.SetGlobalInstance(new ViewStreamDatabase());
|
||||
return ViewStreamDatabase.instance;
|
||||
})
|
||||
.AddSingleton<IWorker, ViewStreamDatabase>(sp => sp.GetRequiredService<ViewStreamDatabase>());
|
||||
|
||||
public static IServiceCollection AddPrimitiveStreams(this IServiceCollection services, IConfiguration configurationSection) =>
|
||||
services.Configure<PrimitiveManagerConfig>(configurationSection)
|
||||
|
||||
+7
-3
@@ -8,9 +8,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// For all the pairs generated by SpatialFuturePairsStream, this stream
|
||||
// generates the statistics, by appending together a SpreadStatsStream
|
||||
/// This stream is now created by <see cref="Bts.SharedStreams.StreamFactories.SpatialArbStatsStreamFactory"/>
|
||||
/// <summary>
|
||||
/// For all the pairs generated by SpatialFuturePairsStream, this stream
|
||||
/// generates the statistics, by appending together a SpreadStatsStream.
|
||||
/// <para>
|
||||
/// This stream is now created by <see cref="Bts.SharedStreams.StreamFactories.SpatialArbStatsStreamFactory"/>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[DataStreamUserRespresentation(false)]
|
||||
public class SpatialArbStatsStream : ViewStream{
|
||||
private ViewStream _spatial_pairs_stream;
|
||||
|
||||
@@ -12,7 +12,9 @@ public static class SharedStreamsServices {
|
||||
public static IServiceCollection AddMarketDataStreams(this IServiceCollection services) =>
|
||||
services.addStreamFactory<BookStreamFactory>()
|
||||
.addStreamFactory<SpreadBookStreamFactory>()
|
||||
.addStreamFactory<InstrumentStreamFactory>();
|
||||
.addStreamFactory<InstrumentStreamFactory>()
|
||||
.addStreamFactory<SpatialFuturePairsStreamFactory>()
|
||||
.addStreamFactory<SpatialArbStatsStreamFactory>();
|
||||
|
||||
public static IServiceCollection AddNaturalLanguageStreams(this IServiceCollection services, IConfigurationSection configurationSection) {
|
||||
services.Configure<NLPromptConfig>(configurationSection);
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
namespace Bts.SharedStreams.StreamFactories;
|
||||
|
||||
using BCG;
|
||||
|
||||
using bts.BlueOrb;
|
||||
|
||||
using Bts.DataStreamCore;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
using Spark.Api.MarketData;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
class SpatialArbStatsStreamFactory : IDataStreamFactory {
|
||||
readonly IMarketDataClient marketDataClient;
|
||||
readonly ViewStreamDatabase viewStreamDatabase;
|
||||
readonly ILogger logger;
|
||||
|
||||
public SpatialArbStatsStreamFactory(IMarketDataClient marketDataClient, ViewStreamDatabase viewStreamDatabase, ILogger<SpatialArbStatsStreamFactory> logger) {
|
||||
this.marketDataClient = marketDataClient;
|
||||
this.viewStreamDatabase = viewStreamDatabase;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public ViewStream? Create(string streamId, IEnumerable<(string? Name, int? Index, object? Value)> args) {
|
||||
if (SupportedStreams.SpatialArbStats.IsMatch(streamId)) {
|
||||
return createSpatialArbStats(args);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public IEnumerable<IDataStreamMetadata> GetSupportedStreams() {
|
||||
yield return SupportedStreams.SpatialArbStats;
|
||||
}
|
||||
|
||||
ViewStream? createSpatialArbStats(IEnumerable<(string? Name, int? Index, object? Value)> args) {
|
||||
if (!StreamFactoryArgStore.TryGetParams(args, out SpatialArbStatsStreamParams? sassp, out var err)) {
|
||||
logger.LogInvalidParams("spatialArbStats", err);
|
||||
return null;
|
||||
}
|
||||
return new SpatialArbStatsStream(marketDataClient, sassp.WindowSize, sassp.SamplingInterval, viewStreamDatabase);
|
||||
}
|
||||
|
||||
static class SupportedStreams {
|
||||
public static readonly DataStreamMetadata SpatialArbStats = new() {
|
||||
Name = "spatialArbStats",
|
||||
AlternateNames = new() { "SpatialArbStatsStream" },
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace Bts.SharedStreams.StreamFactories;
|
||||
|
||||
using Bts.DataStreamCore;
|
||||
|
||||
public class SpatialArbStatsStreamParams {
|
||||
[StreamArgument(RegexNames = new[] { "^win(dow)?_?(Sz|Size)?" }, Position = 0, ParserType = typeof(TimeSpanOrSecondsParser))]
|
||||
public TimeSpan WindowSize { get; set; }
|
||||
|
||||
[StreamArgument(RegexNames = new[] { "^(sampling|sample|poll|polling)_?(Interval|Period|Size|Sz)" }, Position = 1, ParserType = typeof(TimeSpanOrSecondsParser))]
|
||||
public TimeSpan SamplingInterval { get; set; }
|
||||
|
||||
class TimeSpanOrSecondsParser : IStreamArgumentParser {
|
||||
public bool TryParse(string? name, string? valueStr, out object? result) {
|
||||
if (int.TryParse(valueStr, out var secs)) {
|
||||
result = TimeSpan.FromSeconds(secs);
|
||||
return true;
|
||||
}
|
||||
if (TimeSpan.TryParse(valueStr, out var ts)) {
|
||||
result = ts;
|
||||
return true;
|
||||
}
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
namespace Bts.SharedStreams.StreamFactories;
|
||||
|
||||
using BCG;
|
||||
|
||||
using bts.BlueOrb;
|
||||
|
||||
using Bts.DataStreamCore;
|
||||
|
||||
using Spark.Api.MarketData;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
class SpatialFuturePairsStreamFactory : IDataStreamFactory {
|
||||
readonly IMarketDataClient marketDataClient;
|
||||
|
||||
public SpatialFuturePairsStreamFactory(IMarketDataClient marketDataClient) =>
|
||||
this.marketDataClient = marketDataClient;
|
||||
|
||||
public ViewStream? Create(string streamId, IEnumerable<(string? Name, int? Index, object? Value)> args) {
|
||||
if (SupportedStreams.SpatialFuturePairs.IsMatch(streamId)) {
|
||||
return createSpatialFuturePairs(args);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public IEnumerable<IDataStreamMetadata> GetSupportedStreams() {
|
||||
yield return SupportedStreams.SpatialFuturePairs;
|
||||
}
|
||||
|
||||
ViewStream createSpatialFuturePairs(IEnumerable<(string? Name, int? Index, object? Value)> args) =>
|
||||
new SpatialFuturePairsStream(marketDataClient);
|
||||
|
||||
static class SupportedStreams {
|
||||
public static readonly DataStreamMetadata SpatialFuturePairs = new() {
|
||||
Name = "spatialFuturePairs",
|
||||
AlternateNames = new() { "SpatialFuturePairsStream" },
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user