From bb7fd20225a5f32367644e6bfeae7346327030df Mon Sep 17 00:00:00 2001 From: vlad zverzhkhovskiy Date: Tue, 9 Sep 2025 15:29:56 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=87=D0=B8=D0=B5=20=D0=B8=D0=BD=D1=82=D0=B5?= =?UTF-8?q?=D1=80=D0=B2=D0=B0=D0=BB=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KLHZ.Trader.Core.Math/Common/Lines.cs | 4 ++ .../Declisions/Utils/MovingAverage.cs | 6 ++- KLHZ.Trader.Core/Exchange/Services/Trader.cs | 48 ++++++++----------- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/KLHZ.Trader.Core.Math/Common/Lines.cs b/KLHZ.Trader.Core.Math/Common/Lines.cs index 3e054fe..774dd5e 100644 --- a/KLHZ.Trader.Core.Math/Common/Lines.cs +++ b/KLHZ.Trader.Core.Math/Common/Lines.cs @@ -31,6 +31,10 @@ return (crossingTimestamp >= time1 && crossingTimestamp <= time2, crossingTimestamp, cross.y); } } + //else if (b1 == b2) + //{ + // return (true, time2, val2_2); + //} return (false, DateTime.MinValue, 0); } } diff --git a/KLHZ.Trader.Core.Math/Declisions/Utils/MovingAverage.cs b/KLHZ.Trader.Core.Math/Declisions/Utils/MovingAverage.cs index 49a94f3..9c1b788 100644 --- a/KLHZ.Trader.Core.Math/Declisions/Utils/MovingAverage.cs +++ b/KLHZ.Trader.Core.Math/Declisions/Utils/MovingAverage.cs @@ -20,7 +20,9 @@ namespace KLHZ.Trader.Core.Math.Declisions.Utils return (startTime, sum / count); } - public static (TradingEvent events, decimal bigWindowAv, decimal smallWindowAv) CheckByWindowAverageMean(DateTime[] timestamps, decimal[] prices, int size, int smallWindow, int bigWindow, TimeSpan timeForUptreandStart, decimal downtrendStartingDetectionMeanfullStep = 3m, decimal uptrendEndingDetectionMeanfullStep = 3m) + public static (TradingEvent events, decimal bigWindowAv, decimal smallWindowAv) CheckByWindowAverageMean(DateTime[] timestamps, + decimal[] prices, int size, int smallWindow, int bigWindow, TimeSpan timeForUptreandStart, + decimal downtrendStartingDetectionMeanfullStep = 3m, decimal uptrendEndingDetectionMeanfullStep = 3m) { var res = TradingEvent.None; var bigWindowAv = 0m; @@ -110,7 +112,7 @@ namespace KLHZ.Trader.Core.Math.Declisions.Utils // если фильтрация окном 120 наползает на окно 15 сверху, потенциальное время открытия лонга и закрытия шорта if (twavss[size - 1] >= twavbs[size - 1] && twavss[size - 2] < twavbs[size - 2]) { - if (pricesForFinalComparison[crossings[0]] - pricesForFinalComparison[crossings[1]] <= -downtrendStartingDetectionMeanfullStep + if (pricesForFinalComparison[crossings[0]] - pricesForFinalComparison[crossings[1]] <= downtrendStartingDetectionMeanfullStep && times[crossings[0]] - times[crossings[1]] >= timeForUptreandStart) { res |= TradingEvent.UptrendStart; diff --git a/KLHZ.Trader.Core/Exchange/Services/Trader.cs b/KLHZ.Trader.Core/Exchange/Services/Trader.cs index 29d422b..0404c51 100644 --- a/KLHZ.Trader.Core/Exchange/Services/Trader.cs +++ b/KLHZ.Trader.Core/Exchange/Services/Trader.cs @@ -166,43 +166,37 @@ namespace KLHZ.Trader.Core.Exchange.Services var fullData = await _tradeDataProvider.GetData(message.Figi, TimeSpan.FromMinutes(30)); if (fullData.isFullIntervalExists) { - var max = fullData.prices.Max(); - var min = fullData.prices.Min(); - - if (max - min < 15 && fullData.prices.Last() - fullData.prices.First() < 4 && fullData.prices.Last() - fullData.prices.First() > -4) + if (!message.IsHistoricalData && BotModeSwitcher.CanPurchase()) { - if (!message.IsHistoricalData && BotModeSwitcher.CanPurchase()) + var accounts = _tradeDataProvider.Accounts + .Where(a => !a.Value.Assets.ContainsKey(message.Figi)) + .ToArray(); + var loggedDeclisions = 0; + foreach (var acc in accounts) { - var accounts = _tradeDataProvider.Accounts - .Where(a => !a.Value.Assets.ContainsKey(message.Figi)) - .ToArray(); - var loggedDeclisions = 0; - foreach (var acc in accounts) + if (IsBuyAllowed(acc.Value, message.Value, 1, _accountCashPartFutures, _accountCashPart)) { - if (IsBuyAllowed(acc.Value, message.Value, 1, _accountCashPartFutures, _accountCashPart)) + if (RandomNumberGenerator.GetInt32(100) > 50) { - if (RandomNumberGenerator.GetInt32(100) > 50) + await _dataBus.Broadcast(new TradeCommand() { - await _dataBus.Broadcast(new TradeCommand() - { - AccountId = acc.Value.AccountId, - Figi = message.Figi, - CommandType = Contracts.Messaging.Dtos.Enums.TradeCommandType.MarketBuy, - Count = 1, - RecomendPrice = null, - }); - if (loggedDeclisions == 0) - { - await LogDeclision(DeclisionTradeAction.OpenLongReal, message); - OpeningStops[message.Figi] = DateTime.UtcNow.AddMinutes(1); - loggedDeclisions++; - } + AccountId = acc.Value.AccountId, + Figi = message.Figi, + CommandType = Contracts.Messaging.Dtos.Enums.TradeCommandType.MarketBuy, + Count = 1, + RecomendPrice = null, + }); + if (loggedDeclisions == 0) + { + await LogDeclision(DeclisionTradeAction.OpenLongReal, message); + OpeningStops[message.Figi] = DateTime.UtcNow.AddMinutes(1); + loggedDeclisions++; } } } } - await LogDeclision(DeclisionTradeAction.OpenLong, message); } + await LogDeclision(DeclisionTradeAction.OpenLong, message); } }