Skip to content

Commit

Permalink
refactor: DataReceived event
Browse files Browse the repository at this point in the history
  • Loading branch information
jirikostiha committed Jan 2, 2025
1 parent 2ac80c3 commit 8d66f1c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/SyncAPIConnector/StreamingApiConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public StreamingApiConnector(IPEndPoint endpoint, IStreamingListener? streamingL
}

#region Events

/// <summary>
/// Event raised when a command is being executed.
/// </summary>
Expand All @@ -45,7 +46,7 @@ public StreamingApiConnector(IPEndPoint endpoint, IStreamingListener? streamingL
/// <summary>
/// Event raised when a streaming data is being received.
/// </summary>
public event EventHandler<string>? StreamingDataReceived;
public event EventHandler<DataReceivedEventArgs>? DataReceived;

/// <summary>
/// Event raised when a tick record is received.
Expand Down Expand Up @@ -179,7 +180,7 @@ private async Task ReadStreamMessageAsync(CancellationToken cancellationToken =

var jsonDataObject = jsonSubnode.AsObject();

StreamingDataReceived?.Invoke(this, dataType);
DataReceived?.Invoke(this, new(dataType, responseBody));

if (dataType == StreamingDataType.TickPrices)
{
Expand Down
5 changes: 4 additions & 1 deletion src/SyncAPIConnector/abstraction/EventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Net;
using System.Text.Json.Nodes;
using Xtb.XApi.Records;

namespace Xtb.XApi;
Expand Down Expand Up @@ -28,9 +29,11 @@ public class EndpointEventArgs(IPEndPoint endpoint) : EventArgs
public IPEndPoint EndPoint { get; } = endpoint;
}

public class StreamingDataReceivedEventArgs(string dataType) : EventArgs
public class DataReceivedEventArgs(string dataType, JsonNode responseObject) : EventArgs
{
public string DataType { get; } = dataType;

public JsonNode ResponseBody { get; } = responseObject;
}

public class TickReceivedEventArgs(StreamingTickRecord tickRecord) : EventArgs
Expand Down

0 comments on commit 8d66f1c

Please sign in to comment.