mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-07-28 19:17:48 +00:00
Added MtNofication message into MtClient
This commit is contained in:
@@ -3792,7 +3792,7 @@ namespace MtApi5
|
||||
{
|
||||
Log?.Debug("OnConnected: begin");
|
||||
|
||||
Client?.Send(new MtClientReady());
|
||||
Client?.Send(new MtNotification(MtNotificationType.ClientReady));
|
||||
|
||||
_isBacktestingMode = IsTesting();
|
||||
|
||||
|
||||
+12
-8
@@ -1,7 +1,4 @@
|
||||
using System.ComponentModel.Design;
|
||||
using System.Data;
|
||||
|
||||
namespace MtClient
|
||||
namespace MtClient
|
||||
{
|
||||
public enum MessageType
|
||||
{
|
||||
@@ -11,7 +8,12 @@ namespace MtClient
|
||||
ExpertList = 3,
|
||||
ExpertAdded = 4,
|
||||
ExpertRemoved = 5,
|
||||
ClientReady = 6
|
||||
Notification = 6
|
||||
}
|
||||
|
||||
public enum MtNotificationType
|
||||
{
|
||||
ClientReady = 0
|
||||
}
|
||||
|
||||
public abstract class MtMessage
|
||||
@@ -41,14 +43,16 @@ namespace MtClient
|
||||
}
|
||||
}
|
||||
|
||||
public class MtClientReady : MtMessage
|
||||
public class MtNotification(MtNotificationType notificationType) : MtMessage
|
||||
{
|
||||
public override MessageType MsgType => MessageType.ClientReady;
|
||||
public override MessageType MsgType => MessageType.Notification;
|
||||
|
||||
protected override string GetMessageBody()
|
||||
{
|
||||
return string.Empty;
|
||||
return $"{(int)NotificationType}";
|
||||
}
|
||||
|
||||
public MtNotificationType NotificationType { private set; get; } = notificationType;
|
||||
}
|
||||
|
||||
public class MtEvent(int expertHandle, int eventType, string payload) : MtMessage
|
||||
|
||||
@@ -58,7 +58,10 @@ namespace MtClient
|
||||
|
||||
public void Send(MtMessage message)
|
||||
{
|
||||
pendingMessages_.Enqueue(message.Serialize());
|
||||
lock (pendingMessages_)
|
||||
{
|
||||
pendingMessages_.Enqueue(message);
|
||||
}
|
||||
sendWaiter_.Set();
|
||||
}
|
||||
|
||||
@@ -66,7 +69,7 @@ namespace MtClient
|
||||
{
|
||||
while(ws_.State == WebSocketState.Open)
|
||||
{
|
||||
string? message = null;
|
||||
MtMessage? message = null;
|
||||
lock(pendingMessages_)
|
||||
{
|
||||
if (pendingMessages_.Count > 0)
|
||||
@@ -81,8 +84,9 @@ namespace MtClient
|
||||
|
||||
try
|
||||
{
|
||||
Log($"DoWrite: sending message: {message}");
|
||||
byte[] bytes = Encoding.ASCII.GetBytes(message);
|
||||
string msgStr = message.Serialize();
|
||||
Log($"DoWrite: sending message: {msgStr}");
|
||||
byte[] bytes = Encoding.ASCII.GetBytes(msgStr);
|
||||
await ws_.SendAsync(bytes, WebSocketMessageType.Text, true, CancellationToken.None);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -177,8 +181,7 @@ namespace MtClient
|
||||
private readonly string host_;
|
||||
private readonly int port_;
|
||||
private readonly byte[] buf_ = new byte[10000];
|
||||
private readonly Dictionary<MessageType, Func<string, MtMessage?>> msgHandlers_ = new();
|
||||
private readonly Queue<string> pendingMessages_ = [];
|
||||
private readonly Queue<MtMessage> pendingMessages_ = [];
|
||||
|
||||
private readonly Thread receiveThread_;
|
||||
private readonly Thread sendThread_;
|
||||
|
||||
Reference in New Issue
Block a user