Streamlining DataServer
This commit is contained in:
+13
-148
@@ -6,163 +6,28 @@ uses
|
||||
System.SysUtils;
|
||||
|
||||
type
|
||||
IDataPoint<T> = interface
|
||||
['{6A52697A-2868-42A9-982D-993542B7B360}']
|
||||
function GetData: T;
|
||||
function GetIdx: Int64;
|
||||
function GetTime: TDateTime;
|
||||
function GetVolume: Double;
|
||||
|
||||
property Time: TDateTime read GetTime;
|
||||
property Volume: Double read GetVolume;
|
||||
property Data: T read GetData;
|
||||
property Idx: Int64 read GetIdx;
|
||||
// A specific data record structure for Ask and Bid prices.
|
||||
TAskBidItem = packed record
|
||||
Ask: Single;
|
||||
Bid: Single;
|
||||
end;
|
||||
|
||||
ITick = interface
|
||||
['{B342223B-D299-4A1C-82F3-569F54417A66}']
|
||||
function GetAsk: Double;
|
||||
function GetBid: Double;
|
||||
|
||||
property Ask: Double read GetAsk;
|
||||
property Bid: Double read GetBid;
|
||||
end;
|
||||
ITickData = IDataPoint<ITick>;
|
||||
|
||||
IOHLC = interface
|
||||
['{05374E3C-731B-44FA-A23E-051F1461B78D}']
|
||||
function GetOpen: Double;
|
||||
function GetHigh: Double;
|
||||
function GetLow: Double;
|
||||
function GetClose: Double;
|
||||
|
||||
property Open: Double read GetOpen;
|
||||
property High: Double read GetHigh;
|
||||
property Low: Double read GetLow;
|
||||
property Close: Double read GetClose;
|
||||
end;
|
||||
IOHLCData = IDataPoint<IOHLC>;
|
||||
|
||||
// Abstract base class for all data points.
|
||||
TDataPoint<T> = class abstract(TInterfacedObject, IDataPoint<T>)
|
||||
protected
|
||||
fTime: TDateTime;
|
||||
fVolume: Double;
|
||||
FData: T;
|
||||
FIdx: Int64;
|
||||
function GetTime: TDateTime;
|
||||
function GetVolume: Double;
|
||||
function GetData: T;
|
||||
function GetIdx: Int64;
|
||||
public
|
||||
constructor Create(Idx: Int64; Time: TDateTime; Volume: Double; const AData: T);
|
||||
end;
|
||||
|
||||
TTick = class(TInterfacedObject, ITick)
|
||||
private
|
||||
fAsk: Double;
|
||||
fBid: Double;
|
||||
function GetAsk: Double;
|
||||
function GetBid: Double;
|
||||
public
|
||||
constructor Create(Ask: Double; Bid: Double);
|
||||
end;
|
||||
|
||||
TOHLC = class(TInterfacedObject, IOHLC)
|
||||
private
|
||||
fOpen: Double;
|
||||
fHigh: Double;
|
||||
fLow: Double;
|
||||
fClose: Double;
|
||||
function GetClose: Double;
|
||||
function GetHigh: Double;
|
||||
function GetLow: Double;
|
||||
function GetOpen: Double;
|
||||
public
|
||||
constructor Create(Open, High, Low, Close: Double);
|
||||
TDataPoint<T> = record
|
||||
Idx: Int64;
|
||||
Time: TDateTime;
|
||||
Data: T;
|
||||
constructor Create(AIdx: Int64; ATime: TDateTime; const AData: T);
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ TDataPoint }
|
||||
|
||||
constructor TDataPoint<T>.Create(Idx: Int64; Time: TDateTime; Volume: Double; const AData: T);
|
||||
constructor TDataPoint<T>.Create(AIdx: Int64; ATime: TDateTime; const AData: T);
|
||||
begin
|
||||
inherited Create;
|
||||
FIdx := Idx;
|
||||
fTime := Time;
|
||||
fVolume := Volume;
|
||||
FData := AData;
|
||||
end;
|
||||
|
||||
function TDataPoint<T>.GetData: T;
|
||||
begin
|
||||
Result := FData;
|
||||
end;
|
||||
|
||||
function TDataPoint<T>.GetIdx: Int64;
|
||||
begin
|
||||
Result := FIdx;
|
||||
end;
|
||||
|
||||
function TDataPoint<T>.GetTime: TDateTime;
|
||||
begin
|
||||
result := fTime;
|
||||
end;
|
||||
|
||||
function TDataPoint<T>.GetVolume: Double;
|
||||
begin
|
||||
result := fVolume;
|
||||
end;
|
||||
|
||||
{ TTick }
|
||||
|
||||
constructor TTick.Create(Ask: Double; Bid: Double);
|
||||
begin
|
||||
inherited Create;
|
||||
fAsk := Ask;
|
||||
fBid := Bid;
|
||||
end;
|
||||
|
||||
function TTick.GetAsk: Double;
|
||||
begin
|
||||
result := fAsk;
|
||||
end;
|
||||
|
||||
function TTick.GetBid: Double;
|
||||
begin
|
||||
result := fBid;
|
||||
end;
|
||||
|
||||
{ TOHLC }
|
||||
|
||||
constructor TOHLC.Create(Open, High, Low, Close: Double);
|
||||
begin
|
||||
inherited Create;
|
||||
fOpen := Open;
|
||||
fHigh := High;
|
||||
fLow := Low;
|
||||
fClose := Close;
|
||||
end;
|
||||
|
||||
function TOHLC.GetClose: Double;
|
||||
begin
|
||||
result := fClose;
|
||||
end;
|
||||
|
||||
function TOHLC.GetHigh: Double;
|
||||
begin
|
||||
result := fHigh;
|
||||
end;
|
||||
|
||||
function TOHLC.GetLow: Double;
|
||||
begin
|
||||
result := fLow;
|
||||
end;
|
||||
|
||||
function TOHLC.GetOpen: Double;
|
||||
begin
|
||||
result := fOpen;
|
||||
Idx := AIdx;
|
||||
Time := ATime;
|
||||
Data := AData;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user