Skip to content

Commit dc73c83

Browse files
committed
initial commit
0 parents  commit dc73c83

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+25551
-0
lines changed

.gitignore

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
bin
2+
obj
3+
.vs
4+
*.user
5+
packages
6+
*.csv
7+
.vs/RabbitAPI/v16/Server/sqlite3/storage.ide-wal
8+
.vs/RabbitAPI/v16/.suo
9+
.vs/RabbitAPI/v16/Server/sqlite3/storage.ide
10+
.vs/RabbitAPI/v16/Server/sqlite3/storage.ide-shm
11+
.vs/RabbitAPI/v16/Server/sqlite3/storage.ide-wal
12+
.pdb
13+
/BackEnd/obj/Debug
14+
logs
15+
.idea
16+
*.json
17+
18+
/OrderBookChecker/trades
19+
/OrderBookChecker/Debug
20+
/ConsoleApp/trades
21+
*.xlsx
22+
*.txt
23+
24+
/BackEnd/VSdoc
25+
*.xml
26+
/VSdoc
27+
/RabbitAPI.sln.vsdoc
28+
/Configs
29+
/ConsoleApp/Configs
30+
/parameters.json
31+
/documentation
32+
/Dispatcher/gui/convert_ui.bat
33+
/Dispatcher/gui/GUI.ui
34+
/Dispatcher/gui/__pycache__
35+
/Dispatcher/__pycache__
36+
/Dispatcher/__pycache__/Dispatcher.cpython-37.pyc
37+
/Dispatcher/__pycache__/Robot.cpython-37.pyc
38+
/Dispatcher/__pycache__/__init__.cpython-37.pyc
39+
/Dispatcher/__pycache__/commands.cpython-37.pyc
40+
*.pyc
41+
/Dispatcher/source/messages/protoc.exe
42+
/Dispatcher/source/messages/proto_convert_client.bat
43+
/Dispatcher/source/messages/proto_convert_server.bat
44+
/OuterDispatcher/gui/convert_ui.bat
45+
/OuterDispatcher/source/messages/protoc.exe
46+
/OuterDispatcher/source/messages/proto_convert_client.bat
47+
/OuterDispatcher/source/messages/proto_convert_server.bat
48+
/WebDispatcherCore3.0/Properties/PublishProfiles
49+
/WebDispatcherD/WebDispatcherD.db
50+
/WebDispatcherD/AppData/TradingData.db
51+
/WebDispatcherD/AppData/WebDispatcherD.db
52+
/WebDispatcherD/AppData/TradingData.db-shm
53+
/WebDispatcherD/AppData/TradingData.db-wal
54+
/WebDispatcherD/AdamsMMTradingData.db
55+
/WebDispatcherD/AppData/WebDispatcherD.db-shm
56+
/WebDispatcherD/AppData/WebDispatcherD.db-wal
57+
/proto_convert.bat
58+
/protoc.exe
59+
/DigitexConnector/EngineAPI/protoc.exe
60+
/DigitexConnector/EngineAPI/proto_convert.bat
61+
/DigitexConnector/EngineAPI/messages-public.proto

DigitexConnector/DWConverter.cs

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
using System;
2+
using DigitexWire;
3+
using Google.Protobuf;
4+
5+
namespace DigitexConnector.Extentions
6+
{
7+
/// <summary>
8+
/// Class with methods of conversion.
9+
/// </summary>
10+
public static class DWConverter
11+
{
12+
/// <summary>
13+
/// Create message for send to exchange.
14+
/// </summary>
15+
/// <param name="oneOfContent"><see cref="Message"/></param>
16+
/// <param name="marketId">Id of current market.</param>
17+
/// <param name="clientId">Id of message to send.</param>
18+
/// <param name="traderId">Identificator of trader (ain't necessary in stock version of connector - set to 0)</param>
19+
/// <returns>Message to send. <see cref="Message"/></returns>
20+
static public Message BuildMessage(IMessage oneOfContent, uint marketId, Guid clientId, uint traderId)
21+
{
22+
Message masterMessage = new Message();
23+
//switch (slaveMessage.GetType().ToString())
24+
if (oneOfContent.GetType() == typeof(PlaceOrderMessage))
25+
{ masterMessage.PlaceOrderMsg = ((PlaceOrderMessage)oneOfContent).Clone(); }
26+
else if (oneOfContent.GetType() == typeof(CancelOrderMessage))
27+
{ masterMessage.CancelOrderMsg = ((CancelOrderMessage)oneOfContent).Clone(); }
28+
else if (oneOfContent.GetType() == typeof(CancelAllOrdersMessage))
29+
{ masterMessage.CancelAllOrdersMsg = ((CancelAllOrdersMessage)oneOfContent).Clone(); }
30+
else if (oneOfContent.GetType() == typeof(OrderStatusMessage))
31+
{ masterMessage.OrderStatusMsg = ((OrderStatusMessage)oneOfContent).Clone(); }
32+
else if (oneOfContent.GetType() == typeof(OrderFilledMessage))
33+
{ masterMessage.OrderFilledMsg = ((OrderFilledMessage)oneOfContent).Clone(); }
34+
else if (oneOfContent.GetType() == typeof(ChangeLeverageAllMessage))
35+
{ masterMessage.ChangeLeverageAllMsg = ((ChangeLeverageAllMessage)oneOfContent).Clone(); }
36+
else if (oneOfContent.GetType() == typeof(GetTraderStatusMessage))
37+
{ masterMessage.GetTraderStatusMsg = ((GetTraderStatusMessage)oneOfContent).Clone(); }
38+
else if (oneOfContent.GetType() == typeof(OrderBookRequestMessage))
39+
{ masterMessage.OrderBookRequestMsg = ((OrderBookRequestMessage)oneOfContent).Clone(); }
40+
else if (oneOfContent.GetType() == typeof(GetMarketStateMessage))
41+
{ masterMessage.GetMarketStateMsg = ((GetMarketStateMessage)oneOfContent).Clone(); }
42+
else
43+
{ throw new FormatException($"Message Type \"{oneOfContent.GetType()}\" does not exist"); }
44+
45+
masterMessage.Timestamp = DateTime.Now.Ticks;
46+
masterMessage.Serial = 0;
47+
masterMessage.MarketId = marketId;
48+
masterMessage.TraderId = traderId;
49+
masterMessage.ClientId = ByteString.CopyFrom(clientId.ToByteArray());
50+
return masterMessage;
51+
}
52+
53+
/// <summary>
54+
/// Convert System.Decimal type to DigitexWire.Decimal.
55+
/// </summary>
56+
/// <param name="decValue">Original value.</param>
57+
/// <returns>Value converted to DigitexWire.Decimal. <see cref="DigitexWire.Decimal"/></returns>
58+
static public DigitexWire.Decimal ToProtoDecimal(decimal decValue)
59+
{
60+
uint scale = 0;
61+
decimal reminder = decValue % 1;
62+
long value64 = (long)(decValue - reminder);
63+
while (reminder != 0)
64+
{
65+
reminder *= 10;
66+
value64 *= 10;
67+
scale += 1;
68+
value64 += (long)(reminder - (reminder % 1));
69+
reminder %= 1;
70+
}
71+
DigitexWire.Decimal value = new DigitexWire.Decimal();
72+
value.Value64 = value64;
73+
value.Scale = scale;
74+
return value;
75+
}
76+
77+
/// <summary>
78+
/// Convert DigitexWire.Decimal to System.Decimal.
79+
/// </summary>
80+
/// <param name="value">Original DigitexWire.Decimal value. <see cref="DigitexWire.Decimal"/></param>
81+
/// <returns>Value converted to System.Decimal.</returns>
82+
static public decimal FromProtoDecimal(DigitexWire.Decimal value)
83+
{
84+
return value == null ? 0 : (decimal)(value.Value64 * Math.Pow(10, -value.Scale));
85+
}
86+
87+
/// <summary>
88+
/// Convert Google.Protobuf.ByteString guid, using in DigitexWire, to System.Guid.
89+
/// </summary>
90+
/// <param name="guid">Original Google.Protobuf.ByteString value.</param>
91+
/// <returns>Value converted to System.Guid.</returns>
92+
static public Guid FromProtoUuid(ByteString uuid)
93+
{
94+
if (uuid.IsEmpty)
95+
{
96+
return Guid.Empty;
97+
}
98+
byte[] bytes = uuid.ToByteArray();
99+
byte[] newBytes = new byte[]
100+
{
101+
bytes[3],
102+
bytes[2],
103+
bytes[1],
104+
bytes[0],
105+
bytes[5],
106+
bytes[4],
107+
bytes[7],
108+
bytes[6],
109+
bytes[8],
110+
bytes[9],
111+
bytes[10],
112+
bytes[11],
113+
bytes[12],
114+
bytes[13],
115+
bytes[14],
116+
bytes[15],
117+
};
118+
return new Guid(newBytes);
119+
}
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+
167+
static public Guid GuidToUuid(Guid guid)
168+
{
169+
byte[] bytes = guid.ToByteArray();
170+
byte[] newBytes = new byte[]
171+
{
172+
bytes[3],
173+
bytes[2],
174+
bytes[1],
175+
bytes[0],
176+
bytes[5],
177+
bytes[4],
178+
bytes[7],
179+
bytes[6],
180+
bytes[8],
181+
bytes[9],
182+
bytes[10],
183+
bytes[11],
184+
bytes[12],
185+
bytes[13],
186+
bytes[14],
187+
bytes[15],
188+
};
189+
return new Guid(newBytes);
190+
}
191+
192+
/// <summary>
193+
/// Convert long Timestamp value to System.DateTime./>
194+
/// </summary>
195+
/// <param name="time">Original long Timestamp value.</param>
196+
/// <returns>Value converted to System.DateTime.</returns>
197+
static public DateTime FromLongDateTime(long time)
198+
{
199+
return (new DateTime(1970, 1, 1) + TimeSpan.FromMilliseconds(time / 1000)).ToLocalTime();
200+
}
201+
}
202+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
7+
<PackageId>DigitexConnectorCSharp</PackageId>
8+
<Version>0.8.2</Version>
9+
<Authors>Vitaliy Artemov, Daria Korepanova</Authors>
10+
<Company>SmartDec</Company>
11+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
12+
<RepositoryURL>https://github.com/smartdec/DigitexConnectorCSharp</RepositoryURL>
13+
<PackageTags>digitex</PackageTags>
14+
<Title>Digitex Connector</Title>
15+
<Description>Library for connect to Digitex Futures Exchange</Description>
16+
</PropertyGroup>
17+
18+
<ItemGroup>
19+
<None Remove="Symbols.json" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<PackageReference Include="Google.Protobuf" Version="3.13.0" />
24+
<PackageReference Include="NLog" Version="4.7.4" />
25+
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
26+
<PackageReference Include="Websocket.Client" Version="4.3.21" />
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<None Include="Symbols.json">
31+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
32+
</None>
33+
</ItemGroup>
34+
35+
<ItemGroup>
36+
<None Update="NLog.config">
37+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
38+
</None>
39+
</ItemGroup>
40+
41+
</Project>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
3+
namespace DigitexConnector.EngineAPI
4+
{
5+
/// <summary>
6+
/// Common fields for all meassages received in Executor via ctl channel.
7+
/// </summary>
8+
public class CommonFields
9+
{
10+
/// <summary>
11+
/// Id of specidif trader.
12+
/// </summary>
13+
public uint TraderId { get; protected set; }
14+
/// <summary>
15+
/// Order id.
16+
/// </summary>
17+
public Guid ClientId { get; protected set; }
18+
/// <summary>
19+
/// Symbol.
20+
/// </summary>
21+
public Symbol Symbol { get; protected set; }
22+
/// <summary>
23+
/// Margin of position.
24+
/// </summary>
25+
public decimal PositionMargin { get; protected set; }
26+
/// <summary>
27+
/// Margin of all orders.
28+
/// </summary>
29+
public decimal OrderMargin { get; protected set; }
30+
/// <summary>
31+
/// Balance of trader.
32+
/// </summary>
33+
public decimal TraderBalance { get; protected set; }
34+
/// <summary>
35+
/// Unrealized profit and loss.
36+
/// </summary>
37+
public decimal? Upnl { get; protected set; }
38+
/// <summary>
39+
/// Realized profit and loss.
40+
/// </summary>
41+
public decimal? Pnl { get; protected set; }
42+
/// <summary>
43+
/// Margin of buy orders.
44+
/// </summary>
45+
public decimal BuyOrderMargin { get; protected set; }
46+
/// <summary>
47+
/// Margin of buy orders.
48+
/// </summary>
49+
public decimal SellOrderMargin { get; protected set; }
50+
/// <summary>
51+
/// Accum quantity.
52+
/// </summary>
53+
public decimal AccumQuantity { get; protected set; }
54+
/// <summary>
55+
/// Quantity of all active long orders.
56+
/// </summary>
57+
public decimal BuyOrderQuantity { get; protected set; }
58+
/// <summary>
59+
/// Quantity of all active short orders.
60+
/// </summary>
61+
public decimal SellOrderQuantity { get; protected set; }
62+
}
63+
64+
}

0 commit comments

Comments
 (0)