private Task CommitExceptionHandler(Exception exception, IOrderHistory order, ITrade trade)
        {
            var context = $"Error {exception.Message} \n" +
                          $"Entity <{nameof(IOrderHistory)}>: \n" +
                          order.ToJson() + " \n" +
                          $"Entity <{nameof(ITrade)}>: \n" +
                          trade?.ToJson();

            return(_log.WriteErrorAsync(nameof(OrdersHistorySqlRepository), nameof(AddAsync), context, exception));
        }
        public async Task AddAsync(IOrderHistory order)
        {
            using (var conn = new SqlConnection(_settings.Db.ReportsSqlConnString))
            {
                var query = $"insert into {TableName} " +
                            @"(Id, Code, ClientId, TradingConditionId, AccountAssetId, Instrument, Type, CreateDate, OpenDate,
                            CloseDate, ExpectedOpenPrice, OpenPrice, ClosePrice, QuoteRate, Volume, TakeProfit, 
                            StopLoss, CommissionLot, OpenCommission, CloseCommission, SwapCommission, StartClosingDate, 
                            Status, CloseReason, FillType, RejectReason, RejectReasonText, Comment, MatchedVolume,
                            MatchedCloseVolume, Fpl, PnL, InterestRateSwap, MarginInit, MarginMaintenance, 
                            OrderUpdateType, OpenExternalOrderId, OpenExternalProviderId, CloseExternalOrderId,
                            CloseExternalProviderId, MatchingEngineMode, LegalEntity) 
                             values 
                            (@Id, @Code, @ClientId, @TradingConditionId, @AccountAssetId, @Instrument, @Type, @CreateDate, @OpenDate,
                            @CloseDate, @ExpectedOpenPrice, @OpenPrice, @ClosePrice, @QuoteRate, @Volume, @TakeProfit, 
                            @StopLoss, @CommissionLot, @OpenCommission, @CloseCommission, @SwapCommission, @StartClosingDate, 
                            @Status, @CloseReason, @FillType, @RejectReason, @RejectReasonText, @Comment, @MatchedVolume,
                            @MatchedCloseVolume, @Fpl, @PnL, @InterestRateSwap, @MarginInit, @MarginMaintenance, 
                            @OrderUpdateType, @OpenExternalOrderId, @OpenExternalProviderId, @CloseExternalOrderId,
                            @CloseExternalProviderId, @MatchingEngineMode, @LegalEntity)";

                try
                {
                    var entity = MarginTradingOrderHistoryEntity.Create(order);
                    await conn.ExecuteAsync(query, entity);
                }
                catch (Exception ex)
                {
                    var msg = $"Error {ex.Message} \n" +
                              "Entity <IOrderHistory>: \n" +
                              order.ToJson();

                    _log?.WriteWarning("AccountTransactionsReportsSqlRepository", "InsertOrReplaceAsync", msg);

                    throw new Exception(msg);
                }
            }
        }