Поправка сохранения стопов
test / deploy_trader_prod (push) Successful in 1m41s Details

dev
vlad zverzhkhovskiy 2025-09-23 11:16:52 +03:00
parent d459728ca3
commit e5eee25042
5 changed files with 15 additions and 15 deletions

View File

@ -5,10 +5,10 @@ namespace KLHZ.Trader.Core.Exchange.Extentions
{
internal static class InvestApiClientExtentions
{
public static async Task<Dictionary<string,string>> GetAccounts(this InvestApiClient client, params string[] managedAccountNamePatterns)
public static async Task<Dictionary<string, string>> GetAccounts(this InvestApiClient client, params string[] managedAccountNamePatterns)
{
var accounts = await client.Users.GetAccountsAsync();
var accs = new Dictionary<string,string>();
var accs = new Dictionary<string, string>();
foreach (var pattern in managedAccountNamePatterns)
{
var aids = accounts.Accounts

View File

@ -9,7 +9,7 @@ namespace KLHZ.Trader.Core.Exchange.Interfaces
public decimal Total { get; }
bool Initialized { get; }
string AccountId { get; }
string? AccountName{ get; }
string? AccountName { get; }
Task Init(string accountId, string? accountName = null);
Task LoadPortfolio();
ImmutableDictionary<string, Asset> Assets { get; }

View File

@ -52,7 +52,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
var accounts = await _investApiClient.GetAccounts(_managedAccountNamePatterns);
foreach (var acc in accounts)
{
await _portfolioWrapper.AddAccount(acc.Key,acc.Value);
await _portfolioWrapper.AddAccount(acc.Key, acc.Value);
}
_ = CycleSubscribtion(accounts.Keys.ToArray());
}

View File

@ -294,8 +294,8 @@ namespace KLHZ.Trader.Core.Exchange.Services
await OpenPositions(accounts, message, PositionType.Long, stops.stopLoss, stops.takeProfit, 1);
}
await LogDeclision(DeclisionTradeAction.OpenLong, message);
await LogDeclision(DeclisionTradeAction.OpenLong, message.Value + stops.takeProfit, message.Time.AddMilliseconds(-RandomNumberGenerator.GetInt32(10, 100)), message);
await LogDeclision(DeclisionTradeAction.OpenLong, message.Value - stops.stopLoss, message.Time.AddMilliseconds(RandomNumberGenerator.GetInt32(10, 100)), message);
await LogDeclision(DeclisionTradeAction.OpenLong, message.Value + stops.takeProfit, message.Time.AddMilliseconds(-RandomNumberGenerator.GetInt32(300, 1000)), message);
await LogDeclision(DeclisionTradeAction.OpenLong, message.Value - stops.stopLoss, message.Time.AddMilliseconds(RandomNumberGenerator.GetInt32(300, 1000)), message);
}
if (newMod == TradingMode.Dropping && newMod != oldMod)
{
@ -310,8 +310,8 @@ namespace KLHZ.Trader.Core.Exchange.Services
await OpenPositions(accounts, message, PositionType.Short, stops.stopLoss, stops.takeProfit, 1);
}
await LogDeclision(DeclisionTradeAction.OpenShort, message);
await LogDeclision(DeclisionTradeAction.OpenShort, message.Value - stops.takeProfit, message.Time.AddMilliseconds(-RandomNumberGenerator.GetInt32(10,100)), message);
await LogDeclision(DeclisionTradeAction.OpenShort, message.Value + stops.stopLoss, message.Time.AddMilliseconds(RandomNumberGenerator.GetInt32(10, 100)), message);
await LogDeclision(DeclisionTradeAction.OpenShort, message.Value - stops.takeProfit, message.Time.AddMilliseconds(-RandomNumberGenerator.GetInt32(10, 100)), message);
await LogDeclision(DeclisionTradeAction.OpenShort, message.Value + stops.stopLoss, message.Time.AddMilliseconds(RandomNumberGenerator.GetInt32(300, 1000)), message);
}
TradingModes[message.Figi] = newMod;
if (oldMod != newMod)
@ -467,7 +467,7 @@ INewPrice message, int windowMaxSize, decimal uptrendStartingDetectionMeanfullSt
assetsForClose.Add(asset);
}
}
var tasks = assetsForClose.Select(asset => _portfolioWrapper.Accounts[asset.AccountId].ClosePosition(message.Figi));
await Task.WhenAll(tasks);
}
@ -548,8 +548,8 @@ INewPrice message, int windowMaxSize, decimal uptrendStartingDetectionMeanfullSt
}
await LogDeclision(DeclisionTradeAction.OpenLong, message);
await LogDeclision(DeclisionTradeAction.OpenLong, message.Value + stops.takeProfit, message.Time.AddMilliseconds(-RandomNumberGenerator.GetInt32(10, 100)), message);
await LogDeclision(DeclisionTradeAction.OpenLong, message.Value - stops.stopLoss, message.Time.AddMilliseconds(RandomNumberGenerator.GetInt32(10, 100)), message);
await LogDeclision(DeclisionTradeAction.OpenLong, message.Value + stops.takeProfit, message.Time.AddMilliseconds(-RandomNumberGenerator.GetInt32(300, 1000)), message);
await LogDeclision(DeclisionTradeAction.OpenLong, message.Value - stops.stopLoss, message.Time.AddMilliseconds(RandomNumberGenerator.GetInt32(300, 1000)), message);
}
if (result[TradingEvent.DowntrendStart] > Constants.PowerUppingCoefficient
&& !ShortOpeningStops.ContainsKey(message.Figi)
@ -568,8 +568,8 @@ INewPrice message, int windowMaxSize, decimal uptrendStartingDetectionMeanfullSt
}
await LogDeclision(DeclisionTradeAction.OpenShort, message);
await LogDeclision(DeclisionTradeAction.OpenShort, message.Value - stops.takeProfit, message.Time.AddMilliseconds(-RandomNumberGenerator.GetInt32(10, 100)), message);
await LogDeclision(DeclisionTradeAction.OpenShort, message.Value + stops.stopLoss, message.Time.AddMilliseconds(RandomNumberGenerator.GetInt32(10, 100)), message);
await LogDeclision(DeclisionTradeAction.OpenShort, message.Value - stops.takeProfit, message.Time.AddMilliseconds(-RandomNumberGenerator.GetInt32(300, 1000)), message);
await LogDeclision(DeclisionTradeAction.OpenShort, message.Value + stops.stopLoss, message.Time.AddMilliseconds(RandomNumberGenerator.GetInt32(300, 1000)), message);
}
if (result[TradingEvent.UptrendEnd] > Constants.UppingCoefficient)
{

View File

@ -39,11 +39,11 @@ namespace KLHZ.Trader.Core.TG.Services
{
await _botClient.SendMessage(admin, message.Text);
}
catch(Exception ex)
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при отправке сообщения в бота.");
}
}
}
}