-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
114 lines (98 loc) · 3.43 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
namespace Xtb.XApi.SystemTests;
internal static class Program
{
public const string HostIPAddressString = "81.2.190.163";
public const int DemoRequestingPort = 5124;
public const int DemoStreamingPort = 5125;
public const int RealRequestingPort = 5112;
public const int RealStreamingPort = 5113;
public static IPAddress HostIPAddress => IPAddress.Parse(HostIPAddressString);
public static IPEndPoint DemoRequestingEndpoint => new(HostIPAddress, DemoRequestingPort);
public static IPEndPoint DemoStreamingEndpoint => new(HostIPAddress, DemoStreamingPort);
public static IPEndPoint RealRequestingEndpoint => new(HostIPAddress, RealRequestingPort);
public static IPEndPoint RealStreamingEndpoint => new(HostIPAddress, RealStreamingPort);
private static string _userId = "16697884";
private static string _password = "xoh11724";
private static void Main(string[] args)
{
//using (var connector = new Connector(DemoRequestingEndpoint))
//{
// RunConnectorTest(connector);
//}
//Console.WriteLine();
using (var xApiClient = XApiClient.Create(DemoRequestingEndpoint, DemoStreamingEndpoint))
{
RunSyncTest(xApiClient);
}
Console.WriteLine();
using (var xApiClient = XApiClient.Create(DemoRequestingEndpoint, DemoStreamingEndpoint))
{
RunAsyncTest(xApiClient);
}
Console.WriteLine("**** Done ****");
Console.Read();
}
private static void RunConnectorTest(Connector connector)
{
Console.WriteLine("----Connector test---");
var connectorTest = new ConnectorTest(connector, _userId, _password);
connectorTest.Run();
}
private static void RunSyncTest(XApiClient xApiClient)
{
Console.WriteLine();
Console.WriteLine("----Sync test---");
var syncTest = new SyncTest(xApiClient, _userId, _password)
{
ShallLogTime = true,
ShallOpenTrades = false,
};
syncTest.Run();
}
private static void RunAsyncTest(XApiClient xApiClient)
{
Console.WriteLine("----Async test---");
Console.WriteLine("(esc) abort");
var asyncTest = new AsyncTest(xApiClient, _userId, _password)
{
MessageFolder = @"\messages\",
ShallLogTime = true,
ShallOpenTrades = false,
};
using var tokenSource = new CancellationTokenSource();
var keyWaitTask = Task.Run(() =>
{
while (!tokenSource.Token.IsCancellationRequested)
{
if (Console.KeyAvailable)
{
var key = Console.ReadKey(intercept: true);
if (key.Key == ConsoleKey.Escape)
{
tokenSource.Cancel();
Console.WriteLine("Operation aborted.");
break;
}
}
Thread.Sleep(100);
}
});
try
{
asyncTest.RunAsync(tokenSource.Token).GetAwaiter().GetResult();
}
catch (OperationCanceledException)
{
Console.WriteLine("Operation was canceled.");
}
finally
{
tokenSource.Cancel();
keyWaitTask.Wait();
}
}
}