Skip to content

Commit

Permalink
Merge pull request #536 from LykkeBusiness/LT-5364
Browse files Browse the repository at this point in the history
LT-5364 -  ExternalOrderWasNotExecuted as warning
  • Loading branch information
dziudan-lykke authored Aug 5, 2024
2 parents cb976a0 + 8f8896e commit de71b63
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2019 Lykke Corp.
// See the LICENSE file in the project root for more information.

using System;
using MarginTrading.Backend.Contracts.ExchangeConnector;

namespace MarginTrading.Backend.Core.Exceptions
{
public class ExternalOrderWasNotExecuted : Exception
{
public ExternalOrderWasNotExecuted(ExecutionReport executionResult) : base($"External order was not executed. Status: {executionResult.ExecutionStatus}. Failure: {executionResult.FailureType}")
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using Common;
using Common.Log;
using Lykke.Common.Log;
using MarginTrading.Backend.Contracts.ExchangeConnector;
using MarginTrading.Backend.Core;
using MarginTrading.Backend.Core.Exceptions;
Expand All @@ -23,6 +24,7 @@
using MarginTrading.Common.Extensions;
using MarginTrading.Common.Services;
using MarginTrading.Common.Settings;
using Microsoft.Extensions.Logging;
using OrderType = MarginTrading.Backend.Contracts.ExchangeConnector.OrderType;

namespace MarginTrading.Backend.Services.MatchingEngines
Expand Down Expand Up @@ -143,8 +145,7 @@ public async ValueTask<MatchedOrderCollection> MatchOrderAsync(OrderFulfillmentP

if (!executionResult.Success)
{
var ex = new Exception(
$"External order was not executed. Status: {executionResult.ExecutionStatus}. Failure: {executionResult.FailureType}");
var ex = new ExternalOrderWasNotExecuted(executionResult);
LogOrderExecutionException(order, externalOrderModel, ex);
}
else
Expand Down Expand Up @@ -198,9 +199,17 @@ private void LogOrderExecutionException(Order internalOrder, OrderModel external
? "Fake"
: _exchangeConnectorServiceClient.ServiceUrl;

_log.WriteError(
$"{nameof(StpMatchingEngine)}:{nameof(MatchOrderAsync)}:{connector}",
$"Internal order: {internalOrder.ToJson()}, External order model: {externalOrderModel.ToJson()}", ex);
var process = $"{nameof(StpMatchingEngine)}:{nameof(MatchOrderAsync)}:{connector}";
var context = $"Internal order: {internalOrder.ToJson()}, External order model: {externalOrderModel.ToJson()}";

if (ex is ExternalOrderWasNotExecuted)
{
_log.WriteWarning(process, context, string.Empty ,ex);
}
else
{
_log.WriteError(process, context, ex);
}
}

public (string externalProviderId, decimal? price) GetBestPriceForOpen(string assetPairId, decimal volume)
Expand Down

0 comments on commit de71b63

Please sign in to comment.