DataFeed Refactoring
This commit is contained in:
+36
-28
@@ -115,8 +115,8 @@ type
|
||||
FProcessDone: TState;
|
||||
FApplication: IAuraApplication;
|
||||
FModulesItem: TTreeViewItem;
|
||||
FFileCache: IDataFileCache<TArray<TScalarRecordFeed.TBatch>>;
|
||||
FFeed: IScalarRecordFeed;
|
||||
FFileCache: IDataFileCache<TArray<TScalarBatch>>;
|
||||
FFeed: IScalarBatchLoader;
|
||||
function SelectedSymbol: String;
|
||||
procedure ExecuteStrategy(const Symbol: String; Timeframe: TTimeframe; const Consumer: IConsumer<TDataPoint<TOhlcItem>>);
|
||||
|
||||
@@ -197,7 +197,7 @@ procedure TForm1.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FApplication := TMycAuraApplication.Create;
|
||||
|
||||
FFileCache := TDataFileCache<TArray<TScalarRecordFeed.TBatch>>.Create;
|
||||
FFileCache := TDataFileCache<TArray<TScalarBatch>>.Create;
|
||||
|
||||
FModulesItem := TTreeViewItem.Create(Self);
|
||||
FModulesItem.Text := 'Modules';
|
||||
@@ -386,11 +386,40 @@ begin
|
||||
var terminated := TFlag.CreateObserver(FTerminate.Signal).State;
|
||||
var path := '\\COFFEE\TickData\Pepperstone'; // Or FServer.Path if compatible
|
||||
|
||||
FFeed := TScalarRecordFeed.Create(FFileCache, path, '.m1', true, def);
|
||||
FFeed :=
|
||||
TScalarBatchLoader.Create(
|
||||
FFileCache,
|
||||
path,
|
||||
'.m1',
|
||||
true,
|
||||
SizeOf(TM1FileItem),
|
||||
procedure(const Src: Pointer; Dst: TScalar.PValue)
|
||||
var
|
||||
Item: ^TM1FileItem;
|
||||
begin
|
||||
Item := Src;
|
||||
|
||||
// Field 0: Time (DateTime is stored as Double/OADate in TScalar)
|
||||
Dst.AsDouble := Item.OADateTime;
|
||||
|
||||
// Move to next field in destination (TScalar values are contiguous)
|
||||
Inc(Dst);
|
||||
|
||||
// Field 1: Close (Float)
|
||||
// Convert Int64 price to Double using Digits: Price / 10^Digits
|
||||
if Item.Digits > 0 then
|
||||
Dst.AsDouble := Item.Close / Power(10, Item.Digits)
|
||||
else
|
||||
Dst.AsDouble := Item.Close;
|
||||
end
|
||||
);
|
||||
|
||||
// Converter: Transforms raw IRecordSeries (Columns) into TArray<TDataPoint>
|
||||
|
||||
var unpacker: TConverter<TScalarBatch, IScalarRecord> := TScalarBatchUnpacker.Create(def);
|
||||
|
||||
var ticker :=
|
||||
FFeed.Ticker.Chain<TDataPoint<Double>>(
|
||||
unpacker.Producer.Chain<TDataPoint<Double>>(
|
||||
function(const Tick: IScalarRecord): TDataPoint<Double>
|
||||
begin
|
||||
Result.Time := Tick[iTime].Value.Value.AsDouble;
|
||||
@@ -398,6 +427,8 @@ begin
|
||||
end
|
||||
);
|
||||
|
||||
FFeed.BatchProducer.Chain(unpacker.Consumer);
|
||||
|
||||
// Link Chart to Ticker
|
||||
chart
|
||||
.SetXAxisSeries(TTimeframe.M, ticker.Chain<TDateTime>(function(const p: TDataPoint<Double>): TDateTime begin Result := p.Time end));
|
||||
@@ -408,29 +439,6 @@ begin
|
||||
TAlphaColors.Orange
|
||||
);
|
||||
|
||||
FFeed.SetImportOptions(
|
||||
SizeOf(TM1FileItem),
|
||||
procedure(const Src: Pointer; Dst: TScalar.PValue)
|
||||
var
|
||||
Item: ^TM1FileItem;
|
||||
begin
|
||||
Item := Src;
|
||||
|
||||
// Field 0: Time (DateTime is stored as Double/OADate in TScalar)
|
||||
Dst.AsDouble := Item.OADateTime;
|
||||
|
||||
// Move to next field in destination (TScalar values are contiguous)
|
||||
Inc(Dst);
|
||||
|
||||
// Field 1: Close (Float)
|
||||
// Convert Int64 price to Double using Digits: Price / 10^Digits
|
||||
if Item.Digits > 0 then
|
||||
Dst.AsDouble := Item.Close / Power(10, Item.Digits)
|
||||
else
|
||||
Dst.AsDouble := Item.Close;
|
||||
end
|
||||
);
|
||||
|
||||
// Connect pipeline: Server -> Converter
|
||||
FProcessDone := FFeed.ProcessData(symbol, terminated);
|
||||
end;
|
||||
|
||||
Reference in New Issue
Block a user