DataFeed-Producer
This commit is contained in:
@@ -9,7 +9,8 @@ uses
|
||||
DynamicFMXControl in 'DynamicFMXControl.pas',
|
||||
Myc.Trade.Pipeline.Impl in '..\Src\Myc.Trade.Pipeline.Impl.pas',
|
||||
Myc.Trade.Indicators_v2 in '..\Src\Myc.Trade.Indicators_v2.pas',
|
||||
Strategy2 in 'Strategy2.pas';
|
||||
Strategy2 in 'Strategy2.pas',
|
||||
Myc.Trade.DataFeed in '..\Src\Myc.Trade.DataFeed.pas';
|
||||
|
||||
{$R *.res}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<ProjectVersion>20.3</ProjectVersion>
|
||||
<FrameworkType>FMX</FrameworkType>
|
||||
<Base>True</Base>
|
||||
<Config Condition="'$(Config)'==''">Debug</Config>
|
||||
<Config Condition="'$(Config)'==''">Release</Config>
|
||||
<Platform Condition="'$(Platform)'==''">Win64</Platform>
|
||||
<ProjectName Condition="'$(ProjectName)'==''">AuraTrader</ProjectName>
|
||||
<TargetedPlatforms>3</TargetedPlatforms>
|
||||
@@ -140,6 +140,7 @@
|
||||
<DCCReference Include="..\Src\Myc.Trade.Pipeline.Impl.pas"/>
|
||||
<DCCReference Include="..\Src\Myc.Trade.Indicators_v2.pas"/>
|
||||
<DCCReference Include="Strategy2.pas"/>
|
||||
<DCCReference Include="..\Src\Myc.Trade.DataFeed.pas"/>
|
||||
<BuildConfiguration Include="Base">
|
||||
<Key>Base</Key>
|
||||
</BuildConfiguration>
|
||||
|
||||
@@ -204,6 +204,13 @@ object Form1: TForm1
|
||||
Text = 'Button2'
|
||||
OnClick = Button2Click
|
||||
end
|
||||
object Button3: TButton
|
||||
Position.X = 64.000000000000000000
|
||||
Position.Y = 152.000000000000000000
|
||||
TabOrder = 2
|
||||
Text = 'Button3'
|
||||
OnClick = Button3Click
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -40,6 +40,8 @@ uses
|
||||
Myc.Signals.FMX,
|
||||
Myc.TaskManager,
|
||||
Myc.Aura.Module,
|
||||
Myc.Data.Scalar,
|
||||
Myc.Data.Keyword,
|
||||
FMX.ListBox,
|
||||
FMX.Layouts,
|
||||
FMX.TreeView,
|
||||
@@ -53,6 +55,7 @@ uses
|
||||
Myc.FMX.Chart,
|
||||
Myc.Trade.Indicators,
|
||||
Myc.Trade.Indicators.Common,
|
||||
Myc.Trade.DataFeed,
|
||||
StrategyTest,
|
||||
TestMethodCallFromRecordParams;
|
||||
|
||||
@@ -85,6 +88,7 @@ type
|
||||
Strat2Button: TSpeedButton;
|
||||
Button1: TButton;
|
||||
Button2: TButton;
|
||||
Button3: TButton;
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormDestroy(Sender: TObject);
|
||||
procedure StopButtonClick(Sender: TObject);
|
||||
@@ -92,6 +96,7 @@ type
|
||||
procedure AddWorkspaceActionExecute(Sender: TObject);
|
||||
procedure Button1Click(Sender: TObject);
|
||||
procedure Button2Click(Sender: TObject);
|
||||
procedure Button3Click(Sender: TObject);
|
||||
procedure LogMemoChange(Sender: TObject);
|
||||
procedure Strat2ButtonClick(Sender: TObject);
|
||||
procedure TestActionExecute(Sender: TObject);
|
||||
@@ -109,6 +114,7 @@ type
|
||||
FProcessDone: TState;
|
||||
FApplication: IAuraApplication;
|
||||
FModulesItem: TTreeViewItem;
|
||||
FTickerServer: IScalarBatchServer;
|
||||
function SelectedSymbol: String;
|
||||
procedure ExecuteStrategy(const Symbol: String; Timeframe: TTimeframe; const Consumer: IConsumer<TDataPoint<TOhlcItem>>);
|
||||
|
||||
@@ -340,6 +346,91 @@ begin
|
||||
|
||||
end;
|
||||
|
||||
procedure TForm1.Button3Click(Sender: TObject);
|
||||
begin
|
||||
var symbol := SelectedSymbol;
|
||||
if symbol = '' then
|
||||
exit;
|
||||
|
||||
var layout := CurrLayout<TVertScrollBox>;
|
||||
if layout = nil then
|
||||
exit;
|
||||
|
||||
// 1. Setup Chart
|
||||
var chart := TMycChart.Create(Self);
|
||||
AlignControl(chart);
|
||||
chart.Height := layout.ChildrenRect.Width * 9 / 16;
|
||||
chart.Lookback.Value := 500000;
|
||||
|
||||
// 2. Define Schema (Keywords & Layout)
|
||||
var kTime := TKeywordRegistry.Intern('Time');
|
||||
var kClose := TKeywordRegistry.Intern('Close');
|
||||
|
||||
var def :=
|
||||
TScalarRecordRegistry.Intern(
|
||||
[
|
||||
TPair<IKeyword, TScalar.TKind>.Create(kTime, TScalar.TKind.DateTime),
|
||||
TPair<IKeyword, TScalar.TKind>.Create(kClose, TScalar.TKind.Float)
|
||||
]
|
||||
);
|
||||
|
||||
// 3. Build Pipeline
|
||||
|
||||
var iTime := def.IndexOf(kTime);
|
||||
var iClose := def.IndexOf(kClose);
|
||||
|
||||
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;
|
||||
|
||||
// Converter: Transforms raw IRecordSeries (Columns) into TArray<TDataPoint>
|
||||
var ticker :=
|
||||
FTickerServer.Ticker.Chain<TDataPoint<Double>>(
|
||||
function(const Tick: IScalarRecord): TDataPoint<Double>
|
||||
begin
|
||||
Result.Time := Tick.ItemByIndex(iTime).Value.AsDouble;
|
||||
Result.Data := Tick.ItemByIndex(iClose).Value.AsDouble;
|
||||
end
|
||||
);
|
||||
|
||||
// Link Chart to Ticker
|
||||
chart
|
||||
.SetXAxisSeries(TTimeframe.M, ticker.Chain<TDateTime>(function(const p: TDataPoint<Double>): TDateTime begin Result := p.Time end));
|
||||
|
||||
var panel := chart.AddPanel;
|
||||
panel.AddDoubleSeries(
|
||||
ticker.Chain<Double>(function(const p: TDataPoint<Double>): Double begin Result := p.Data end),
|
||||
TAlphaColors.Orange
|
||||
);
|
||||
|
||||
FTickerServer.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 := FTickerServer.ProcessData(symbol, terminated);
|
||||
end;
|
||||
|
||||
function TForm1.CreateStrategy2(Timeframe: TTimeframe): IConsumer<TDataPoint<TOhlcItem>>;
|
||||
type
|
||||
TSignal = record
|
||||
|
||||
Reference in New Issue
Block a user