Skip to content

Commit f482195

Browse files
committed
update to version 0.8.5
1 parent a0af4d6 commit f482195

14 files changed

+207
-79
lines changed

DigitexConnector/Configuration.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using DigitexConnector.Enums;
2+
3+
namespace DigitexConnector
4+
{
5+
public static class Configuration
6+
{
7+
public static Servers? Server;
8+
public static string Token { set; internal get; }
9+
}
10+
}

DigitexConnector/DWConverter.cs

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -117,53 +117,7 @@ static public Guid FromProtoUuid(ByteString uuid)
117117
};
118118
return new Guid(newBytes);
119119
}
120-
121-
static public Guid FromOpenAPIUUID(string uuid)
122-
{
123-
char[] charArray = uuid.ToCharArray();
124-
char[] resultArray = new char[]
125-
{
126-
charArray[6],
127-
charArray[7],
128-
charArray[4],
129-
charArray[5],
130-
charArray[2],
131-
charArray[3],
132-
charArray[0],
133-
charArray[1],
134-
charArray[8],
135-
charArray[11],
136-
charArray[12],
137-
charArray[9],
138-
charArray[10],
139-
charArray[13],
140-
charArray[16],
141-
charArray[17],
142-
charArray[14],
143-
charArray[15],
144-
charArray[18],
145-
charArray[19],
146-
charArray[20],
147-
charArray[21],
148-
charArray[22],
149-
charArray[23],
150-
charArray[24],
151-
charArray[25],
152-
charArray[26],
153-
charArray[27],
154-
charArray[28],
155-
charArray[29],
156-
charArray[30],
157-
charArray[31],
158-
charArray[32],
159-
charArray[33],
160-
charArray[34],
161-
charArray[35]
162-
};
163-
string guid = new string(charArray);
164-
return new Guid(guid);
165-
}
166-
120+
167121
static public Guid GuidToUuid(Guid guid)
168122
{
169123
byte[] bytes = guid.ToByteArray();

DigitexConnector/DigitexConnector.csproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
66
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
77
<PackageId>DigitexConnectorCSharp</PackageId>
8-
<Version>0.8.3</Version>
9-
<Authors>Vitaliy Artemov, Daria Korepanova</Authors>
8+
<Version>0.8.5</Version>
9+
<Authors>SmartDec https://smartdec.com/</Authors>
1010
<Company>SmartDec</Company>
1111
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1212
<RepositoryURL>https://github.com/smartdec/DigitexConnectorCSharp</RepositoryURL>
13-
<PackageTags>digitex</PackageTags>
13+
<PackageTags>Digitex, DigitexFutures, Algotrading, Exchange</PackageTags>
1414
<Title>Digitex Connector</Title>
1515
<Description>Library for connect to Digitex Futures Exchange</Description>
16+
<PackageIcon>icon.png</PackageIcon>
1617
</PropertyGroup>
1718

1819
<ItemGroup>
1920
<None Remove="Symbols.json" />
21+
<None Include="icon.png" Pack="true" PackagePath="\"/>
2022
</ItemGroup>
2123

2224
<ItemGroup>

DigitexConnector/EngineAPI/DigitexConnection.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using NLog;
88
using DigitexConnector.Interfaces;
99
using System.Collections.Generic;
10+
using DigitexConnector.Enums;
1011

1112
namespace DigitexConnector.EngineAPI
1213
{
@@ -129,6 +130,24 @@ public DigitexConnection(string hostName, string token, bool secureConnection)
129130
Init();
130131
}
131132

133+
public DigitexConnection(Servers? server, string token)
134+
{
135+
_transport = new WebsocketsTransport(server, token);
136+
Init();
137+
}
138+
139+
public DigitexConnection(string token)
140+
{
141+
_transport = new WebsocketsTransport(token);
142+
Init();
143+
}
144+
145+
public DigitexConnection()
146+
{
147+
_transport = new WebsocketsTransport();
148+
Init();
149+
}
150+
132151
private void Init()
133152
{
134153
_transport.MessageReceived += ReceiveMessage;

DigitexConnector/EngineAPI/WebsocketsTransport.cs

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using System.Net.WebSockets;
55
using NLog;
66
using DigitexConnector.Interfaces;
7+
using DigitexConnector.Enums;
8+
using System.Collections.Generic;
79

810
namespace DigitexConnector.EngineAPI
911
{
@@ -54,13 +56,67 @@ public class WebsocketsTransport : ITransport, IDisposable
5456
/// </summary>
5557
public event Action ControlDisconnected;
5658

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+
5765
/// <summary>
58-
/// Constructor.
66+
/// Use this constructor to provide directly host name.
5967
/// </summary>
6068
/// <param name="hostName">Exchange address.</param>
61-
/// <param name="token">Trader's JWT.</param>
69+
/// <param name="token">API-token.</param>
6270
/// <param name="secureConnection">True if connection is secure else false.</param>
6371
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)
64120
{
65121
HostName = hostName;
66122
Token = token;

DigitexConnector/Enums.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace DigitexConnector.Enums
2+
{
3+
public enum Servers { testnet, mainnet, }
4+
5+
public enum Markets { BTC_USD, ETH_USD, XRP_USD, DGTX_ETH, XAU_USD, EUR_USD, BTC_USD1, USD_JPY, }
6+
}

DigitexConnector/Symbols.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
"QuantityStep": 1
3131
},
3232
{
33-
"MarketId": 7,
34-
"Name": "EUR/USD",
35-
"PriceStep": 0.0001,
36-
"QuantityStep": 1
33+
"MarketId": 7,
34+
"Name": "EUR/USD",
35+
"PriceStep": 0.0001,
36+
"QuantityStep": 1
3737
},
3838
{
3939
"MarketId": 9,
@@ -46,5 +46,5 @@
4646
"Name": "USD/JPY",
4747
"PriceStep": 0.01,
4848
"QuantityStep": 1
49-
},
49+
}
5050
]}

DigitexConnector/Trading/Aggregator.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
using DigitexWire;
55
using DigitexConnector.EngineAPI;
66
using System.Threading;
7-
using NLog;
87
using DigitexConnector.Interfaces;
98
using System.Linq;
9+
using DigitexConnector.Enums;
1010

1111
namespace DigitexConnector.Trading
1212
{
@@ -65,8 +65,6 @@ public class Aggregator : IAggregator
6565

6666
public event Action<OrderCanceledData> OrderCancelError;
6767

68-
private Logger _logger = LogManager.GetCurrentClassLogger();
69-
7068
public Aggregator(IConnection connection)
7169
{
7270
_connection = connection;
@@ -82,6 +80,30 @@ public Aggregator(string hostName, string token, bool secureConnection)
8280
_receiver = new Receiver(Orders, ordersLock);
8381
Init();
8482
}
83+
84+
public Aggregator(Servers? server, string token)
85+
{
86+
_connection = new DigitexConnection(server, token);
87+
_sender = new Sender(Orders, TrailingOrders, _connection, ordersLock, trailingsLock);
88+
_receiver = new Receiver(Orders, ordersLock);
89+
Init();
90+
}
91+
92+
public Aggregator(string token)
93+
{
94+
_connection = new DigitexConnection(token);
95+
_sender = new Sender(Orders, TrailingOrders, _connection, ordersLock, trailingsLock);
96+
_receiver = new Receiver(Orders, ordersLock);
97+
Init();
98+
}
99+
100+
public Aggregator()
101+
{
102+
_connection = new DigitexConnection();
103+
_sender = new Sender(Orders, TrailingOrders, _connection, ordersLock, trailingsLock);
104+
_receiver = new Receiver(Orders, ordersLock);
105+
Init();
106+
}
85107

86108
private void Init()
87109
{

DigitexConnector/EngineAPI/TradingAdapter.cs renamed to DigitexConnector/Trading/TradingAdapter.cs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
using System.Collections.Generic;
33
using DigitexWire;
44
using DigitexConnector.Orders;
5-
using DigitexConnector.Trading;
5+
using DigitexConnector.EngineAPI;
66
using DigitexConnector.Interfaces;
7+
using DigitexConnector.Enums;
78

8-
namespace DigitexConnector.EngineAPI
9+
namespace DigitexConnector.Trading
910
{
1011
/// <summary>
1112
/// Main class for trading.
@@ -93,17 +94,47 @@ public TradingAdapter(IAggregator account)
9394
}
9495

9596
/// <summary>
96-
/// Constructor.
97+
/// Use this constructor for set hostName and token directly.
9798
/// </summary>
9899
/// <param name="hostName">Address of exchange without prefix.</param>
99-
/// <param name="token">Your API-token.</param>
100-
/// <param name="secureConnection">Use ssh.</param>
100+
/// <param name="token">API-token.</param>
101+
/// <param name="secureConnection">Use (true) ssh or not (false).</param>
101102
public TradingAdapter(string hostName, string token, bool secureConnection)
102103
{
103104
Account = new Aggregator(hostName, token, secureConnection);
104105
Init();
105106
}
106107

108+
/// <summary>
109+
/// Use this constructor for set one of two servers and set token directly.
110+
/// </summary>
111+
/// <param name="server"><see cref="Servers"/></param>
112+
/// <param name="token">API-token.</param>
113+
public TradingAdapter(Servers? server, string token)
114+
{
115+
Account = new Aggregator(server, token);
116+
Init();
117+
}
118+
119+
/// <summary>
120+
/// Use this constructor for set token directly and if <see cref="Configuration.Server"/> is set.
121+
/// </summary>
122+
/// <param name="token">API-token.</param>
123+
public TradingAdapter(string token)
124+
{
125+
Account = new Aggregator(token);
126+
Init();
127+
}
128+
129+
/// <summary>
130+
/// Use this constructor if <see cref="Configuration.Server"/> and <see cref="Configuration.Token"/> are set.
131+
/// </summary>
132+
public TradingAdapter()
133+
{
134+
Account = new Aggregator();
135+
Init();
136+
}
137+
107138
private void Init()
108139
{
109140
Account.Connected += OnAccountConnectedHandler;

DigitexConnector/Trading/TradingAlgorithm.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Collections.Generic;
2-
using DigitexConnector.EngineAPI;
2+
using DigitexConnector.Enums;
33
using DigitexConnector.Interfaces;
44

55
namespace DigitexConnector.Trading
@@ -9,6 +9,12 @@ namespace DigitexConnector.Trading
99
/// </summary>
1010
public abstract class TradingAlgorithm : TradingAdapter
1111
{
12+
/// <summary>
13+
/// Use this constructor for set hostName and token directly.
14+
/// </summary>
15+
/// <param name="hostName">Address of exchange without prefix.</param>
16+
/// <param name="token">API-token.</param>
17+
/// <param name="secureConnection">Use (true) ssh or not (false).</param>
1218
public TradingAlgorithm(string hostName, string token, bool secureConnection)
1319
: base(hostName, token, secureConnection)
1420
{ }
@@ -17,6 +23,30 @@ public TradingAlgorithm(IAggregator account)
1723
: base(account)
1824
{ }
1925

26+
// <summary>
27+
/// Use this constructor for set one of two servers and set token directly.
28+
/// </summary>
29+
/// <param name="server"><see cref="Servers"/></param>
30+
/// <param name="token">API-token.</param>
31+
public TradingAlgorithm(Servers? server, string token)
32+
: base(server, token)
33+
{ }
34+
35+
/// <summary>
36+
/// Use this constructor for set token directly and if <see cref="Configuration.Server"/> is set.
37+
/// </summary>
38+
/// <param name="token">API-token.</param>
39+
public TradingAlgorithm(string token)
40+
: base(token)
41+
{ }
42+
43+
/// <summary>
44+
/// Use this constructor if <see cref="Configuration.Server"/> and <see cref="Configuration.Token"/> are set.
45+
/// </summary>
46+
public TradingAlgorithm()
47+
: base()
48+
{ }
49+
2050
/// <summary>
2151
/// Method that called before trading.
2252
/// </summary>

0 commit comments

Comments
 (0)