-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
44 lines (34 loc) · 1.57 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Security.Cryptography;
using System.Text;
using CtraderApi;
using CtraderApi.Helpers;
using Google.Protobuf;
using Microsoft.Extensions.Configuration;
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
var appSettings = configuration.GetSection("TradePlatform:Credentials:45");
var proxyHost = appSettings["Host"].ThrowIfNull();
var proxyPort = int.Parse(appSettings["Port"].ThrowIfNull());
var plantId = appSettings["PlantId"].ThrowIfNull();
var environmentName = appSettings["EnvironmentName"].ThrowIfNull();
var login = long.Parse(appSettings["Login"].ThrowIfNull());
var password = appSettings["Password"].ThrowIfNull();
var client = new CtraderManagerApiClient(proxyHost, proxyPort);
client.MessageWithoutIdReceived += OnMessageWithoutIdReceived;
client.Error += OnException;
await client.Connect();
var applicationAuthReq = new ProtoManagerAuthReq
{
PlantId = plantId,
EnvironmentName = environmentName,
Login = login,
PasswordHash = Convert.ToHexString(MD5.HashData(Encoding.ASCII.GetBytes(password))).ToLower()
};
await client.SendMessage<ProtoManagerAuthReq, ProtoManagerAuthRes>(applicationAuthReq);
var response = await client.SendMessage<ProtoManagerSymbolListReq, ProtoManagerSymbolListRes>(
new ProtoManagerSymbolListReq());
Console.WriteLine(response.PayloadType);
static void OnMessageWithoutIdReceived(IMessage message) =>
Console.WriteLine($"Message received -> {message.GetPayloadType()}");
static void OnException(Exception e) => Console.WriteLine($"\n{DateTime.Now}: Exception\n: {e}");