обновление алгоритма принятия решений
test / deploy_trader_prod (push) Successful in 41s Details

main
vlad zverzhkhovskiy 2025-09-03 15:51:34 +03:00
parent 59c777172e
commit 6efea45378
2 changed files with 15 additions and 16 deletions

View File

@ -33,7 +33,7 @@ namespace KLHZ.Trader.Core.Math.Declisions.Utils
var twavbs = new decimal[size]; var twavbs = new decimal[size];
var times = new DateTime[size]; var times = new DateTime[size];
for (int shift = 0; shift < size-1 && shift < prices.Length -1; shift++) for (int shift = 0; shift < size - 1 && shift < prices.Length - 1; shift++)
{ {
s = shift; s = shift;
var i2 = size - 1 - shift; var i2 = size - 1 - shift;
@ -75,7 +75,7 @@ namespace KLHZ.Trader.Core.Math.Declisions.Utils
// если фильтрация окном 120 наползает на окно 15 сверху, потенциальное время открытия лонга и закрытия шорта // если фильтрация окном 120 наползает на окно 15 сверху, потенциальное время открытия лонга и закрытия шорта
if (twavbs[size - 1] <= twavss[size - 1] && twavbs[size - 2] > twavss[size - 2]) if (twavbs[size - 1] <= twavss[size - 1] && twavbs[size - 2] > twavss[size - 2])
{ {
if (pricesForFinalComparison[i2+1] - pricesForFinalComparison[size - 1] >= meanfullStep) if (pricesForFinalComparison[i2 + 1] - pricesForFinalComparison[size - 1] >= meanfullStep)
{ {
res |= TradingEvent.LongOpen; res |= TradingEvent.LongOpen;
res |= TradingEvent.ShortClose; res |= TradingEvent.ShortClose;
@ -86,7 +86,7 @@ namespace KLHZ.Trader.Core.Math.Declisions.Utils
// если фильтрация окном 15 наползает на окно 120 сверху, потенциальное время закрытия лонга и возможно открытия шорта // если фильтрация окном 15 наползает на окно 120 сверху, потенциальное время закрытия лонга и возможно открытия шорта
if (twavss[size - 1] <= twavbs[size - 1] && twavss[size - 2] > twavbs[size - 2]) if (twavss[size - 1] <= twavbs[size - 1] && twavss[size - 2] > twavbs[size - 2])
{ {
if (pricesForFinalComparison[i2+1] - pricesForFinalComparison[size - 1] <= -meanfullStep) if (pricesForFinalComparison[i2 + 1] - pricesForFinalComparison[size - 1] <= -meanfullStep)
{ {
res |= TradingEvent.LongClose; res |= TradingEvent.LongClose;
res |= TradingEvent.ShortOpen; res |= TradingEvent.ShortOpen;

View File

@ -31,7 +31,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
private readonly IDataBus _dataBus; private readonly IDataBus _dataBus;
private readonly BotModeSwitcher _botModeSwitcher; private readonly BotModeSwitcher _botModeSwitcher;
private readonly IDbContextFactory<TraderDbContext> _dbContextFactory; private readonly IDbContextFactory<TraderDbContext> _dbContextFactory;
private readonly ConcurrentDictionary<string, DateTime> BuyStops = new(); private readonly ConcurrentDictionary<string, DateTime> OpeningStops = new();
private readonly ConcurrentDictionary<string, ManagedAccount> Accounts = new(); private readonly ConcurrentDictionary<string, ManagedAccount> Accounts = new();
private readonly ConcurrentDictionary<string, IPriceHistoryCacheUnit> _historyCash = new(); private readonly ConcurrentDictionary<string, IPriceHistoryCacheUnit> _historyCash = new();
private readonly ILogger<Trader> _logger; private readonly ILogger<Trader> _logger;
@ -110,7 +110,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
foreach (var stop in stops) foreach (var stop in stops)
{ {
var time = stop.Time.AddMinutes(_buyStopLength); var time = stop.Time.AddMinutes(_buyStopLength);
BuyStops.TryAdd(stop.Figi, time); OpeningStops.TryAdd(stop.Figi, time);
} }
} }
@ -137,22 +137,18 @@ namespace KLHZ.Trader.Core.Exchange.Services
if (message.Figi == "FUTIMOEXF000") if (message.Figi == "FUTIMOEXF000")
{ {
var data = await unit.GetData(); var data = await unit.GetData();
if (BuyStops.TryGetValue(message.Figi, out var dt)) if (OpeningStops.TryGetValue(message.Figi, out var dt))
{ {
if (dt > (message.IsHistoricalData ? message.Time : DateTime.UtcNow)) if (dt < (message.IsHistoricalData ? message.Time : DateTime.UtcNow))
{ {
continue; OpeningStops.TryRemove(message.Figi, out _);
}
else
{
BuyStops.TryRemove(message.Figi, out _);
} }
} }
if ((unit.BidsCount / unit.AsksCount) < 0.5m || (unit.BidsCount / unit.AsksCount) > 2m) if ((unit.BidsCount / unit.AsksCount) < 0.5m || (unit.BidsCount / unit.AsksCount) > 2m)
{ {
var stopTo = (message.IsHistoricalData ? message.Time : DateTime.UtcNow).AddMinutes(3); var stopTo = (message.IsHistoricalData ? message.Time : DateTime.UtcNow).AddMinutes(3);
BuyStops.AddOrUpdate(message.Figi, stopTo, (k, v) => stopTo); OpeningStops.AddOrUpdate(message.Figi, stopTo, (k, v) => stopTo);
declisionsForSave.Add(new Declision() declisionsForSave.Add(new Declision()
{ {
AccountId = string.Empty, AccountId = string.Empty,
@ -191,7 +187,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
if ((result.events & TradingEvent.StopBuy) == TradingEvent.StopBuy) if ((result.events & TradingEvent.StopBuy) == TradingEvent.StopBuy)
{ {
var stopTo = (message.IsHistoricalData ? message.Time : DateTime.UtcNow).AddMinutes(_buyStopLength); var stopTo = (message.IsHistoricalData ? message.Time : DateTime.UtcNow).AddMinutes(_buyStopLength);
BuyStops.AddOrUpdate(message.Figi, stopTo, (k, v) => stopTo); OpeningStops.AddOrUpdate(message.Figi, stopTo, (k, v) => stopTo);
declisionsForSave.Add(new Declision() declisionsForSave.Add(new Declision()
{ {
AccountId = string.Empty, AccountId = string.Empty,
@ -205,6 +201,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
} }
if ((result.events & TradingEvent.LongOpen) == TradingEvent.LongOpen if ((result.events & TradingEvent.LongOpen) == TradingEvent.LongOpen
&& !OpeningStops.TryGetValue(message.Figi, out _)
&& ((unit.BidsCount / unit.AsksCount) > 0.5m)) && ((unit.BidsCount / unit.AsksCount) > 0.5m))
{ {
declisionsForSave.Add(new Declision() declisionsForSave.Add(new Declision()
@ -231,7 +228,9 @@ namespace KLHZ.Trader.Core.Exchange.Services
}); });
} }
if ((result.events & TradingEvent.ShortOpen) == TradingEvent.ShortOpen && (unit.BidsCount / unit.AsksCount < 2)) if ((result.events & TradingEvent.ShortOpen) == TradingEvent.ShortOpen
&& !OpeningStops.TryGetValue(message.Figi, out _)
&& (unit.BidsCount / unit.AsksCount < 2))
{ {
declisionsForSave.Add(new Declision() declisionsForSave.Add(new Declision()
{ {