From f13e9f69405cf1df0ce8a22f485614c52e11ea7b Mon Sep 17 00:00:00 2001 From: "yahor.mazko" Date: Fri, 27 Sep 2024 12:39:41 +0300 Subject: [PATCH] Add close price to trade close operation --- TTWebClient/Domain/TTTrade.cs | 5 +++- TTWebClient/TTWebClient.csproj | 2 +- TTWebClient/app.config | 12 +++++----- TTWebClientRobot/App.config | 10 ++++---- TTWebClientRobot/TTWebClientRobot.csproj | 2 +- TTWebClientSample/App.config | 10 ++++---- TTWebClientSample/TTWebClientSample.csproj | 2 +- TTWebClientUI/App.config | 10 ++++---- TTWebClientUI/ClientView.cs | 23 +++++++++++++++++++ TTWebClientUI/MainWindow.xaml | 14 +++++++---- .../Properties/Resources.Designer.cs | 2 +- TTWebClientUI/Properties/Settings.Designer.cs | 2 +- TTWebClientUI/TTWebClientUI.csproj | 2 +- 13 files changed, 64 insertions(+), 32 deletions(-) diff --git a/TTWebClient/Domain/TTTrade.cs b/TTWebClient/Domain/TTTrade.cs index 30ff46e..ebfaa85 100644 --- a/TTWebClient/Domain/TTTrade.cs +++ b/TTWebClient/Domain/TTTrade.cs @@ -158,7 +158,10 @@ public class TTTrade /// Trigger Time public DateTime? TriggerTime { get; set; } - /// Commission + /// Order Id Triggered By public long? OrderIdTriggeredBy { get; set; } + + /// Close Price + public decimal? ClosePrice { get; set; } } } diff --git a/TTWebClient/TTWebClient.csproj b/TTWebClient/TTWebClient.csproj index 074e413..90ba7c1 100644 --- a/TTWebClient/TTWebClient.csproj +++ b/TTWebClient/TTWebClient.csproj @@ -9,7 +9,7 @@ Properties TTWebClient TTWebClient - v4.6.1 + v4.8 512 ..\ true diff --git a/TTWebClient/app.config b/TTWebClient/app.config index 323c0f4..a905483 100644 --- a/TTWebClient/app.config +++ b/TTWebClient/app.config @@ -1,17 +1,17 @@ - + - + - - + + - - + + diff --git a/TTWebClientRobot/App.config b/TTWebClientRobot/App.config index 1a53b96..1231108 100644 --- a/TTWebClientRobot/App.config +++ b/TTWebClientRobot/App.config @@ -1,17 +1,17 @@ - + - - + + - - + + diff --git a/TTWebClientRobot/TTWebClientRobot.csproj b/TTWebClientRobot/TTWebClientRobot.csproj index 3da7d46..3e9a667 100644 --- a/TTWebClientRobot/TTWebClientRobot.csproj +++ b/TTWebClientRobot/TTWebClientRobot.csproj @@ -9,7 +9,7 @@ Properties TTWebClientRobot TTWebClientRobot - v4.6.1 + v4.8 512 diff --git a/TTWebClientSample/App.config b/TTWebClientSample/App.config index 1a53b96..1231108 100644 --- a/TTWebClientSample/App.config +++ b/TTWebClientSample/App.config @@ -1,17 +1,17 @@ - + - - + + - - + + diff --git a/TTWebClientSample/TTWebClientSample.csproj b/TTWebClientSample/TTWebClientSample.csproj index f9cd116..15f31a7 100644 --- a/TTWebClientSample/TTWebClientSample.csproj +++ b/TTWebClientSample/TTWebClientSample.csproj @@ -9,7 +9,7 @@ Properties TTWebClientSample TTWebClientSample - v4.6.1 + v4.8 512 publish\ true diff --git a/TTWebClientUI/App.config b/TTWebClientUI/App.config index d87e154..6e0188a 100644 --- a/TTWebClientUI/App.config +++ b/TTWebClientUI/App.config @@ -6,18 +6,18 @@ - + - - + + - - + + diff --git a/TTWebClientUI/ClientView.cs b/TTWebClientUI/ClientView.cs index 4bbed2b..2396b64 100644 --- a/TTWebClientUI/ClientView.cs +++ b/TTWebClientUI/ClientView.cs @@ -143,6 +143,7 @@ internal class ClientView : ObservableObject public Command GetPositionsCommand { get; set; } public Command GetTradesCommand { get; set; } public Command PostTradeCommand { get; set; } + public Command CloseTradeCommand { get; set; } public Command GetTradeHistoryCommand { get; set; } public bool IsPublicEnabled @@ -538,6 +539,7 @@ public ClientView(CredsModel creds) GetPositionsCommand = new Command(async () => await GetPositions()); GetTradesCommand = new Command(async () => await GetTrades()); PostTradeCommand = new Command(async () => await PostTrade()); + CloseTradeCommand = new Command(async () => await CloseTrade()); GetTradeHistoryCommand = new Command(async () => await GetTradeHistory()); if (creds.IsPublicOnly) @@ -876,6 +878,27 @@ public async Task PostTrade() Trades = trades != null ? new ObservableCollection(trades) : null; } + public async Task CloseTrade() + { + // Account trades + List trades = null; + if (!long.TryParse(TradeId, out var tradeId)) + return; + else + { + try + { + var trade = await _client.CloseTradeAsync(tradeId, null); + trades = new List(new[] { trade.Trade }); + } + catch (Exception) + { + } + } + + Trades = trades != null ? new ObservableCollection(trades) : null; + } + #endregion #region Account trade history information diff --git a/TTWebClientUI/MainWindow.xaml b/TTWebClientUI/MainWindow.xaml index a4ebbb7..8fa781b 100644 --- a/TTWebClientUI/MainWindow.xaml +++ b/TTWebClientUI/MainWindow.xaml @@ -576,10 +576,15 @@ - -