Beispiel #1
0
 public override int GetHashCode()
 {
     return
         (BaseCurrencyAmount.GetHashCode()
          ^ UnixTimeStamp.GetHashCode()
          ^ CounterCurrencyAmount.GetHashCode()
          ^ ExchangeRate.GetHashCode()
          ^ OrderId.GetHashCode()
          ^ Pair.GetHashCode()
          ^ SourceExchange.GetHashCode()
          ^ TradeFee.GetHashCode()
          ^ TradeFeeCurrency.GetHashCode()
          ^ TransactionType.GetHashCode()
          ^ TransactionId.GetHashCode());
 }
Beispiel #2
0
        public void TestSaveLoad_TradeFee()
        {
            TradeFee fee = new TradeFee();

            fee.AddVarietyFee(new TradeFee_Code("RB", 10, 1, 2, 2, false, 15));
            fee.AddCodeFee(new TradeFee_Code("RB", 10, 1, 2, 2, false, 15));

            XmlElement elem = GetXmlRoot();

            fee.Save(elem);
            //Console.WriteLine(fee);

            TradeFee fee2 = new TradeFee();

            fee2.Load(elem);

            Assert.AreEqual(fee.ToString(), fee2.ToString());
        }
        private async Task <FileStatus> ProcessFeesFileReport(ImportedFile file, Stream stream)
        {
            if (stream == null || stream.Length == 0)
            {
                return(await Task.FromResult(FileStatus.Failed));
            }

            var newTradeFeeList = new List <TradeFee>();

            using (var reader = new StreamReader(stream))
            {
                while (!reader.EndOfStream)
                {
                    var row = await reader.ReadLineAsync();

                    if (!row.Trim().StartsWith("<ClientFee "))
                    {
                        continue;
                    }

                    try
                    {
                        var doc = XDocument.Load(new MemoryStream(Encoding.UTF8.GetBytes(row)));
                        var e   = doc.Elements().First();

                        var tradeFeeTypeId = GetOrCreateTradeFeeTypeId(new TradeFeeType
                        {
                            TradeFeeTypeName = e.Attribute(XName.Get("feeType"))?.Value
                        });

                        var tradeFeeInstrumentId = GetOrCreateTradeFeeInstrumentId(new TradeInstrument
                        {
                            InstrumentName = e.Attribute(XName.Get("currency"))?.Value
                        });

                        var tradeAccountId = GetOrCreateTradeAccountId(new TradeAccount
                        {
                            AccountName     = _fileNameMatcher.GetCorrectAccountId(e.Attribute(XName.Get("accountId"))?.Value),
                            AccountAlias    = e.Attribute(XName.Get("acctAlias"))?.Value,
                            MasterAccountId = file.MasterAccountId
                        });

                        var externalDate =
                            DateHelper.ParseDateTime(e.Attribute(XName.Get("date"))?.Value, "yyyyMMdd;HHmmss", DateHelper.DefaultDateFormat);

                        if (externalDate == null)
                        {
                            throw new Exception("There is no date");
                        }

                        var newTradeFee = new TradeFee
                        {
                            TradeAccountId    = tradeAccountId,
                            TradeFeeTypeId    = tradeFeeTypeId,
                            TradeInstrumentId = tradeFeeInstrumentId,
                            // MasterAccountId = file.MasterAccountId,
                            // ----
                            ExternalTradeName = e.Attribute(XName.Get("tradeID"))?.Value,
                            ExternalExecName  = e.Attribute(XName.Get("execID"))?.Value,
                            ExternalDate      = externalDate.Value,
                            RateToBase        = ParseDecimal(e.Attribute(XName.Get("fxRateToBase"))?.Value),
                            RevenueInCurrency = ParseDecimal(e.Attribute(XName.Get("revenue"))?.Value),
                            RevenueInBase     = ParseDecimal(e.Attribute(XName.Get("revenueInBase"))?.Value),
                            ExpenseInCurrency = ParseDecimal(e.Attribute(XName.Get("expense"))?.Value),
                            ExpenseInBase     = ParseDecimal(e.Attribute(XName.Get("expenseInBase"))?.Value),
                            NetInCurrency     = ParseDecimal(e.Attribute(XName.Get("net"))?.Value),
                            NetInBase         = ParseDecimal(e.Attribute(XName.Get("netInBase"))?.Value),
                        };

                        newTradeFeeList.Add(newTradeFee);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Error while parsing TradeFee record. \nRow: {row} \nException: {ex}");
                        loggerException.Error(this.GetErrorLogMessage(ex));
                    }
                }
            }

            {
                var counter = 0;
                foreach (var tradeFee in newTradeFeeList)
                {
                    try
                    {
                        _importJobRepository.AddTradeFee(tradeFee);

                        if (counter % 100 == 0)
                        {
                            Console.WriteLine($"Handled {counter} of {newTradeFeeList.Count} trade cash records");
                            logger.Log(LogLevel.Info,
                                       $"import$ Handled {counter} of {newTradeFeeList.Count} trade cash records");
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Error while adding TradeFee record to DB. Exception: {ex}");
                        loggerException.Error(this.GetErrorLogMessage(ex));
                    }

                    counter++;
                }
            }

            _importJobRepository.SaveChanges();

            return(await Task.FromResult(FileStatus.Success));
        }
Beispiel #4
0
        private async Task <FileStatus> ProcessFeesFileReport(ImportedFile file, Stream stream)
        {
            if (stream == null || stream.Length == 0)
            {
                return(await Task.FromResult(FileStatus.Failed));
            }

            var newTradeFeeList = new List <TradeFee>();

            using (var reader = new StreamReader(stream))
            {
                while (!reader.EndOfStream)
                {
                    var row = await reader.ReadLineAsync();

                    if (!row.Trim().StartsWith("<ClientFee "))
                    {
                        continue;
                    }

                    try
                    {
                        var doc = XDocument.Load(new MemoryStream(Encoding.UTF8.GetBytes(row)));
                        var e   = doc.Elements().First();

                        var tradeFeeTypeId = GetOrCreateTradeFeeTypeId(new TradeFeeType
                        {
                            TradeFeeTypeName = e.Attribute(XName.Get("feeType"))?.Value
                        });

                        var tradeFeeInstrumentId = GetOrCreateTradeFeeInstrumentId(new TradeInstrument
                        {
                            InstrumentName = e.Attribute(XName.Get("currency"))?.Value
                        });

                        var tradeAccountId = GetOrCreateTradeAccountId(new TradeAccount
                        {
                            AccountName =
                                _fileNameMatcher.GetCorrectAccountId(e.Attribute(XName.Get("accountId"))?.Value),
                            AccountAlias    = e.Attribute(XName.Get("acctAlias"))?.Value,
                            MasterAccountId = file.MasterAccountId,
                            ImportedFile    = file
                        });

                        var externalDate = DateHelper.ParseDateTime(e.Attribute(XName.Get("date"))?.Value,
                                                                    "yyyyMMdd;HHmmss", DateHelper.DefaultDateFormat);

                        if (externalDate == null)
                        {
                            throw new Exception("There is no date");
                        }

                        var newTradeFee = new TradeFee
                        {
                            TradeAccountId    = tradeAccountId,
                            TradeFeeTypeId    = tradeFeeTypeId,
                            TradeInstrumentId = tradeFeeInstrumentId,
                            ImportedFile      = file,

                            ExternalTradeName = e.Attribute(XName.Get("tradeID"))?.Value,
                            ExternalExecName  = e.Attribute(XName.Get("execID"))?.Value,
                            ExternalDate      = externalDate.Value,
                            RateToBase        = ParseDecimal(e.Attribute(XName.Get("fxRateToBase"))?.Value),
                            RevenueInCurrency = ParseDecimal(e.Attribute(XName.Get("revenue"))?.Value),
                            RevenueInBase     = ParseDecimal(e.Attribute(XName.Get("revenueInBase"))?.Value),
                            ExpenseInCurrency = ParseDecimal(e.Attribute(XName.Get("expense"))?.Value),
                            ExpenseInBase     = ParseDecimal(e.Attribute(XName.Get("expenseInBase"))?.Value),
                            NetInCurrency     = ParseDecimal(e.Attribute(XName.Get("net"))?.Value),
                            NetInBase         = ParseDecimal(e.Attribute(XName.Get("netInBase"))?.Value),
                        };

                        newTradeFeeList.Add(newTradeFee);
                    }
                    catch (Exception ex)
                    {
                        GlobalLogger.LogError($"Error while parsing TradeFee record. \nRow: {row}", ex, GetType().Name,
                                              true);
                    }
                }
            }

            try
            {
                _importJobRepository.AddRangeTradeFee(newTradeFeeList);
                _importJobRepository.SaveChanges();
            }
            catch (Exception ex)
            {
                GlobalLogger.LogError($"Error while adding TradeFee records to DB.", ex, GetType().Name, true);
                return(await Task.FromResult(FileStatus.Failed));
            }

            return(await Task.FromResult(FileStatus.Success));
        }
Beispiel #5
0
 public void Save(string name, TradeFee tradeFee)
 {
 }
 public void AddTradeFee(TradeFee tradeFee)
 {
     _dbContext.TradeFees.Add(tradeFee);
 }