Compare commits
No commits in common. "9bfff7e4d6cec38824c966cf06da424a6a176b8d" and "fcf686a9d51df3128482f6e03242f7373da16a57" have entirely different histories.
9bfff7e4d6
...
fcf686a9d5
|
@ -1,8 +0,0 @@
|
||||||
namespace KLHZ.Trader.Core.Contracts.Declisions.Dtos
|
|
||||||
{
|
|
||||||
public class CachedValue
|
|
||||||
{
|
|
||||||
public DateTime Time { get; init; }
|
|
||||||
public decimal Value { get; init; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
namespace KLHZ.Trader.Core.Contracts.Declisions.Dtos.Enums
|
|
||||||
{
|
|
||||||
public enum TimeWindowCacheType
|
|
||||||
{
|
|
||||||
None = 0,
|
|
||||||
_1_Minute = 1,
|
|
||||||
_2_Minutes = 2,
|
|
||||||
_15_Minutes = 15,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,4 @@
|
||||||
using KLHZ.Trader.Core.Contracts.Declisions.Dtos;
|
using KLHZ.Trader.Core.Contracts.Messaging.Dtos.Interfaces;
|
||||||
using KLHZ.Trader.Core.Contracts.Declisions.Dtos.Enums;
|
|
||||||
using KLHZ.Trader.Core.Contracts.Messaging.Dtos.Interfaces;
|
|
||||||
|
|
||||||
namespace KLHZ.Trader.Core.Contracts.Declisions.Interfaces
|
namespace KLHZ.Trader.Core.Contracts.Declisions.Interfaces
|
||||||
{
|
{
|
||||||
|
@ -13,10 +11,6 @@ namespace KLHZ.Trader.Core.Contracts.Declisions.Interfaces
|
||||||
public ValueTask<(DateTime[] timestamps, decimal[] prices, bool isFullIntervalExists)> GetData(TimeSpan period);
|
public ValueTask<(DateTime[] timestamps, decimal[] prices, bool isFullIntervalExists)> GetData(TimeSpan period);
|
||||||
public ValueTask AddOrderbook(IOrderbook orderbook);
|
public ValueTask AddOrderbook(IOrderbook orderbook);
|
||||||
|
|
||||||
public ValueTask AddDataToTimeWindowCache(string key, CachedValue data, TimeWindowCacheType timeWindowCacheType);
|
|
||||||
|
|
||||||
public ValueTask<CachedValue[]> GetDataFromTimeWindowCache(string key, TimeWindowCacheType timeWindowCacheType);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Число заявок на продаже в стакане.
|
/// Число заявок на продаже в стакане.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace KLHZ.Trader.Core.Math.Declisions.Dtos
|
||||||
|
{
|
||||||
|
public class CachedValue
|
||||||
|
{
|
||||||
|
public DateTime Time { get; init; }
|
||||||
|
public decimal Value { get; init; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,61 +0,0 @@
|
||||||
using KLHZ.Trader.Core.Contracts.Declisions.Dtos;
|
|
||||||
using KLHZ.Trader.Core.Contracts.Declisions.Dtos.Enums;
|
|
||||||
|
|
||||||
namespace KLHZ.Trader.Core.Math.Declisions.Dtos
|
|
||||||
{
|
|
||||||
internal class TimeWindowCacheItem
|
|
||||||
{
|
|
||||||
private readonly object _locker = new();
|
|
||||||
private readonly LinkedList<CachedValue> _cachedValues = new();
|
|
||||||
|
|
||||||
public readonly TimeSpan WindowSize;
|
|
||||||
public readonly string Key;
|
|
||||||
|
|
||||||
public TimeWindowCacheItem(string key, TimeWindowCacheType window)
|
|
||||||
{
|
|
||||||
Key = key;
|
|
||||||
WindowSize = GetTimeSpan(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueTask AddData(CachedValue cachedValue)
|
|
||||||
{
|
|
||||||
lock (_locker)
|
|
||||||
{
|
|
||||||
_cachedValues.AddLast(cachedValue);
|
|
||||||
if (_cachedValues.Last != null && _cachedValues.First != null
|
|
||||||
&& _cachedValues.Last.Value.Time - _cachedValues.First.Value.Time > WindowSize)
|
|
||||||
{
|
|
||||||
_cachedValues.RemoveFirst();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ValueTask.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueTask<CachedValue[]> GetValues()
|
|
||||||
{
|
|
||||||
lock (_locker)
|
|
||||||
{
|
|
||||||
return ValueTask.FromResult(_cachedValues.ToArray());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static TimeSpan GetTimeSpan(TimeWindowCacheType type)
|
|
||||||
{
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case TimeWindowCacheType._2_Minutes:
|
|
||||||
{
|
|
||||||
return TimeSpan.FromMinutes(2);
|
|
||||||
}
|
|
||||||
case TimeWindowCacheType._15_Minutes:
|
|
||||||
{
|
|
||||||
return TimeSpan.FromMinutes(15);
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
return TimeSpan.FromMinutes(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,4 @@
|
||||||
using KLHZ.Trader.Core.Contracts.Declisions.Dtos;
|
using KLHZ.Trader.Core.Contracts.Declisions.Interfaces;
|
||||||
using KLHZ.Trader.Core.Contracts.Declisions.Dtos.Enums;
|
|
||||||
using KLHZ.Trader.Core.Contracts.Declisions.Interfaces;
|
|
||||||
using KLHZ.Trader.Core.Contracts.Messaging.Dtos.Interfaces;
|
using KLHZ.Trader.Core.Contracts.Messaging.Dtos.Interfaces;
|
||||||
using KLHZ.Trader.Core.Math.Declisions.Dtos;
|
using KLHZ.Trader.Core.Math.Declisions.Dtos;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
@ -50,9 +48,7 @@ namespace KLHZ.Trader.Core.Math.Declisions.Services.Cache
|
||||||
private readonly object _locker = new();
|
private readonly object _locker = new();
|
||||||
private readonly decimal[] Prices = new decimal[_arrayMaxLength];
|
private readonly decimal[] Prices = new decimal[_arrayMaxLength];
|
||||||
private readonly DateTime[] Timestamps = new DateTime[_arrayMaxLength];
|
private readonly DateTime[] Timestamps = new DateTime[_arrayMaxLength];
|
||||||
private readonly ConcurrentDictionary<string, TimeWindowCacheItem> _1_minTimeWindows = new();
|
private readonly ConcurrentDictionary<string, LinkedList<CachedValue>> TimeWindows = new();
|
||||||
private readonly ConcurrentDictionary<string, TimeWindowCacheItem> _2_minTimeWindows = new();
|
|
||||||
private readonly ConcurrentDictionary<string, TimeWindowCacheItem> _15_minTimeWindows = new();
|
|
||||||
|
|
||||||
private int _length = 0;
|
private int _length = 0;
|
||||||
private int _pointer = -1;
|
private int _pointer = -1;
|
||||||
|
@ -60,46 +56,11 @@ namespace KLHZ.Trader.Core.Math.Declisions.Services.Cache
|
||||||
private long _asksCount = 1;
|
private long _asksCount = 1;
|
||||||
private long _bidsCount = 1;
|
private long _bidsCount = 1;
|
||||||
|
|
||||||
public ValueTask AddDataToTimeWindowCache(string key, CachedValue data, TimeWindowCacheType timeWindowCacheType)
|
public ValueTask AddDataToTimeWindowCache(string key, CachedValue data, TimeSpan window)
|
||||||
{
|
{
|
||||||
var dict = GetDict(timeWindowCacheType);
|
|
||||||
if (!dict.TryGetValue(key, out var cahcheItem))
|
|
||||||
{
|
|
||||||
dict.TryAdd(key, new TimeWindowCacheItem(key, timeWindowCacheType));
|
|
||||||
}
|
|
||||||
dict[key].AddData(data);
|
|
||||||
return ValueTask.CompletedTask;
|
return ValueTask.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueTask<CachedValue[]> GetDataFromTimeWindowCache(string key, TimeWindowCacheType timeWindowCacheType)
|
|
||||||
{
|
|
||||||
var dict = GetDict(timeWindowCacheType);
|
|
||||||
if (dict.TryGetValue(key, out var cahcheItem))
|
|
||||||
{
|
|
||||||
return cahcheItem.GetValues();
|
|
||||||
}
|
|
||||||
return ValueTask.FromResult(Array.Empty<CachedValue>());
|
|
||||||
}
|
|
||||||
|
|
||||||
private ConcurrentDictionary<string, TimeWindowCacheItem> GetDict(TimeWindowCacheType timeWindowCacheType)
|
|
||||||
{
|
|
||||||
switch (timeWindowCacheType)
|
|
||||||
{
|
|
||||||
case TimeWindowCacheType._2_Minutes:
|
|
||||||
{
|
|
||||||
return _2_minTimeWindows;
|
|
||||||
}
|
|
||||||
case TimeWindowCacheType._15_Minutes:
|
|
||||||
{
|
|
||||||
return _15_minTimeWindows;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
return _1_minTimeWindows; ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueTask AddData(INewPrice priceChange)
|
public ValueTask AddData(INewPrice priceChange)
|
||||||
{
|
{
|
||||||
if (priceChange.Figi != Figi) return ValueTask.CompletedTask;
|
if (priceChange.Figi != Figi) return ValueTask.CompletedTask;
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
namespace KLHZ.Trader.Core.Exchange
|
|
||||||
{
|
|
||||||
internal static class Constants
|
|
||||||
{
|
|
||||||
internal const string _1minCacheKey = "1min";
|
|
||||||
internal const string BigWindowCrossingAverageProcessor = "Trader_big";
|
|
||||||
internal const string SmallWindowCrossingAverageProcessor = "Trader_small";
|
|
||||||
internal const string AreasRelationProcessor = "balancescalc30min";
|
|
||||||
internal readonly static TimeSpan AreasRelationWindow = TimeSpan.FromMinutes(15);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -29,9 +29,11 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
private readonly TraderDataProvider _tradeDataProvider;
|
private readonly TraderDataProvider _tradeDataProvider;
|
||||||
private readonly ILogger<Trader> _logger;
|
private readonly ILogger<Trader> _logger;
|
||||||
private readonly ConcurrentDictionary<string, DateTime> OpeningStops = new();
|
private readonly ConcurrentDictionary<string, DateTime> OpeningStops = new();
|
||||||
private readonly ConcurrentDictionary<string, DateTime> ClosingStops = new();
|
|
||||||
private readonly ConcurrentDictionary<string, InstrumentSettings> Leverages = new();
|
private readonly ConcurrentDictionary<string, InstrumentSettings> Leverages = new();
|
||||||
|
|
||||||
|
private readonly string _bigWindowProcessor = nameof(Trader) + "_big";
|
||||||
|
private readonly string _smallWindowProcessor = nameof(Trader) + "_small";
|
||||||
|
|
||||||
private readonly decimal _futureComission;
|
private readonly decimal _futureComission;
|
||||||
private readonly decimal _shareComission;
|
private readonly decimal _shareComission;
|
||||||
private readonly decimal _accountCashPart;
|
private readonly decimal _accountCashPart;
|
||||||
|
@ -73,6 +75,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
|
|
||||||
private async Task ProcessPrices()
|
private async Task ProcessPrices()
|
||||||
{
|
{
|
||||||
|
var buffer = new LinkedList<(DateTime, double)>();
|
||||||
while (await _pricesChannel.Reader.WaitToReadAsync())
|
while (await _pricesChannel.Reader.WaitToReadAsync())
|
||||||
{
|
{
|
||||||
var message = await _pricesChannel.Reader.ReadAsync();
|
var message = await _pricesChannel.Reader.ReadAsync();
|
||||||
|
@ -88,15 +91,18 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
{
|
{
|
||||||
if (message.Figi == "FUTIMOEXF000")
|
if (message.Figi == "FUTIMOEXF000")
|
||||||
{
|
{
|
||||||
ProcessStops(message, currentTime);
|
|
||||||
var windowMaxSize = 1000;
|
var windowMaxSize = 1000;
|
||||||
await SellAssetsIfNeed(message);
|
await SellAssetsIfNeed(message);
|
||||||
var data = await _tradeDataProvider.GetData(message.Figi, windowMaxSize);
|
var data = await _tradeDataProvider.GetData(message.Figi, windowMaxSize);
|
||||||
|
if (data.timestamps.Length <= 1)
|
||||||
|
{
|
||||||
|
buffer.Clear();
|
||||||
|
}
|
||||||
var state = ExchangeScheduler.GetCurrentState(message.Time);
|
var state = ExchangeScheduler.GetCurrentState(message.Time);
|
||||||
await ProcessClearing(data, state, message);
|
await ProcessClearing(data, state, message);
|
||||||
|
|
||||||
|
ProcessOpeningStops(message, currentTime);
|
||||||
await ProcessNewPriceIMOEXF(data, state, message, windowMaxSize);
|
await ProcessNewPriceIMOEXF(data, state, message, windowMaxSize, buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -122,8 +128,8 @@ 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;
|
|
||||||
if (message.Time - asset.BoughtAt > TimeSpan.FromMinutes(4) && profit < -66m && !ClosingStops.ContainsKey(stoppingKey))
|
if (message.Time - asset.BoughtAt > TimeSpan.FromMinutes(4) && profit<-66m)
|
||||||
{
|
{
|
||||||
await _dataBus.Broadcast(new TradeCommand()
|
await _dataBus.Broadcast(new TradeCommand()
|
||||||
{
|
{
|
||||||
|
@ -136,12 +142,10 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
EnableMargin = false,
|
EnableMargin = false,
|
||||||
});
|
});
|
||||||
OpeningStops[message.Figi] = DateTime.UtcNow.AddMinutes(10);
|
OpeningStops[message.Figi] = DateTime.UtcNow.AddMinutes(10);
|
||||||
ClosingStops[stoppingKey] = DateTime.UtcNow.AddSeconds(30);
|
|
||||||
await LogDeclision(DeclisionTradeAction.CloseLong, message, profit);
|
await LogDeclision(DeclisionTradeAction.CloseLong, message, profit);
|
||||||
await LogDeclision(DeclisionTradeAction.CloseLongReal, message, profit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.Time - asset.BoughtAt > TimeSpan.FromHours(4) && profit > 100 && !ClosingStops.ContainsKey(stoppingKey))
|
if (message.Time - asset.BoughtAt > TimeSpan.FromHours(4) && profit> 100)
|
||||||
{
|
{
|
||||||
await _dataBus.Broadcast(new TradeCommand()
|
await _dataBus.Broadcast(new TradeCommand()
|
||||||
{
|
{
|
||||||
|
@ -153,9 +157,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
RecomendPrice = null,
|
RecomendPrice = null,
|
||||||
EnableMargin = false,
|
EnableMargin = false,
|
||||||
});
|
});
|
||||||
ClosingStops[stoppingKey] = DateTime.UtcNow.AddSeconds(30);
|
|
||||||
await LogDeclision(DeclisionTradeAction.CloseLong, message, profit);
|
await LogDeclision(DeclisionTradeAction.CloseLong, message, profit);
|
||||||
await LogDeclision(DeclisionTradeAction.CloseLongReal, message, profit);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,7 +165,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
|
|
||||||
private async Task ProcessNewPriceIMOEXF((DateTime[] timestamps, decimal[] prices) data,
|
private async Task ProcessNewPriceIMOEXF((DateTime[] timestamps, decimal[] prices) data,
|
||||||
ExchangeState state,
|
ExchangeState state,
|
||||||
INewPrice message, int windowMaxSize)
|
INewPrice message, int windowMaxSize, LinkedList<(DateTime time, double val)> areasBuffer)
|
||||||
{
|
{
|
||||||
var res = TradingEvent.None;
|
var res = TradingEvent.None;
|
||||||
var resultMoveAvFull = MovingAverage.CheckByWindowAverageMean(data.timestamps, data.prices,
|
var resultMoveAvFull = MovingAverage.CheckByWindowAverageMean(data.timestamps, data.prices,
|
||||||
|
@ -173,22 +175,21 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
|
|
||||||
if (resultMoveAvFull.bigWindowAv != 0)
|
if (resultMoveAvFull.bigWindowAv != 0)
|
||||||
{
|
{
|
||||||
await LogPrice(message, Constants.BigWindowCrossingAverageProcessor, resultMoveAvFull.bigWindowAv);
|
await LogPrice(message, _bigWindowProcessor, resultMoveAvFull.bigWindowAv);
|
||||||
await LogPrice(message, Constants.SmallWindowCrossingAverageProcessor, resultMoveAvFull.smallWindowAv);
|
await LogPrice(message, _smallWindowProcessor, resultMoveAvFull.smallWindowAv);
|
||||||
}
|
}
|
||||||
|
|
||||||
var areasRel = -1m;
|
var areasRel = -1m;
|
||||||
if (ShapeAreaCalculator.TryGetAreasRelation(data.timestamps, data.prices, message.Value, Constants.AreasRelationWindow, out var rel))
|
if (ShapeAreaCalculator.TryGetAreasRelation(data.timestamps, data.prices, message.Value, TimeSpan.FromMinutes(15), out var rel))
|
||||||
{
|
{
|
||||||
await _tradeDataProvider.AddDataTo1MinuteWindowCache(message.Figi, Constants._1minCacheKey, new Contracts.Declisions.Dtos.CachedValue()
|
areasBuffer.AddLast((message.Time, rel));
|
||||||
|
if (areasBuffer.Last != null && areasBuffer.First != null
|
||||||
|
&& areasBuffer.Last.Value.time - areasBuffer.First.Value.time > TimeSpan.FromMinutes(1))
|
||||||
{
|
{
|
||||||
Time = message.Time,
|
areasBuffer.RemoveFirst();
|
||||||
Value = (decimal)rel
|
}
|
||||||
});
|
areasRel = (decimal)areasBuffer.Sum(a => a.val) / areasBuffer.Count;
|
||||||
var areas = await _tradeDataProvider.GetDataFrom1MinuteWindowCache(message.Figi, Constants._1minCacheKey);
|
await LogPrice(message, "balancescalc30min", areasRel);
|
||||||
|
|
||||||
areasRel = (decimal)areas.Sum(a => a.Value) / areas.Length;
|
|
||||||
await LogPrice(message, Constants.AreasRelationProcessor, areasRel);
|
|
||||||
}
|
}
|
||||||
if ((res & TradingEvent.UptrendStart) == TradingEvent.UptrendStart
|
if ((res & TradingEvent.UptrendStart) == TradingEvent.UptrendStart
|
||||||
&& !OpeningStops.TryGetValue(message.Figi, out _)
|
&& !OpeningStops.TryGetValue(message.Figi, out _)
|
||||||
|
@ -231,6 +232,10 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
}
|
}
|
||||||
await LogDeclision(DeclisionTradeAction.OpenLong, message);
|
await LogDeclision(DeclisionTradeAction.OpenLong, message);
|
||||||
}
|
}
|
||||||
|
//else if (areasRel >=75)
|
||||||
|
//{
|
||||||
|
// await LogDeclision(DeclisionTradeAction.OpenShort, message);
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((res & TradingEvent.UptrendEnd) == TradingEvent.UptrendEnd)
|
if ((res & TradingEvent.UptrendEnd) == TradingEvent.UptrendEnd)
|
||||||
|
@ -257,10 +262,8 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
profit = TradingCalculator.CaclProfit(asset.BoughtPrice, message.Value,
|
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;
|
if (profit > 0)
|
||||||
if (profit > 0 && !ClosingStops.ContainsKey(stoppingKey))
|
|
||||||
{
|
{
|
||||||
ClosingStops[stoppingKey] = DateTime.UtcNow.AddSeconds(30);
|
|
||||||
await _dataBus.Broadcast(new TradeCommand()
|
await _dataBus.Broadcast(new TradeCommand()
|
||||||
{
|
{
|
||||||
AccountId = asset.AccountId,
|
AccountId = asset.AccountId,
|
||||||
|
@ -293,7 +296,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessStops(INewPrice message, DateTime currentTime)
|
private void ProcessOpeningStops(INewPrice message, DateTime currentTime)
|
||||||
{
|
{
|
||||||
if (OpeningStops.TryGetValue(message.Figi, out var dt))
|
if (OpeningStops.TryGetValue(message.Figi, out var dt))
|
||||||
{
|
{
|
||||||
|
@ -302,13 +305,6 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
OpeningStops.TryRemove(message.Figi, out _);
|
OpeningStops.TryRemove(message.Figi, out _);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ClosingStops.TryGetValue(message.Figi, out var dt2))
|
|
||||||
{
|
|
||||||
if (dt2 < currentTime)
|
|
||||||
{
|
|
||||||
ClosingStops.TryRemove(message.Figi, out _);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task LogPrice(INewPrice message, string processor, decimal value)
|
private async Task LogPrice(INewPrice message, string processor, decimal value)
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
using KLHZ.Trader.Core.Contracts.Declisions.Dtos;
|
using KLHZ.Trader.Core.Contracts.Declisions.Interfaces;
|
||||||
using KLHZ.Trader.Core.Contracts.Declisions.Dtos.Enums;
|
|
||||||
using KLHZ.Trader.Core.Contracts.Declisions.Interfaces;
|
|
||||||
using KLHZ.Trader.Core.Contracts.Messaging.Dtos;
|
using KLHZ.Trader.Core.Contracts.Messaging.Dtos;
|
||||||
using KLHZ.Trader.Core.Contracts.Messaging.Dtos.Interfaces;
|
using KLHZ.Trader.Core.Contracts.Messaging.Dtos.Interfaces;
|
||||||
using KLHZ.Trader.Core.DataLayer;
|
using KLHZ.Trader.Core.DataLayer;
|
||||||
|
@ -10,7 +8,6 @@ using KLHZ.Trader.Core.Exchange.Extentions;
|
||||||
using KLHZ.Trader.Core.Exchange.Models.AssetsAccounting;
|
using KLHZ.Trader.Core.Exchange.Models.AssetsAccounting;
|
||||||
using KLHZ.Trader.Core.Exchange.Models.Configs;
|
using KLHZ.Trader.Core.Exchange.Models.Configs;
|
||||||
using KLHZ.Trader.Core.Math.Declisions.Services.Cache;
|
using KLHZ.Trader.Core.Math.Declisions.Services.Cache;
|
||||||
using KLHZ.Trader.Core.Math.Declisions.Utils;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
@ -99,25 +96,6 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask AddDataTo1MinuteWindowCache(string figi, string key, CachedValue data)
|
|
||||||
{
|
|
||||||
if (!_historyCash.TryGetValue(figi, out var unit))
|
|
||||||
{
|
|
||||||
unit = new PriceHistoryCacheUnit2(figi);
|
|
||||||
_historyCash.TryAdd(figi, unit);
|
|
||||||
}
|
|
||||||
await _historyCash[figi].AddDataToTimeWindowCache(key, data, TimeWindowCacheType._1_Minute);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueTask<CachedValue[]> GetDataFrom1MinuteWindowCache(string figi, string key)
|
|
||||||
{
|
|
||||||
if (_historyCash.TryGetValue(figi, out var cahcheItem))
|
|
||||||
{
|
|
||||||
return cahcheItem.GetDataFromTimeWindowCache(key, TimeWindowCacheType._1_Minute);
|
|
||||||
}
|
|
||||||
return ValueTask.FromResult(Array.Empty<CachedValue>());
|
|
||||||
}
|
|
||||||
|
|
||||||
public async ValueTask AddOrderbook(IOrderbook orderbook)
|
public async ValueTask AddOrderbook(IOrderbook orderbook)
|
||||||
{
|
{
|
||||||
if (!_historyCash.TryGetValue(orderbook.Figi, out var unit))
|
if (!_historyCash.TryGetValue(orderbook.Figi, out var unit))
|
||||||
|
@ -183,12 +161,6 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
foreach (var price in data)
|
foreach (var price in data)
|
||||||
{
|
{
|
||||||
await AddData(price);
|
await AddData(price);
|
||||||
|
|
||||||
var cachedData = await GetData(price.Figi);
|
|
||||||
if (ShapeAreaCalculator.TryGetAreasRelation(cachedData.timestamps, cachedData.prices, price.Value, Constants.AreasRelationWindow, out var rel))
|
|
||||||
{
|
|
||||||
await AddDataTo1MinuteWindowCache(price.Figi, Constants._1minCacheKey, new CachedValue() { Time = price.Time, Value = (decimal)rel });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace KLHZ.Trader.Service.Controllers
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var time1 = DateTime.UtcNow.AddDays(-30);
|
var time1 = DateTime.UtcNow.AddDays(-30);
|
||||||
var time2 = DateTime.UtcNow.AddMinutes(18);
|
var time2 = DateTime.UtcNow.AddMinutes(30);
|
||||||
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