Фиксы багов купли продажи по решению
test / deploy_trader_prod (push) Successful in 2m0s Details

main
vlad zverzhkhovskiy 2025-09-05 19:12:35 +03:00
parent f95a34e5a1
commit 83e1b0fe43
7 changed files with 26 additions and 54 deletions

View File

@ -1,19 +1,4 @@
using Castle.Core.Logging; using KLHZ.Trader.Core.Exchange.Models.AssetsAccounting;
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;
namespace KLHZ.Trader.Core.Tests namespace KLHZ.Trader.Core.Tests
{ {

View File

@ -3,8 +3,8 @@
public static class BotModeSwitcher public static class BotModeSwitcher
{ {
private readonly static object _locker = new(); private readonly static object _locker = new();
private static bool _canSell = true; private static bool _canSell = false;
private static bool _canPurchase = true; private static bool _canPurchase = false;
public static bool CanSell() public static bool CanSell()
{ {

View File

@ -61,7 +61,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
if (_instrumentsFigis.Contains(future.Figi)) if (_instrumentsFigis.Contains(future.Figi))
{ {
_tickersCache.TryAdd(future.Figi, future.Ticker); _tickersCache.TryAdd(future.Figi, future.Ticker);
_assetTypesCache.TryAdd(future.Figi, AssetType.Common); _assetTypesCache.TryAdd(future.Figi, AssetType.Futures);
} }
} }

View File

@ -120,7 +120,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
DeferredLongOpens.TryRemove(message.Figi, out _); DeferredLongOpens.TryRemove(message.Figi, out _);
if (message.Value - longOpen.Price < 1) if (message.Value - longOpen.Price < 1)
{ {
if (!message.IsHistoricalData) if (!message.IsHistoricalData && BotModeSwitcher.CanPurchase())
{ {
var accounts = _tradeDataProvider.Accounts var accounts = _tradeDataProvider.Accounts
.Where(a => !a.Value.Assets.ContainsKey(message.Figi)) .Where(a => !a.Value.Assets.ContainsKey(message.Figi))
@ -158,7 +158,8 @@ namespace KLHZ.Trader.Core.Exchange.Services
DeferredLongCloses.TryRemove(message.Figi, out _); DeferredLongCloses.TryRemove(message.Figi, out _);
if (longClose.Price - message.Value < 1) if (longClose.Price - message.Value < 1)
{ {
if (!message.IsHistoricalData) var assetType = _tradeDataProvider.GetAssetTypeByFigi(message.Figi);
if (!message.IsHistoricalData && BotModeSwitcher.CanSell())
{ {
var assetsForClose = _tradeDataProvider.Accounts var assetsForClose = _tradeDataProvider.Accounts
.SelectMany(a => a.Value.Assets.Values) .SelectMany(a => a.Value.Assets.Values)
@ -167,7 +168,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
foreach (var asset in assetsForClose) foreach (var asset in assetsForClose)
{ {
var profit = 0m; var profit = 0m;
var assetType = _tradeDataProvider.GetAssetTypeByFigi(message.Figi);
if (assetType == AssetType.Common && asset.Count > 0) if (assetType == AssetType.Common && asset.Count > 0)
{ {
profit = TradingCalculator.CaclProfit(asset.BoughtPrice, message.Value, profit = TradingCalculator.CaclProfit(asset.BoughtPrice, message.Value,
@ -236,10 +237,22 @@ namespace KLHZ.Trader.Core.Exchange.Services
res |= (uptrendStarts & TradingEvent.UptrendStart); res |= (uptrendStarts & TradingEvent.UptrendStart);
//res |= (uptrendStarts2 & TradingEvent.UptrendStart);
//res |= downtrendEnds;
res |= resultLongClose; res |= resultLongClose;
res |= resultMoveAvFull.events; 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) if (resultMoveAvFull.bigWindowAv != 0)
{ {
LogPrice(processedPrices, message, bigWindowProcessor, resultMoveAvFull.bigWindowAv); LogPrice(processedPrices, message, bigWindowProcessor, resultMoveAvFull.bigWindowAv);

View File

@ -10,11 +10,11 @@ namespace KLHZ.Trader.Core.Exchange.Utils
private readonly static TimeOnly _openTimeHoliday = new(7, 10); private readonly static TimeOnly _openTimeHoliday = new(7, 10);
private readonly static TimeOnly _closeTimeHoliday = new(17, 45); 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 _firstClearingEnd = new(11, 10);
private readonly static TimeOnly _mainClearingStart = new(15, 50); private readonly static TimeOnly _mainClearingStart = new(15, 45);
private readonly static TimeOnly _mainClearingEnd = new(16, 5); private readonly static TimeOnly _mainClearingEnd = new(16, 10);
internal static ExchangeState GetCurrentState(DateTime? currentDt = null) internal static ExchangeState GetCurrentState(DateTime? currentDt = null)
{ {

View File

@ -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<string, ManagedAccount> accounts, INewPrice message, List<Declision> declisions)
//{
// var accs = accounts.Where(a => !a.Value.Assets.ContainsKey(message.Figi))
// .ToArray();
//}
}
}

View File

@ -1,4 +1,3 @@
using KLHZ.Trader.Core.Common;
using KLHZ.Trader.Core.Common.Messaging.Services; using KLHZ.Trader.Core.Common.Messaging.Services;
using KLHZ.Trader.Core.Contracts.Messaging.Interfaces; using KLHZ.Trader.Core.Contracts.Messaging.Interfaces;
using KLHZ.Trader.Core.DataLayer; using KLHZ.Trader.Core.DataLayer;