Unit TradeSimulatorUnit; { This unit creates fake TOS and L1 data. It has a very simple interface which is especially useful for stress testing. Currently this is tied to the esignal implementation of TOS and L1. The interface and design should be reused to match other data feeds. } Interface Uses Timers, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; Type TTradeSimulator = class(TForm) EnabledCheckBox: TCheckBox; Label1: TLabel; Label2: TLabel; Label3: TLabel; SymbolNames: TMemo; Label4: TLabel; TradesPerCycle: TEdit; BBOChangesPerCycle: TEdit; MsPerCycle: TEdit; DoOnce: TButton; procedure DoOnceClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure EnabledCheckBoxClick(Sender: TObject); private Timer : ITimerEvent; SymbolNamesCopy : TStrings; TradesPerCycleCopy, BBOChangesPerCycleCopy : Integer; LastPrice : Double; //Ticks : Word; //Index : Integer; Procedure DoOneCycle; Procedure CopyArgs; Procedure StartEvents; Procedure StopEvents; public { Public declarations } end; Var TradeSimulator: TTradeSimulator; Implementation {$R *.dfm} Uses GenericTosDataNode {, EsigDmThread}; Procedure TTradeSimulator.StartEvents; Var MsPerCycleCopy : Integer; Begin CopyArgs; MsPerCycleCopy := StrToInt(MsPerCycle.Text); SymbolNames.Enabled := False; TradesPerCycle.Enabled := False; BBOChangesPerCycle.Enabled := False; MsPerCycle.Enabled := False; DoOnce.Enabled := False; Timer := RequestPeriodicCallback(DoOneCycle, MsPerCycleCopy) End; Procedure TTradeSimulator.StopEvents; Begin If Assigned(Timer) Then Begin Timer.Clear; Timer := Nil End; SymbolNames.Enabled := True; TradesPerCycle.Enabled := True; BBOChangesPerCycle.Enabled := True; MsPerCycle.Enabled := True; DoOnce.Enabled := True; End; procedure TTradeSimulator.CopyArgs; Begin SymbolNamesCopy.Assign(SymbolNames.Lines); TradesPerCycleCopy := StrToInt(TradesPerCycle.Text); BBOChangesPerCycleCopy := StrToInt(BBOChangesPerCycle.Text); End; procedure TTradeSimulator.DoOneCycle; { Var I : Integer; Data : TDmData; Key : String; Info : TDmInfo;} begin { Data.L1.Open := 10.00; Data.L1.High := 0.05; Data.L1.Low := 0.02; Data.L1.PrevClose := 20.00; Data.LastTos.Size := 100; Data.LastTos.Time := Now; Data.LastTos.Exchange := 'PHIL'; Data.LastTos.FormT := False; Data.LastTos.EventType := etNewPrint; //Data.LastTos.TradeType := 0; Data.TosAndL1Valid := True; Data.L1.BidExchange := 'PHIL'; Data.L1.AskExchange := 'PHIL'; Data.L1.AskSize := 100; Data.L1.BidSize := 200; For I := 1 To BBOChangesPerCycleCopy Do Begin LastPrice := LastPrice + 0.01; If I <= TradesPerCycleCopy Then Begin Inc(Data.LastTos.Ticks); Data.NewTosEvent := True End Else Data.NewTosEvent := False; Data.LastTos.Price := LastPrice; Data.L1.BidPrice := LastPrice - 0.01; Data.L1.AskPrice := LastPrice + 0.01; Data.L1.Volume := Ticks * 100; Key := SymbolNamesCopy[Index Mod SymbolNamesCopy.Count]; Info := TDmInfo.Create; Info.Symbol := Key; Info.Data := Data; Info.Send(TESignalDm.DataChannel(Key)); Inc(Index) End} End; procedure TTradeSimulator.DoOnceClick(Sender: TObject); begin CopyArgs; DoOneCycle end; procedure TTradeSimulator.FormCreate(Sender: TObject); begin SymbolNamesCopy := TStringList.Create; LastPrice := 0.05; end; procedure TTradeSimulator.EnabledCheckBoxClick(Sender: TObject); begin If EnabledCheckBox.Checked Then Try StartEvents Except On EConvertError Do Begin Beep; StopEvents; EnabledCheckBox.Checked := False End End Else StopEvents; end; end.