|
4 | 4 | using System.Net.WebSockets;
|
5 | 5 | using NLog;
|
6 | 6 | using DigitexConnector.Interfaces;
|
| 7 | +using DigitexConnector.Enums; |
| 8 | +using System.Collections.Generic; |
7 | 9 |
|
8 | 10 | namespace DigitexConnector.EngineAPI
|
9 | 11 | {
|
@@ -54,13 +56,67 @@ public class WebsocketsTransport : ITransport, IDisposable
|
54 | 56 | /// </summary>
|
55 | 57 | public event Action ControlDisconnected;
|
56 | 58 |
|
| 59 | + private Dictionary<Servers?, string> HostNames = new Dictionary<Servers?, string>() |
| 60 | + { |
| 61 | + { Servers.testnet, "ws.testnet.digitexfutures.com" }, |
| 62 | + { Servers.mainnet, "ws.mainnet.digitexfutures.com" }, |
| 63 | + }; |
| 64 | + |
57 | 65 | /// <summary>
|
58 |
| - /// Constructor. |
| 66 | + /// Use this constructor to provide directly host name. |
59 | 67 | /// </summary>
|
60 | 68 | /// <param name="hostName">Exchange address.</param>
|
61 |
| - /// <param name="token">Trader's JWT.</param> |
| 69 | + /// <param name="token">API-token.</param> |
62 | 70 | /// <param name="secureConnection">True if connection is secure else false.</param>
|
63 | 71 | public WebsocketsTransport(string hostName, string token, bool secureConnection = true)
|
| 72 | + { |
| 73 | + Init(hostName, token, secureConnection); |
| 74 | + } |
| 75 | + |
| 76 | + /// <summary> |
| 77 | + /// Use this constructor to provide testnet or mainnet host names. |
| 78 | + /// </summary> |
| 79 | + /// <param name="server"><see cref="Servers"/></param> |
| 80 | + /// <param name="token">API-token</param> |
| 81 | + public WebsocketsTransport(Servers? server, string token) |
| 82 | + { |
| 83 | + if (server is null) |
| 84 | + { |
| 85 | + throw new ArgumentNullException("server", "Server is not set."); |
| 86 | + } |
| 87 | + Init(HostNames[server], token, true); |
| 88 | + } |
| 89 | + |
| 90 | + /// <summary> |
| 91 | + /// Use this constructor if <see cref="Configuration.Server"/> is set. |
| 92 | + /// </summary> |
| 93 | + /// <param name="token">API-token.</param> |
| 94 | + public WebsocketsTransport(string token) |
| 95 | + { |
| 96 | + if (Configuration.Server is null) |
| 97 | + { |
| 98 | + throw new ArgumentNullException("DigitexConnector.Configuration.Server", "Server is not set."); |
| 99 | + } |
| 100 | + Init(HostNames[Configuration.Server], token, true); |
| 101 | + } |
| 102 | + |
| 103 | + /// <summary> |
| 104 | + /// Use this constructor if <see cref="Configuration.Server"/> and <see cref="Configuration.Token"/> are set. |
| 105 | + /// </summary> |
| 106 | + public WebsocketsTransport() |
| 107 | + { |
| 108 | + if (Configuration.Server is null) |
| 109 | + { |
| 110 | + throw new ArgumentNullException("DigitexConnector.Configuration.Server", "Server is not set."); |
| 111 | + } |
| 112 | + if (Configuration.Token is null) |
| 113 | + { |
| 114 | + throw new ArgumentNullException("DigitexConnector.Configuration.Token", "Token is not set."); |
| 115 | + } |
| 116 | + Init(HostNames[Configuration.Server], Configuration.Token, true); |
| 117 | + } |
| 118 | + |
| 119 | + private void Init(string hostName, string token, bool secureConnection) |
64 | 120 | {
|
65 | 121 | HostName = hostName;
|
66 | 122 | Token = token;
|
|
0 commit comments