фикс подсчёта профита
test / deploy_trader_prod (push) Successful in 57s
Details
test / deploy_trader_prod (push) Successful in 57s
Details
parent
4d898e376a
commit
7d2618dd54
|
@ -20,7 +20,7 @@ namespace KLHZ.Trader.Core.Math.Declisions.Utils
|
||||||
return (startTime, sum / count);
|
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 meanfullStep = 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 res = TradingEvent.None;
|
||||||
var bigWindowAv = 0m;
|
var bigWindowAv = 0m;
|
||||||
|
@ -94,7 +94,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 (diffTotal >= meanfullStep
|
if (diffTotal >= uptrendEndingDetectionMeanfullStep
|
||||||
&& times[crossings[0]] - times[crossings[1]] >= timeForUptreandStart)
|
&& times[crossings[0]] - times[crossings[1]] >= timeForUptreandStart)
|
||||||
{
|
{
|
||||||
res |= TradingEvent.UptrendEnd;
|
res |= TradingEvent.UptrendEnd;
|
||||||
|
@ -112,7 +112,7 @@ namespace KLHZ.Trader.Core.Math.Declisions.Utils
|
||||||
// если фильтрация окном 120 наползает на окно 15 сверху, потенциальное время открытия лонга и закрытия шорта
|
// если фильтрация окном 120 наползает на окно 15 сверху, потенциальное время открытия лонга и закрытия шорта
|
||||||
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[crossings[0]] - pricesForFinalComparison[crossings[1]] <= -meanfullStep
|
if (pricesForFinalComparison[crossings[0]] - pricesForFinalComparison[crossings[1]] <= -downtrendStartingDetectionMeanfullStep
|
||||||
&& times[crossings[0]] - times[crossings[1]] >= timeForUptreandStart)
|
&& times[crossings[0]] - times[crossings[1]] >= timeForUptreandStart)
|
||||||
{
|
{
|
||||||
res |= TradingEvent.UptrendStart;
|
res |= TradingEvent.UptrendStart;
|
||||||
|
|
|
@ -55,9 +55,10 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
//_ = SubscribeUpdates();
|
||||||
if (_exchangeDataRecievingEnabled)
|
if (_exchangeDataRecievingEnabled)
|
||||||
{
|
{
|
||||||
await SubscribePrices();
|
_ = SubscribePrices();
|
||||||
}
|
}
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
}
|
}
|
||||||
|
@ -68,6 +69,23 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task SubscribeUpdates()
|
||||||
|
{
|
||||||
|
var req = new TradesStreamRequest();
|
||||||
|
foreach (var a in _tradeDataProvider.Accounts)
|
||||||
|
{
|
||||||
|
req.Accounts.Add(a.Key);
|
||||||
|
}
|
||||||
|
using var stream = _investApiClient.OrdersStream.TradesStream(req);
|
||||||
|
await foreach (var response in stream.ResponseStream.ReadAllAsync())
|
||||||
|
{
|
||||||
|
if (response.OrderTrades != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async Task SubscribePrices()
|
private async Task SubscribePrices()
|
||||||
{
|
{
|
||||||
using var stream = _investApiClient.MarketDataStream.MarketDataStream();
|
using var stream = _investApiClient.MarketDataStream.MarketDataStream();
|
||||||
|
|
|
@ -145,14 +145,9 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
INewPrice message, int windowMaxSize)
|
INewPrice message, int windowMaxSize)
|
||||||
{
|
{
|
||||||
var res = TradingEvent.None;
|
var res = TradingEvent.None;
|
||||||
var resultMoveAvFull = MovingAverage.CheckByWindowAverageMean(data.timestamps, data.prices, windowMaxSize, 25, 120, TimeSpan.FromSeconds(20), 1.5m);
|
var resultMoveAvFull = MovingAverage.CheckByWindowAverageMean(data.timestamps, data.prices,
|
||||||
//var resultLongClose = MovingAverage.CheckByWindowAverageMean(data.timestamps, data.prices, windowMaxSize, 15, 120, 1.5m).events;
|
windowMaxSize, 25, 120, TimeSpan.FromSeconds(20), 1m, 1.5m);
|
||||||
|
|
||||||
//ar uptrendStarts = LocalTrends.CheckByLocalTrends(data.timestamps, data.prices, TimeSpan.FromSeconds(120), TimeSpan.FromSeconds(20), 1.5m, 15);
|
|
||||||
|
|
||||||
|
|
||||||
//res |= (uptrendStarts & TradingEvent.UptrendStart);
|
|
||||||
//res |= resultLongClose;
|
|
||||||
res |= resultMoveAvFull.events;
|
res |= resultMoveAvFull.events;
|
||||||
|
|
||||||
if (resultMoveAvFull.bigWindowAv != 0)
|
if (resultMoveAvFull.bigWindowAv != 0)
|
||||||
|
@ -160,12 +155,6 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
await LogPrice(message, _bigWindowProcessor, resultMoveAvFull.bigWindowAv);
|
await LogPrice(message, _bigWindowProcessor, resultMoveAvFull.bigWindowAv);
|
||||||
await LogPrice(message, _smallWindowProcessor, resultMoveAvFull.smallWindowAv);
|
await LogPrice(message, _smallWindowProcessor, resultMoveAvFull.smallWindowAv);
|
||||||
}
|
}
|
||||||
if ((resultMoveAvFull.events & TradingEvent.StopBuy) == TradingEvent.StopBuy)
|
|
||||||
{
|
|
||||||
var stopTo = (message.IsHistoricalData ? message.Time : DateTime.UtcNow).AddMinutes(_buyStopLength / 2);
|
|
||||||
//OpeningStops.AddOrUpdate(message.Figi, stopTo, (k, v) => stopTo);
|
|
||||||
//await LogDeclision(DeclisionTradeAction.StopBuy, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((res & TradingEvent.UptrendStart) == TradingEvent.UptrendStart
|
if ((res & TradingEvent.UptrendStart) == TradingEvent.UptrendStart
|
||||||
&& !OpeningStops.TryGetValue(message.Figi, out _)
|
&& !OpeningStops.TryGetValue(message.Figi, out _)
|
||||||
|
@ -221,7 +210,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
{
|
{
|
||||||
var assetType = _tradeDataProvider.GetAssetTypeByFigi(message.Figi);
|
var assetType = _tradeDataProvider.GetAssetTypeByFigi(message.Figi);
|
||||||
var loggedDeclisions = 0;
|
var loggedDeclisions = 0;
|
||||||
if (!message.IsHistoricalData && BotModeSwitcher.CanSell())
|
if (BotModeSwitcher.CanSell())
|
||||||
{
|
{
|
||||||
var assetsForClose = _tradeDataProvider.Accounts
|
var assetsForClose = _tradeDataProvider.Accounts
|
||||||
.SelectMany(a => a.Value.Assets.Values)
|
.SelectMany(a => a.Value.Assets.Values)
|
||||||
|
|
|
@ -4,7 +4,13 @@
|
||||||
{
|
{
|
||||||
public static decimal CaclProfit(decimal openPrice, decimal closePrice, decimal comission, decimal leverage, bool isShort)
|
public static decimal CaclProfit(decimal openPrice, decimal closePrice, decimal comission, decimal leverage, bool isShort)
|
||||||
{
|
{
|
||||||
var diff = ((isShort ? (closePrice - openPrice) : (openPrice - closePrice)) - closePrice * comission - openPrice * comission) * leverage;
|
var summComission = closePrice * comission + openPrice * comission;
|
||||||
|
var priceDiff = closePrice - openPrice;
|
||||||
|
if (isShort)
|
||||||
|
{
|
||||||
|
priceDiff *= -1;
|
||||||
|
}
|
||||||
|
var diff = priceDiff * leverage - summComission;
|
||||||
return diff;
|
return diff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace KLHZ.Trader.Service.Controllers
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var time = DateTime.UtcNow.AddMinutes(-40);
|
var time = DateTime.UtcNow.AddMinutes(-35);
|
||||||
using var context1 = await _dbContextFactory.CreateDbContextAsync();
|
using var context1 = await _dbContextFactory.CreateDbContextAsync();
|
||||||
context1.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
context1.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||||
var data = await context1.PriceChanges
|
var data = await context1.PriceChanges
|
||||||
|
|
Loading…
Reference in New Issue