Skip to content

Commit

Permalink
Added TimeProvider (instead of using DateTime.Now). This will help wh…
Browse files Browse the repository at this point in the history
…en needing to backtest
  • Loading branch information
Ariel Silahian committed Jan 9, 2024
1 parent 59b3474 commit 7922350
Show file tree
Hide file tree
Showing 23 changed files with 36 additions and 282 deletions.
6 changes: 3 additions & 3 deletions DataRetriever/FIXDataRetriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ private void HandleMarketDataSnapshot(MarketDataSnapshotFullRefresh snapshot)
Size = size.ToDouble(),
IsBid = type == '0',
EntryID = entryId.ToString(),
LocalTimeStamp = DateTime.Now,
ServerTimeStamp = DateTime.Now,
LocalTimeStamp = HelperTimeProvider.Now,
ServerTimeStamp = HelperTimeProvider.Now,
DecimalPlaces = decimalPlaces.Value,
ProviderID = 12, //FXCM
Symbol = symbol,
Expand Down Expand Up @@ -202,7 +202,7 @@ private void HandleMarketDataSnapshot(MarketDataSnapshotFullRefresh snapshot)
}
private void HandleHeartBeat()
{
var provider = new VisualHFT.ViewModel.Model.Provider() { LastUpdated = DateTime.Now, ProviderCode = 12, ProviderID = 12, ProviderName = "FXCM", Status = eSESSIONSTATUS.BOTH_CONNECTED };
var provider = new VisualHFT.ViewModel.Model.Provider() { LastUpdated = HelperTimeProvider.Now, ProviderCode = 12, ProviderID = 12, ProviderName = "FXCM", Status = eSESSIONSTATUS.BOTH_CONNECTED };
var model = new List<VisualHFT.ViewModel.Model.Provider>() { provider };
// Raise an event or further process the data as needed
OnDataReceived?.Invoke(this, new DataEventArgs { DataType = "HeartBeats", ParsedModel = model, RawData = "" });
Expand Down
2 changes: 1 addition & 1 deletion DataRetriever/KafkaDataRetriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private void HandleMessage(string message)
// Raise the OnDataReceived event
OnDataReceived?.Invoke(this, new DataEventArgs { DataType = "Market", RawData = message, ParsedModel = model });

var provider = new VisualHFT.ViewModel.Model.Provider() { LastUpdated = DateTime.Now, ProviderID = 2, ProviderName = "Kafka", Status = eSESSIONSTATUS.BOTH_CONNECTED };
var provider = new VisualHFT.ViewModel.Model.Provider() { LastUpdated = HelperTimeProvider.Now, ProviderID = 2, ProviderName = "Kafka", Status = eSESSIONSTATUS.BOTH_CONNECTED };
// Raise the OnDataReceived event
OnDataReceived?.Invoke(this, new DataEventArgs { DataType = "HeartBeats", RawData = message, ParsedModel = model });
}
Expand Down
2 changes: 1 addition & 1 deletion DataRetriever/ZeroMQDataRetriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private void HandleMessage(string message)



var provider = new VisualHFT.ViewModel.Model.Provider() { LastUpdated = DateTime.Now, ProviderID = 1, ProviderName = "ZeroMQ", Status = eSESSIONSTATUS.BOTH_CONNECTED };
var provider = new VisualHFT.ViewModel.Model.Provider() { LastUpdated = HelperTimeProvider.Now, ProviderID = 1, ProviderName = "ZeroMQ", Status = eSESSIONSTATUS.BOTH_CONNECTED };
// Raise the OnDataReceived event
OnDataReceived?.Invoke(this, new DataEventArgs { DataType = "HeartBeats", RawData = message, ParsedModel = model });

Expand Down
6 changes: 3 additions & 3 deletions DataTradeRetriever/FIXTradesRetriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public ReadOnlyCollection<VisualHFT.Model.Position> Positions
order.ProviderId = _providerId;
order.ProviderName = _providerName;
order.Executions = new List<VisualHFT.Model.Execution>();
order.LastUpdated = System.DateTime.Now;
order.LastUpdated = HelperTimeProvider.Now;
parsedOrders.Add(order.ClOrdId, order);
}
else if (dicFIX[Tags.MsgType] == MsgType.ORDER_CANCEL_REPLACE_REQUEST)
Expand All @@ -203,7 +203,7 @@ public ReadOnlyCollection<VisualHFT.Model.Position> Positions
exec.Side = (int)order.Side;
exec.Price = 0;
exec.QtyFilled = 0;
order.LastUpdated = System.DateTime.Now;
order.LastUpdated = HelperTimeProvider.Now;
order.Executions.Add(new VisualHFT.Model.Execution(exec, order.Symbol));
}
else
Expand Down Expand Up @@ -238,7 +238,7 @@ public ReadOnlyCollection<VisualHFT.Model.Position> Positions
order.Executions.Add(new Execution(exec, order.Symbol));

order.Status = ParseOrderStatus(dicFIX[Tags.OrdStatus]);
order.LastUpdated = System.DateTime.Now;
order.LastUpdated = HelperTimeProvider.Now;

if (order.Status == eORDERSTATUS.REPLACED)
{
Expand Down
2 changes: 1 addition & 1 deletion Helpers/HelperActiveOrders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private bool UpdateData(VisualHFT.Model.Order order)
//Check provider
if (!this.ContainsKey(order.ClOrdId))
{
order.CreationTimeStamp = DateTime.Now;
order.CreationTimeStamp = HelperTimeProvider.Now;
return this.TryAdd(order.ClOrdId, order);
}
else
Expand Down
12 changes: 6 additions & 6 deletions Helpers/HelperCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class HelperCommon
{
public static DateTime GetCurrentSessionIni(DateTime? currentSessionDate)
{
currentSessionDate = currentSessionDate.ToDate().AddHours(DateTime.Now.Hour).AddMinutes(DateTime.Now.Minute);
currentSessionDate = currentSessionDate.ToDate().AddHours(HelperTimeProvider.Now.Hour).AddMinutes(HelperTimeProvider.Now.Minute);
if (!currentSessionDate.HasValue)
currentSessionDate = DateTime.Now;
currentSessionDate = HelperTimeProvider.Now;
DateTime DateAt00 = currentSessionDate.ToDate();
DateTime DateAt500PM = DateAt00.AddHours(17);
DateTime DateAt530PM = DateAt00.AddHours(17).AddMinutes(30);
Expand All @@ -24,13 +24,13 @@ public static DateTime GetCurrentSessionIni(DateTime? currentSessionDate)
else if (currentSessionDate > DateAt00 && currentSessionDate < DateAt500PM)
return DateAt530PM.AddDays(-1);
else
return DateTime.Now;
return HelperTimeProvider.Now;
}
public static DateTime GetCurrentSessionEnd(DateTime? currentSessionDate)
{
currentSessionDate = currentSessionDate.ToDate().AddHours(DateTime.Now.Hour).AddMinutes(DateTime.Now.Minute);
currentSessionDate = currentSessionDate.ToDate().AddHours(HelperTimeProvider.Now.Hour).AddMinutes(HelperTimeProvider.Now.Minute);
if (!currentSessionDate.HasValue)
currentSessionDate = DateTime.Now;
currentSessionDate = HelperTimeProvider.Now;
DateTime DateAt00 = currentSessionDate.ToDate();
DateTime DateAt500PM = DateAt00.AddHours(17);
DateTime DateAt530PM = DateAt00.AddHours(17).AddMinutes(30);
Expand All @@ -39,7 +39,7 @@ public static DateTime GetCurrentSessionEnd(DateTime? currentSessionDate)
else if (currentSessionDate > DateAt00 && currentSessionDate < DateAt500PM)
return DateAt500PM;
else
return DateTime.Now;
return HelperTimeProvider.Now;
}
public static int TimerMillisecondsToGetVariables = 1000 * 10; //10 seconds

Expand Down
246 changes: 0 additions & 246 deletions Helpers/HelperDataGrid.cs

This file was deleted.

6 changes: 3 additions & 3 deletions Model/PositionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public PositionManager(List<VisualHFT.Model.Order> orders, PositionManagerCalcul

PLRealized = CalculateRealizedPnL();
PLTot = PLRealized + PLOpen;
LastUpdated = DateTime.Now;
LastUpdated = HelperTimeProvider.Now;
}
private List<VisualHFT.Model.Order> Buys {
get => _buys;
Expand Down Expand Up @@ -149,7 +149,7 @@ public void AddOrder(VisualHFT.Model.Order newOrder)
PLRealized = CalculateRealizedPnL();
PLOpen = CalculateOpenPnl();
PLTot = _plRealized + _plOpen;
LastUpdated = DateTime.Now;
LastUpdated = HelperTimeProvider.Now;
UpdateUI();
}
public void UpdateLastMidPrice(double newMidPrice)
Expand All @@ -158,7 +158,7 @@ public void UpdateLastMidPrice(double newMidPrice)
PLOpen = CalculateOpenPnl();
PLTot = _plRealized + _plOpen;
UpdateUI();
LastUpdated = DateTime.Now;
LastUpdated = HelperTimeProvider.Now;
}
}
}
2 changes: 1 addition & 1 deletion ViewModel/vmMultiVenuePrices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void LIMITORDERBOOK_OnDataReceived(OrderBook e)
_latesPrice[e.ProviderID] = e.MidPrice;
foreach (var key in _allDataSeries.Keys)
{
_allDataSeries[key].Item1.Add(new PlotInfo() { Date = DateTime.Now, Value = _latesPrice[key] });
_allDataSeries[key].Item1.Add(new PlotInfo() { Date = HelperTimeProvider.Now, Value = _latesPrice[key] });
_allDataSeries[key].Item2.ItemsSource = _allDataSeries[key].Item1.Select(x => new OxyPlot.DataPoint(x.Date.Ticks, x.Value));
}
}
Expand Down
Loading

0 comments on commit 7922350

Please sign in to comment.