убрал проверку времени для сброса актива
test / deploy_trader_prod (push) Successful in 5m24s
Details
test / deploy_trader_prod (push) Successful in 5m24s
Details
parent
61d63ee4f3
commit
bcc084c49c
|
@ -15,7 +15,7 @@ namespace KLHZ.Trader.Core.Math.Declisions.Utils
|
||||||
{
|
{
|
||||||
return ValueAmplitudePosition.UpperThen30Decil;
|
return ValueAmplitudePosition.UpperThen30Decil;
|
||||||
}
|
}
|
||||||
else if (value < fftData.Mediana)
|
else if (value < fftData.Mediana && System.Math.Sign(value2)>=0)
|
||||||
{
|
{
|
||||||
return ValueAmplitudePosition.LowerThenMediana;
|
return ValueAmplitudePosition.LowerThenMediana;
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
var currentTime = message.IsHistoricalData ? message.Time : DateTime.UtcNow;
|
var currentTime = message.IsHistoricalData ? message.Time : DateTime.UtcNow;
|
||||||
var position = ValueAmplitudePosition.None;
|
var position = ValueAmplitudePosition.None;
|
||||||
var fft = await _tradeDataProvider.GetFFtResult(message.Figi);
|
var fft = await _tradeDataProvider.GetFFtResult(message.Figi);
|
||||||
var step = message.IsHistoricalData ? 90 : 10;
|
var step = message.IsHistoricalData ? 5 : 5;
|
||||||
if (fft.IsEmpty || (currentTime - fft.LastTime).TotalSeconds > step)
|
if (fft.IsEmpty || (currentTime - fft.LastTime).TotalSeconds > step)
|
||||||
{
|
{
|
||||||
if (data.isFullIntervalExists)
|
if (data.isFullIntervalExists)
|
||||||
|
@ -190,7 +190,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (message.Figi == "FUTIMOEXF000")
|
if (message.Figi == "FUTIMOEXF000" && message.Direction==1)
|
||||||
{
|
{
|
||||||
ProcessStops(message, currentTime);
|
ProcessStops(message, currentTime);
|
||||||
var windowMaxSize = 2000;
|
var windowMaxSize = 2000;
|
||||||
|
@ -227,7 +227,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
var profit = TradingCalculator.CaclProfit(asset.BoughtPrice, message.Value,
|
var profit = TradingCalculator.CaclProfit(asset.BoughtPrice, message.Value,
|
||||||
GetComission(assetType), GetLeverage(message.Figi, asset.Count < 0), asset.Count < 0);
|
GetComission(assetType), GetLeverage(message.Figi, asset.Count < 0), asset.Count < 0);
|
||||||
var stoppingKey = message.Figi + asset.AccountId;
|
var stoppingKey = message.Figi + asset.AccountId;
|
||||||
if (message.Time - asset.BoughtAt > TimeSpan.FromMinutes(4) && profit < -66m)
|
if (profit < -66m)
|
||||||
{
|
{
|
||||||
var command = new TradeCommand()
|
var command = new TradeCommand()
|
||||||
{
|
{
|
||||||
|
@ -250,10 +250,10 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<TradingEvent> CheckByWindowAverageMean((DateTime[] timestamps, decimal[] prices) data,
|
private async Task<TradingEvent> CheckByWindowAverageMean((DateTime[] timestamps, decimal[] prices) data,
|
||||||
INewPrice message, int windowMaxSize)
|
INewPrice message, int windowMaxSize, decimal uptrendStartingDetectionMeanfullStep = 0m, decimal uptrendEndingDetectionMeanfullStep = 3m)
|
||||||
{
|
{
|
||||||
var resultMoveAvFull = MovingAverage.CheckByWindowAverageMean(data.timestamps, data.prices,
|
var resultMoveAvFull = MovingAverage.CheckByWindowAverageMean(data.timestamps, data.prices,
|
||||||
windowMaxSize, 30, 180, TimeSpan.FromSeconds(20), -1m, 2m);
|
windowMaxSize, 30, 180, TimeSpan.FromSeconds(20), uptrendStartingDetectionMeanfullStep, uptrendEndingDetectionMeanfullStep);
|
||||||
if (resultMoveAvFull.bigWindowAv != 0)
|
if (resultMoveAvFull.bigWindowAv != 0)
|
||||||
{
|
{
|
||||||
await LogPrice(message, Constants.BigWindowCrossingAverageProcessor, resultMoveAvFull.bigWindowAv);
|
await LogPrice(message, Constants.BigWindowCrossingAverageProcessor, resultMoveAvFull.bigWindowAv);
|
||||||
|
@ -262,8 +262,16 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
return resultMoveAvFull.events;
|
return resultMoveAvFull.events;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<TradingEvent> CheckByWindowAverageMeanNolog((DateTime[] timestamps, decimal[] prices) data,
|
||||||
|
INewPrice message, int windowMaxSize, decimal uptrendStartingDetectionMeanfullStep = 0m, decimal uptrendEndingDetectionMeanfullStep = 3m)
|
||||||
|
{
|
||||||
|
var resultMoveAvFull = MovingAverage.CheckByWindowAverageMean(data.timestamps, data.prices,
|
||||||
|
windowMaxSize, 30, 180, TimeSpan.FromSeconds(20), uptrendStartingDetectionMeanfullStep, uptrendEndingDetectionMeanfullStep);
|
||||||
|
return resultMoveAvFull.events;
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<TradingEvent> CheckByWindowAverageMeanForShotrs((DateTime[] timestamps, decimal[] prices) data,
|
private async Task<TradingEvent> CheckByWindowAverageMeanForShotrs((DateTime[] timestamps, decimal[] prices) data,
|
||||||
INewPrice message, int windowMaxSize)
|
INewPrice message, int windowMaxSize)
|
||||||
{
|
{
|
||||||
var resultMoveAvFull = MovingAverage.CheckByWindowAverageMean(data.timestamps, data.prices,
|
var resultMoveAvFull = MovingAverage.CheckByWindowAverageMean(data.timestamps, data.prices,
|
||||||
windowMaxSize, 30, 240, TimeSpan.FromSeconds(20), -1m, 1m);
|
windowMaxSize, 30, 240, TimeSpan.FromSeconds(20), -1m, 1m);
|
||||||
|
@ -351,17 +359,21 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
var dsell = (sells / su - 0.5m) * 2;
|
var dsell = (sells / su - 0.5m) * 2;
|
||||||
|
|
||||||
|
|
||||||
var mavTask = CheckByWindowAverageMean(data, message, windowMaxSize);
|
var mavTask = CheckByWindowAverageMean(data, message, windowMaxSize, -1, 2m);
|
||||||
|
var mavTaskEnds = CheckByWindowAverageMeanNolog(data, message, windowMaxSize, -1, 1m);
|
||||||
|
|
||||||
var mavTaskShorts = CheckByWindowAverageMeanForShotrs(data, message, windowMaxSize);
|
var mavTaskShorts = CheckByWindowAverageMeanForShotrs(data, message, windowMaxSize);
|
||||||
var ltTask = CheckByLocalTrends(data, message, windowMaxSize);
|
var ltTask = CheckByLocalTrends(data, message, windowMaxSize);
|
||||||
var areasTask = GetAreasRelation(data, message);
|
var areasTask = GetAreasRelation(data, message);
|
||||||
var positionTask = CheckPosition(message);
|
var positionTask = CheckPosition(message);
|
||||||
var trendTask = CalcTrendDiff(message);
|
var trendTask = CalcTrendDiff(message);
|
||||||
|
|
||||||
await Task.WhenAll(mavTask, ltTask, areasTask, positionTask, trendTask, mavTaskShorts);
|
var ends = mavTaskEnds.Result & TradingEvent.UptrendEnd;
|
||||||
|
|
||||||
|
await Task.WhenAll(mavTask, ltTask, areasTask, positionTask, trendTask, mavTaskShorts, mavTaskEnds);
|
||||||
var assetType = _tradeDataProvider.GetAssetTypeByFigi(message.Figi);
|
var assetType = _tradeDataProvider.GetAssetTypeByFigi(message.Figi);
|
||||||
var res = mavTask.Result | ltTask.Result;
|
var res = mavTask.Result | ltTask.Result;
|
||||||
|
res |= ends;
|
||||||
if ((res & TradingEvent.UptrendStart) == TradingEvent.UptrendStart
|
if ((res & TradingEvent.UptrendStart) == TradingEvent.UptrendStart
|
||||||
&& !LongOpeningStops.ContainsKey(message.Figi)
|
&& !LongOpeningStops.ContainsKey(message.Figi)
|
||||||
&& trendTask.Result.HasValue
|
&& trendTask.Result.HasValue
|
||||||
|
@ -410,56 +422,52 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
}
|
}
|
||||||
if ((res & TradingEvent.UptrendEnd) == TradingEvent.UptrendEnd)
|
if ((res & TradingEvent.UptrendEnd) == TradingEvent.UptrendEnd)
|
||||||
{
|
{
|
||||||
//if (dsell < 0.1m)
|
if (!message.IsHistoricalData && BotModeSwitcher.CanSell())
|
||||||
{
|
{
|
||||||
if (!message.IsHistoricalData && BotModeSwitcher.CanSell())
|
var loggedDeclisions = 0;
|
||||||
|
var assetsForClose = _tradeDataProvider.Accounts
|
||||||
|
.SelectMany(a => a.Value.Assets.Values)
|
||||||
|
.Where(a => a.Figi == message.Figi && a.Count > 0)
|
||||||
|
.ToArray();
|
||||||
|
foreach (var asset in assetsForClose)
|
||||||
{
|
{
|
||||||
var loggedDeclisions = 0;
|
var profit = 0m;
|
||||||
var assetsForClose = _tradeDataProvider.Accounts
|
|
||||||
.SelectMany(a => a.Value.Assets.Values)
|
if (assetType == AssetType.Common && asset.Count > 0)
|
||||||
.Where(a => a.Figi == message.Figi && a.Count > 0)
|
|
||||||
.ToArray();
|
|
||||||
foreach (var asset in assetsForClose)
|
|
||||||
{
|
{
|
||||||
var profit = 0m;
|
profit = TradingCalculator.CaclProfit(asset.BoughtPrice, message.Value,
|
||||||
|
GetComission(assetType), 1, false);
|
||||||
|
}
|
||||||
|
if (assetType == AssetType.Futures)
|
||||||
|
{
|
||||||
|
profit = TradingCalculator.CaclProfit(asset.BoughtPrice, message.Value,
|
||||||
|
GetComission(assetType), GetLeverage(message.Figi, asset.Count < 0), asset.Count < 0);
|
||||||
|
}
|
||||||
|
|
||||||
if (assetType == AssetType.Common && asset.Count > 0)
|
if (profit > 0)
|
||||||
|
{
|
||||||
|
LongClosingStops[message.Figi] = message.Time.AddSeconds(30);
|
||||||
|
var command = new TradeCommand()
|
||||||
{
|
{
|
||||||
profit = TradingCalculator.CaclProfit(asset.BoughtPrice, message.Value,
|
AccountId = asset.AccountId,
|
||||||
GetComission(assetType), 1, false);
|
Figi = message.Figi,
|
||||||
}
|
CommandType = Contracts.Messaging.Dtos.Enums.TradeCommandType.MarketSell,
|
||||||
if (assetType == AssetType.Futures)
|
Count = (long)asset.Count,
|
||||||
|
RecomendPrice = null,
|
||||||
|
EnableMargin = false,
|
||||||
|
};
|
||||||
|
await _dataBus.Broadcast(command);
|
||||||
|
_logger.LogWarning("Продажа актива {figi}! id команды {commandId}. Направление сделки: {dir}; Количество активов: {count}; Разрешена ли маржиналка: {margin}",
|
||||||
|
message.Figi, command.CommandId, command.CommandType, command.Count, command.EnableMargin);
|
||||||
|
if (loggedDeclisions == 0)
|
||||||
{
|
{
|
||||||
profit = TradingCalculator.CaclProfit(asset.BoughtPrice, message.Value,
|
loggedDeclisions++;
|
||||||
GetComission(assetType), GetLeverage(message.Figi, asset.Count < 0), asset.Count < 0);
|
await LogDeclision(DeclisionTradeAction.CloseLongReal, message, profit);
|
||||||
}
|
|
||||||
|
|
||||||
if (profit > 0)
|
|
||||||
{
|
|
||||||
LongClosingStops[message.Figi] = message.Time.AddSeconds(30);
|
|
||||||
var command = new TradeCommand()
|
|
||||||
{
|
|
||||||
AccountId = asset.AccountId,
|
|
||||||
Figi = message.Figi,
|
|
||||||
CommandType = Contracts.Messaging.Dtos.Enums.TradeCommandType.MarketSell,
|
|
||||||
Count = (long)asset.Count,
|
|
||||||
RecomendPrice = null,
|
|
||||||
EnableMargin = false,
|
|
||||||
};
|
|
||||||
await _dataBus.Broadcast(command);
|
|
||||||
_logger.LogWarning("Продажа актива {figi}! id команды {commandId}. Направление сделки: {dir}; Количество активов: {count}; Разрешена ли маржиналка: {margin}",
|
|
||||||
message.Figi, command.CommandId, command.CommandType, command.Count, command.EnableMargin);
|
|
||||||
if (loggedDeclisions == 0)
|
|
||||||
{
|
|
||||||
loggedDeclisions++;
|
|
||||||
await LogDeclision(DeclisionTradeAction.CloseLongReal, message, profit);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await LogDeclision(DeclisionTradeAction.CloseLong, message);
|
|
||||||
}
|
}
|
||||||
|
await LogDeclision(DeclisionTradeAction.CloseLong, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mavTaskShorts.Result & TradingEvent.UptrendEnd) == TradingEvent.UptrendEnd)
|
if ((mavTaskShorts.Result & TradingEvent.UptrendEnd) == TradingEvent.UptrendEnd)
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace KLHZ.Trader.Service.Controllers
|
||||||
//var figi1 = "BBG004730N88";
|
//var figi1 = "BBG004730N88";
|
||||||
var figi2 = "BBG004730N88";
|
var figi2 = "BBG004730N88";
|
||||||
//var figi2 = "FUTIMOEXF000";
|
//var figi2 = "FUTIMOEXF000";
|
||||||
var time1 = DateTime.UtcNow.AddDays(-16.5);
|
var time1 = DateTime.UtcNow.AddDays(-17);
|
||||||
//var time2 = DateTime.UtcNow.AddMinutes(18);
|
//var time2 = DateTime.UtcNow.AddMinutes(18);
|
||||||
using var context1 = await _dbContextFactory.CreateDbContextAsync();
|
using var context1 = await _dbContextFactory.CreateDbContextAsync();
|
||||||
context1.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
context1.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||||
|
|
Loading…
Reference in New Issue