diff --git a/Examples/MtApi5Samples/HistoryOrderSample/HistoryOrderSample.csproj b/Examples/MtApi5Samples/HistoryOrderSample/HistoryOrderSample.csproj new file mode 100755 index 00000000..39193259 --- /dev/null +++ b/Examples/MtApi5Samples/HistoryOrderSample/HistoryOrderSample.csproj @@ -0,0 +1,22 @@ + + + + Exe + net8.0 + enable + enable + + + + + ..\..\..\build\products\Release\net8.0\MtApi5.dll + + + ..\..\..\build\products\Release\net8.0\MtClient.dll + + + ..\..\..\build\products\Release\net8.0\Newtonsoft.Json.dll + + + + diff --git a/Examples/MtApi5Samples/HistoryOrderSample/Program.cs b/Examples/MtApi5Samples/HistoryOrderSample/Program.cs new file mode 100755 index 00000000..811213e7 --- /dev/null +++ b/Examples/MtApi5Samples/HistoryOrderSample/Program.cs @@ -0,0 +1,62 @@ +using MtApi5; + +static DateTime UnixTimeStampToDateTime(long unixTimeStamp) +{ + // Unix timestamp is seconds past epoch + DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); + dateTime = dateTime.AddSeconds(unixTimeStamp).ToLocalTime(); + return dateTime; +} + +const string HOST = "localhost"; +const int PORT = 8228; +const int HISTORY_DAYS = 20; + +var client = new MtApi5Client(); + +Console.WriteLine("Start history test"); + +try +{ + client.Connect(HOST, PORT).Wait(); +} +catch (Exception e) +{ + Console.WriteLine($"Connection failed: {e.Message}"); + return; +} + +Console.WriteLine($"Connected to {HOST}:{PORT}"); + +var to = DateTime.Now; +var from = to.AddDays(-HISTORY_DAYS); +if (client.HistorySelect(from, to)) +{ + var orders = client.HistoryOrdersTotal(); + Console.WriteLine($"Order count: {orders}"); + + for (int i = 0; i < orders; i++) + { + var ticket = client.HistoryOrderGetTicket(i); + + var order_type = (ENUM_ORDER_TYPE) client.HistoryOrderGetInteger(ticket, ENUM_ORDER_PROPERTY_INTEGER.ORDER_TYPE); + long time_setup_msc = client.HistoryOrderGetInteger(ticket, ENUM_ORDER_PROPERTY_INTEGER.ORDER_TIME_SETUP_MSC); + long time_done_msc = client.HistoryOrderGetInteger(ticket, ENUM_ORDER_PROPERTY_INTEGER.ORDER_TIME_DONE_MSC); + double order_open_price = client.HistoryOrderGetDouble(ticket, ENUM_ORDER_PROPERTY_DOUBLE.ORDER_PRICE_OPEN); + double order_volume = client.HistoryOrderGetDouble(ticket, ENUM_ORDER_PROPERTY_DOUBLE.ORDER_VOLUME_INITIAL); + + Console.WriteLine($"{i + 1} - Order #{ticket} type = {order_type}" + + $" ORDER_TIME_SETUP_MSC={time_setup_msc} => {UnixTimeStampToDateTime(time_setup_msc / 1000)}," + + $" ORDER_TIME_DONE_MSC={time_done_msc} => {UnixTimeStampToDateTime(time_done_msc / 1000)}," + + $" Open price = {order_open_price}, Volume = {order_volume}"); + } +} +else +{ + var last_error = client.GetLastError(); + Console.WriteLine($"Failed to select order history. ErrorCode = {last_error}"); +} + +Console.WriteLine("History test completed."); + +client.Disconnect(); \ No newline at end of file diff --git a/Examples/MtApi5Samples/MtApi5Samples.sln b/Examples/MtApi5Samples/MtApi5Samples.sln new file mode 100755 index 00000000..6e605e73 --- /dev/null +++ b/Examples/MtApi5Samples/MtApi5Samples.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34622.214 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HistoryOrderSample", "HistoryOrderSample\HistoryOrderSample.csproj", "{AE42346D-347D-43E4-B0C8-A0BF7E506A5E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AE42346D-347D-43E4-B0C8-A0BF7E506A5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AE42346D-347D-43E4-B0C8-A0BF7E506A5E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AE42346D-347D-43E4-B0C8-A0BF7E506A5E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AE42346D-347D-43E4-B0C8-A0BF7E506A5E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3C1DF1F1-13BF-4CE2-9F74-F39548D21ABE} + EndGlobalSection +EndGlobal