DataFeed-Producer

This commit is contained in:
Michael Schimmel
2025-12-09 11:12:56 +01:00
parent e56bf7ee7d
commit 43afbd6050
2 changed files with 34 additions and 34 deletions
+5 -5
View File
@@ -114,7 +114,7 @@ type
FProcessDone: TState;
FApplication: IAuraApplication;
FModulesItem: TTreeViewItem;
FTickerServer: IScalarBatchServer;
FFeed: IScalarRecordFeed;
function SelectedSymbol: String;
procedure ExecuteStrategy(const Symbol: String; Timeframe: TTimeframe; const Consumer: IConsumer<TDataPoint<TOhlcItem>>);
@@ -382,11 +382,11 @@ begin
var terminated := TFlag.CreateObserver(FTerminate.Signal).State;
var path := '\\COFFEE\TickData\Pepperstone'; // Or FServer.Path if compatible
FTickerServer := TScalarBatchServer.Create(path, '.m1', true, def) as IScalarBatchServer;
FFeed := TScalarRecordFeed.Create(path, '.m1', true, def);
// Converter: Transforms raw IRecordSeries (Columns) into TArray<TDataPoint>
var ticker :=
FTickerServer.Ticker.Chain<TDataPoint<Double>>(
FFeed.Ticker.Chain<TDataPoint<Double>>(
function(const Tick: IScalarRecord): TDataPoint<Double>
begin
Result.Time := Tick.ItemByIndex(iTime).Value.AsDouble;
@@ -404,7 +404,7 @@ begin
TAlphaColors.Orange
);
FTickerServer.SetImportOptions(
FFeed.SetImportOptions(
SizeOf(TM1FileItem),
procedure(const Src: Pointer; Dst: TScalar.PValue)
var
@@ -428,7 +428,7 @@ begin
);
// Connect pipeline: Server -> Converter
FProcessDone := FTickerServer.ProcessData(symbol, terminated);
FProcessDone := FFeed.ProcessData(symbol, terminated);
end;
function TForm1.CreateStrategy2(Timeframe: TTimeframe): IConsumer<TDataPoint<TOhlcItem>>;
+29 -29
View File
@@ -14,7 +14,7 @@ uses
Myc.Data.Scalar,
Myc.Data.Keyword,
Myc.Data.Pipeline,
Myc.Data.Pipeline.Impl, // Added for TMycContainedProducer
Myc.Data.Pipeline.Impl,
Myc.Core.FileCache;
type
@@ -31,7 +31,7 @@ type
property Items[const Key: IKeyword]: TScalar read GetItems; default;
end;
IScalarBatchServer = interface
IScalarRecordFeed = interface
procedure ClearCache;
procedure SetImportOptions(RecordSize: Integer; const Converter: TImportConverter);
function EnumerateSymbols: TFuture<TArray<String>>;
@@ -43,7 +43,7 @@ type
property Ticker: TProducer<IScalarRecord> read GetTicker;
end;
TScalarBatchServer = class(TInterfacedObject, IScalarBatchServer)
TScalarRecordFeed = class(TInterfacedObject, IScalarRecordFeed)
public
type
TBatch = record
@@ -197,9 +197,9 @@ begin
Result.Create(FDef.Fields[Idx].Value, TScalar.PValue(NativeUInt(FData) + NativeUInt(idx * SizeOf(TScalar.TValue)))^);
end;
{ TScalarBatchServer.TDataFile }
{ TScalarRecordFeed.TDataFile }
constructor TScalarBatchServer.TDataFile.Create(const APath, ASymbol, AExtension: String; AYear, AMonth: Integer; const ABasename: String);
constructor TScalarRecordFeed.TDataFile.Create(const APath, ASymbol, AExtension: String; AYear, AMonth: Integer; const ABasename: String);
begin
FPath := APath;
FSymbol := ASymbol;
@@ -209,24 +209,24 @@ begin
FBasename := ABasename;
end;
function TScalarBatchServer.TDataFile.GetBaseFileName: string;
function TScalarRecordFeed.TDataFile.GetBaseFileName: string;
begin
Result := FBasename;
end;
function TScalarBatchServer.TDataFile.GetFullFileName: string;
function TScalarRecordFeed.TDataFile.GetFullFileName: string;
begin
Result := TPath.Combine(FPath, GetBaseFileName + FExtension);
end;
function TScalarBatchServer.TDataFile.GetIsValid: Boolean;
function TScalarRecordFeed.TDataFile.GetIsValid: Boolean;
begin
Result := (FSymbol <> '') and (FYear > 0);
end;
{ TScalarBatchServer }
{ TScalarRecordFeed }
constructor TScalarBatchServer.Create(
constructor TScalarRecordFeed.Create(
const APath: String;
const AExtension: String;
IsCompressed: Boolean;
@@ -249,43 +249,43 @@ begin
.Create(function(const Filename: String): TFuture<TArray<TBatch>> begin Result := DoLoad(Filename, FLoadGate); end);
end;
destructor TScalarBatchServer.Destroy;
destructor TScalarRecordFeed.Destroy;
begin
ClearCache;
FTicker.Free;
FCachedFiles.Free;
FTicker.Free;
inherited Destroy;
end;
procedure TScalarBatchServer.AfterConstruction;
procedure TScalarRecordFeed.AfterConstruction;
begin
inherited;
UpdateSymbols;
end;
procedure TScalarBatchServer.ClearCache;
procedure TScalarRecordFeed.ClearCache;
begin
FCachedFiles.Clear;
end;
procedure TScalarBatchServer.SetImportOptions(RecordSize: Integer; const Converter: TImportConverter);
procedure TScalarRecordFeed.SetImportOptions(RecordSize: Integer; const Converter: TImportConverter);
begin
FImportRecordSize := RecordSize;
FImportConverter := Converter;
ClearCache;
end;
function TScalarBatchServer.GetPath: String;
function TScalarRecordFeed.GetPath: String;
begin
Result := FPath;
end;
function TScalarBatchServer.GetTicker: TProducer<IScalarRecord>;
function TScalarRecordFeed.GetTicker: TProducer<IScalarRecord>;
begin
Result := FTicker;
end;
procedure TScalarBatchServer.UpdateSymbols;
procedure TScalarRecordFeed.UpdateSymbols;
begin
FSymbols :=
TFuture<TDictionary<String, TArray<TDataFile>>>.Construct(
@@ -346,7 +346,7 @@ begin
FSymbols.Manage;
end;
function TScalarBatchServer.EnumerateSymbols: TFuture<TArray<String>>;
function TScalarRecordFeed.EnumerateSymbols: TFuture<TArray<String>>;
begin
Result :=
FSymbols.Chain<TArray<String>>(
@@ -354,7 +354,7 @@ begin
);
end;
function TScalarBatchServer.FindFirstFile(const Symbol: string): TFuture<TDataFile>;
function TScalarRecordFeed.FindFirstFile(const Symbol: string): TFuture<TDataFile>;
begin
var symName := Symbol;
Result :=
@@ -371,7 +371,7 @@ begin
);
end;
function TScalarBatchServer.GetNextFile(const Curr: TDataFile): TDataFile;
function TScalarRecordFeed.GetNextFile(const Curr: TDataFile): TDataFile;
var
allSymbolFiles: TArray<TDataFile>;
foundIndex: Integer;
@@ -399,7 +399,7 @@ begin
end;
end;
function TScalarBatchServer.ParseFileName(const FileName: string): TDataFile;
function TScalarRecordFeed.ParseFileName(const FileName: string): TDataFile;
var
path, fileNameNoPath, baseName, ext, symbol: string;
year, month: Integer;
@@ -440,7 +440,7 @@ begin
Result := TDataFile.Create(path, symbol, ext, year, month, baseName);
end;
function TScalarBatchServer.LoadDataFile(const DataFile: TDataFile): TFuture<TArray<TBatch>>;
function TScalarRecordFeed.LoadDataFile(const DataFile: TDataFile): TFuture<TArray<TBatch>>;
begin
if DataFile.IsValid then
Result := FCachedFiles.GetOrAdd(DataFile.GetFullFileName)
@@ -448,7 +448,7 @@ begin
Result := TFuture<TArray<TBatch>>.Construct(TArray<TBatch>(nil));
end;
function TScalarBatchServer.DoLoad(const FileName: string; const Gate: TLatch): TFuture<TArray<TBatch>>;
function TScalarRecordFeed.DoLoad(const FileName: string; const Gate: TLatch): TFuture<TArray<TBatch>>;
begin
Result := TFuture<TArray<TBatch>>.Null;
if not TFile.Exists(FileName) then
@@ -490,7 +490,7 @@ begin
end;
end;
function TScalarBatchServer.ReadCompressedData(const InputStream: TStream): TArray<TBatch>;
function TScalarRecordFeed.ReadCompressedData(const InputStream: TStream): TArray<TBatch>;
var
decompressionStream: TStream;
localHeader: TZipHeader;
@@ -536,7 +536,7 @@ begin
end;
end;
function TScalarBatchServer.ReadUncompressedData(const InputStream: TStream): TArray<TBatch>;
function TScalarRecordFeed.ReadUncompressedData(const InputStream: TStream): TArray<TBatch>;
var
fileSize, totalRecords: Int64;
fieldsPerRecord: Integer;
@@ -605,7 +605,7 @@ begin
end;
end;
function TScalarBatchServer.ProcessData(const Symbol: String; const Terminated: TState): TState;
function TScalarRecordFeed.ProcessData(const Symbol: String; const Terminated: TState): TState;
begin
var cTerminated := Terminated;
@@ -618,7 +618,7 @@ begin
end);
end;
function TScalarBatchServer.ProcessFile(FileInfo: TDataFile; const DataFile: TFuture<TArray<TBatch>>; const Terminated: TState): TState;
function TScalarRecordFeed.ProcessFile(FileInfo: TDataFile; const DataFile: TFuture<TArray<TBatch>>; const Terminated: TState): TState;
begin
if not FileInfo.IsValid or Terminated.IsSet then
exit(DataFile.Done);
@@ -638,7 +638,7 @@ begin
);
end;
function TScalarBatchServer.ProcessChunks(const Batches: TArray<TBatch>; Terminated: TState): TState;
function TScalarRecordFeed.ProcessChunks(const Batches: TArray<TBatch>; Terminated: TState): TState;
begin
var callProcess :=
function(Idx: Integer): TFunc<TState>