diff --git a/KLHZ.Trader.Core.Tests/TraderTests.cs b/KLHZ.Trader.Core.Tests/TraderTests.cs index 0c82188..df01c3e 100644 --- a/KLHZ.Trader.Core.Tests/TraderTests.cs +++ b/KLHZ.Trader.Core.Tests/TraderTests.cs @@ -1,19 +1,4 @@ -using Castle.Core.Logging; -using KLHZ.Trader.Core.Common; -using KLHZ.Trader.Core.Common.Messaging.Services; -using KLHZ.Trader.Core.DataLayer; -using KLHZ.Trader.Core.Exchange.Models.AssetsAccounting; -using KLHZ.Trader.Core.Exchange.Models.Configs; -using KLHZ.Trader.Core.Math.Common; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; -using NSubstitute; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using KLHZ.Trader.Core.Exchange.Models.AssetsAccounting; namespace KLHZ.Trader.Core.Tests { diff --git a/KLHZ.Trader.Core/Common/BotModeSwitcher.cs b/KLHZ.Trader.Core/Common/BotModeSwitcher.cs index 438658c..5efaa4e 100644 --- a/KLHZ.Trader.Core/Common/BotModeSwitcher.cs +++ b/KLHZ.Trader.Core/Common/BotModeSwitcher.cs @@ -3,8 +3,8 @@ public static class BotModeSwitcher { private readonly static object _locker = new(); - private static bool _canSell = true; - private static bool _canPurchase = true; + private static bool _canSell = false; + private static bool _canPurchase = false; public static bool CanSell() { diff --git a/KLHZ.Trader.Core/Exchange/Services/TradeDataProvider.cs b/KLHZ.Trader.Core/Exchange/Services/TradeDataProvider.cs index 910e558..e47fbd3 100644 --- a/KLHZ.Trader.Core/Exchange/Services/TradeDataProvider.cs +++ b/KLHZ.Trader.Core/Exchange/Services/TradeDataProvider.cs @@ -61,7 +61,7 @@ namespace KLHZ.Trader.Core.Exchange.Services if (_instrumentsFigis.Contains(future.Figi)) { _tickersCache.TryAdd(future.Figi, future.Ticker); - _assetTypesCache.TryAdd(future.Figi, AssetType.Common); + _assetTypesCache.TryAdd(future.Figi, AssetType.Futures); } } diff --git a/KLHZ.Trader.Core/Exchange/Services/Trader.cs b/KLHZ.Trader.Core/Exchange/Services/Trader.cs index 48106b3..5156d83 100644 --- a/KLHZ.Trader.Core/Exchange/Services/Trader.cs +++ b/KLHZ.Trader.Core/Exchange/Services/Trader.cs @@ -120,7 +120,7 @@ namespace KLHZ.Trader.Core.Exchange.Services DeferredLongOpens.TryRemove(message.Figi, out _); if (message.Value - longOpen.Price < 1) { - if (!message.IsHistoricalData) + if (!message.IsHistoricalData && BotModeSwitcher.CanPurchase()) { var accounts = _tradeDataProvider.Accounts .Where(a => !a.Value.Assets.ContainsKey(message.Figi)) @@ -158,7 +158,8 @@ namespace KLHZ.Trader.Core.Exchange.Services DeferredLongCloses.TryRemove(message.Figi, out _); if (longClose.Price - message.Value < 1) { - if (!message.IsHistoricalData) + var assetType = _tradeDataProvider.GetAssetTypeByFigi(message.Figi); + if (!message.IsHistoricalData && BotModeSwitcher.CanSell()) { var assetsForClose = _tradeDataProvider.Accounts .SelectMany(a => a.Value.Assets.Values) @@ -167,7 +168,7 @@ namespace KLHZ.Trader.Core.Exchange.Services foreach (var asset in assetsForClose) { var profit = 0m; - var assetType = _tradeDataProvider.GetAssetTypeByFigi(message.Figi); + if (assetType == AssetType.Common && asset.Count > 0) { profit = TradingCalculator.CaclProfit(asset.BoughtPrice, message.Value, @@ -236,10 +237,22 @@ namespace KLHZ.Trader.Core.Exchange.Services res |= (uptrendStarts & TradingEvent.UptrendStart); - //res |= (uptrendStarts2 & TradingEvent.UptrendStart); - //res |= downtrendEnds; res |= resultLongClose; res |= resultMoveAvFull.events; + + //res = TradingEvent.None; + + //if (!stopBuy &&RandomNumberGenerator.GetInt32(100) < 20) + //{ + // res |= TradingEvent.UptrendStart; + //} + //else if (!stopSell && (RandomNumberGenerator.GetInt32(100) < 20)) + //{ + // res |= TradingEvent.UptrendEnd; + //} + + + if (resultMoveAvFull.bigWindowAv != 0) { LogPrice(processedPrices, message, bigWindowProcessor, resultMoveAvFull.bigWindowAv); @@ -247,7 +260,7 @@ namespace KLHZ.Trader.Core.Exchange.Services } if ((resultLongClose & TradingEvent.StopBuy) == TradingEvent.StopBuy) { - var stopTo = (message.IsHistoricalData ? message.Time : DateTime.UtcNow).AddMinutes(_buyStopLength/2); + var stopTo = (message.IsHistoricalData ? message.Time : DateTime.UtcNow).AddMinutes(_buyStopLength / 2); OpeningStops.AddOrUpdate(message.Figi, stopTo, (k, v) => stopTo); //LogDeclision(declisionsForSave, DeclisionTradeAction.StopBuy, message); } diff --git a/KLHZ.Trader.Core/Exchange/Utils/ExchangeScheduler.cs b/KLHZ.Trader.Core/Exchange/Utils/ExchangeScheduler.cs index 714c944..8efe354 100644 --- a/KLHZ.Trader.Core/Exchange/Utils/ExchangeScheduler.cs +++ b/KLHZ.Trader.Core/Exchange/Utils/ExchangeScheduler.cs @@ -10,11 +10,11 @@ namespace KLHZ.Trader.Core.Exchange.Utils private readonly static TimeOnly _openTimeHoliday = new(7, 10); private readonly static TimeOnly _closeTimeHoliday = new(17, 45); - private readonly static TimeOnly _firstClearingStart = new(10, 55); + private readonly static TimeOnly _firstClearingStart = new(10, 45); private readonly static TimeOnly _firstClearingEnd = new(11, 10); - private readonly static TimeOnly _mainClearingStart = new(15, 50); - private readonly static TimeOnly _mainClearingEnd = new(16, 5); + private readonly static TimeOnly _mainClearingStart = new(15, 45); + private readonly static TimeOnly _mainClearingEnd = new(16, 10); internal static ExchangeState GetCurrentState(DateTime? currentDt = null) { diff --git a/KLHZ.Trader.Core/Exchange/Utils/TraderFuncs.cs b/KLHZ.Trader.Core/Exchange/Utils/TraderFuncs.cs deleted file mode 100644 index 0531730..0000000 --- a/KLHZ.Trader.Core/Exchange/Utils/TraderFuncs.cs +++ /dev/null @@ -1,25 +0,0 @@ -using KLHZ.Trader.Core.Contracts.Messaging.Dtos; -using KLHZ.Trader.Core.Contracts.Messaging.Dtos.Interfaces; -using KLHZ.Trader.Core.DataLayer.Entities.Declisions; -using KLHZ.Trader.Core.DataLayer.Entities.Declisions.Enums; -using KLHZ.Trader.Core.Exchange.Models.AssetsAccounting; -using KLHZ.Trader.Core.Exchange.Services; -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace KLHZ.Trader.Core.Exchange.Utils -{ - internal static class TraderFuncs - { - //internal static TradeCommand[] CreateBuyCommands(ConcurrentDictionary accounts, INewPrice message, List declisions) - //{ - // var accs = accounts.Where(a => !a.Value.Assets.ContainsKey(message.Figi)) - // .ToArray(); - - //} - } -} diff --git a/KLHZ.Trader.Service/Program.cs b/KLHZ.Trader.Service/Program.cs index 75b2fb5..c8eddc8 100644 --- a/KLHZ.Trader.Service/Program.cs +++ b/KLHZ.Trader.Service/Program.cs @@ -1,4 +1,3 @@ -using KLHZ.Trader.Core.Common; using KLHZ.Trader.Core.Common.Messaging.Services; using KLHZ.Trader.Core.Contracts.Messaging.Interfaces; using KLHZ.Trader.Core.DataLayer;