Skip to content

Commit 172bfab

Browse files
author
Ahmad Noman Musleh
committed
Added trend bars call to console app
1 parent 47664b7 commit 172bfab

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

src/Console.Sample/Program.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ private static async Task Main()
103103
ShowDashLine();
104104

105105
Console.WriteLine($"Access token generated: {_token.AccessToken}");
106-
107106
}
108107

109108
var host = ApiInfo.GetHost(mode);
@@ -192,6 +191,7 @@ private static void ProcessCommand(string command)
192191
Console.WriteLine("For getting an account symbols list type (Requires account authorization): symbolslist {Account ID}\n");
193192
Console.WriteLine("For subscribing to symbol(s) spot quotes type (Requires account authorization): subscribe spot {Account ID} {Symbol ID,}\n");
194193
Console.WriteLine("For subscribing to symbol(s) trend bar type (Requires account authorization and spot subscription): subscribe trendbar {Period} {Account ID} {Symbol ID}\n");
194+
Console.WriteLine("For getting trend bar data: trendbar {Period} {Account ID} {Symbol ID} {numberOfDays}\n");
195195
Console.WriteLine("For trend bar period parameter, you can use these values:\n");
196196

197197
var trendbars = Enum.GetValues(typeof(ProtoOATrendbarPeriod)).Cast<ProtoOATrendbarPeriod>();
@@ -239,6 +239,10 @@ private static void ProcessCommand(string command)
239239
ProcessSubscriptionCommand(commandSplit);
240240
break;
241241

242+
case "trendbar":
243+
TrendbarRequest(commandSplit);
244+
break;
245+
242246
case "tickdata":
243247
TickDataRequest(commandSplit);
244248
break;
@@ -424,6 +428,30 @@ private static async void TickDataRequest(string[] commandSplit)
424428
await _client.SendMessage(request);
425429
}
426430

431+
private static async void TrendbarRequest(string[] commandSplit)
432+
{
433+
var period = (ProtoOATrendbarPeriod)Enum.Parse(typeof(ProtoOATrendbarPeriod), commandSplit[1], true);
434+
var accountId = long.Parse(commandSplit[2]);
435+
var symbolId = long.Parse(commandSplit[3]);
436+
437+
var days = long.Parse(commandSplit[4]);
438+
439+
Console.WriteLine("Sending ProtoOAGetTrendbarsReq...");
440+
441+
var request = new ProtoOAGetTrendbarsReq
442+
{
443+
CtidTraderAccountId = accountId,
444+
SymbolId = symbolId,
445+
Period = period,
446+
FromTimestamp = DateTimeOffset.UtcNow.AddDays(-days).ToUnixTimeMilliseconds(),
447+
ToTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
448+
};
449+
450+
Console.WriteLine($"FromTimestamp: {request.FromTimestamp} | ToTimestamp: {request.ToTimestamp}");
451+
452+
await _client.SendMessage(request);
453+
}
454+
427455
private static async void ProfileRequest()
428456
{
429457
Console.WriteLine("Sending ProtoOAGetCtidProfileByTokenReq...");

src/OpenAPI.Net/OpenClient.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public sealed class OpenClient : IDisposable, IObservable<IMessage>
4343

4444
private IDisposable _webSocketMessageReceivedDisposable;
4545

46-
4746
/// <summary>
4847
/// Creates an instance of OpenClient which is not connected yet
4948
/// </summary>
@@ -56,7 +55,7 @@ public OpenClient(string host, int port, TimeSpan heartbeatInerval, int maxReque
5655
{
5756
Host = host ?? throw new ArgumentNullException(nameof(host));
5857

59-
if (port < 0 || port > 65535) throw new ArgumentOutOfRangeException(nameof(port));
58+
if (port is < 0 or > 65535) throw new ArgumentOutOfRangeException(nameof(port));
6059

6160
Port = port;
6261

@@ -137,7 +136,7 @@ public async Task Connect()
137136
_heartbeatDisposable = Observable.Interval(_heartbeatInerval).DoWhile(() => !IsDisposed)
138137
.Subscribe(x => SendHeartbeat());
139138
}
140-
catch(Exception ex)
139+
catch (Exception ex)
141140
{
142141
var connectionException = new ConnectionException(ex);
143142

@@ -173,7 +172,7 @@ public IDisposable Subscribe(IObserver<IMessage> observer)
173172
public async Task SendMessage<T>(T message, string clientMsgId = null) where T : IMessage
174173
{
175174
var protoMessage = MessageFactory.GetMessage(message.GetPayloadType(), message.ToByteString(), clientMsgId);
176-
175+
177176
await SendMessage(protoMessage);
178177
}
179178

@@ -439,7 +438,7 @@ private async void ReadTcp(CancellationToken cancellationToken)
439438
private int GetLength(byte[] lengthBytes)
440439
{
441440
var lengthSpan = lengthBytes.AsSpan();
442-
441+
443442
lengthSpan.Reverse();
444443

445444
return BitConverter.ToInt32(lengthSpan);

0 commit comments

Comments
 (0)