//-------------------------------------------------------------------------
        /// <summary>
        /// Converts an FpML 'BuyerSeller.model' to a {@code BuySell}.
        /// <para>
        /// The <seealso cref="TradeInfo"/> builder is updated with the counterparty.
        ///
        /// </para>
        /// </summary>
        /// <param name="baseEl">  the FpML payer receiver model element </param>
        /// <param name="tradeInfoBuilder">  the builder of the trade info </param>
        /// <returns> the pay/receive flag </returns>
        /// <exception cref="RuntimeException"> if unable to parse </exception>
        public BuySell parseBuyerSeller(XmlElement baseEl, TradeInfoBuilder tradeInfoBuilder)
        {
            string buyerPartyReference  = baseEl.getChild("buyerPartyReference").getAttribute(FpmlDocument.HREF);
            string sellerPartyReference = baseEl.getChild("sellerPartyReference").getAttribute(FpmlDocument.HREF);

            if (ourPartyHrefIds.Empty || ourPartyHrefIds.contains(buyerPartyReference))
            {
                tradeInfoBuilder.counterparty(StandardId.of(FPML_PARTY_SCHEME, parties.get(sellerPartyReference).get(0)));
                return(BuySell.BUY);
            }
            else if (ourPartyHrefIds.contains(sellerPartyReference))
            {
                tradeInfoBuilder.counterparty(StandardId.of(FPML_PARTY_SCHEME, parties.get(buyerPartyReference).get(0)));
                return(BuySell.SELL);
            }
            else
            {
                throw new FpmlParseException(Messages.format("Neither buyerPartyReference nor sellerPartyReference contain our party ID: {}", ourPartyHrefIds));
            }
        }
        /// <summary>
        /// Converts an FpML 'PayerReceiver.model' to a {@code PayReceive}.
        /// <para>
        /// The <seealso cref="TradeInfo"/> builder is updated with the counterparty.
        ///
        /// </para>
        /// </summary>
        /// <param name="baseEl">  the FpML payer receiver model element </param>
        /// <param name="tradeInfoBuilder">  the builder of the trade info </param>
        /// <returns> the pay/receive flag </returns>
        /// <exception cref="RuntimeException"> if unable to parse </exception>
        public PayReceive parsePayerReceiver(XmlElement baseEl, TradeInfoBuilder tradeInfoBuilder)
        {
            string payerPartyReference    = baseEl.getChild("payerPartyReference").getAttribute(HREF);
            string receiverPartyReference = baseEl.getChild("receiverPartyReference").getAttribute(HREF);
            object currentCounterparty    = tradeInfoBuilder.build().Counterparty.orElse(null);

            // determine direction and setup counterparty
            if ((ourPartyHrefIds.Empty && currentCounterparty == null) || ourPartyHrefIds.contains(payerPartyReference))
            {
                StandardId proposedCounterparty = StandardId.of(FPML_PARTY_SCHEME, parties.get(receiverPartyReference).get(0));
                if (currentCounterparty == null)
                {
                    tradeInfoBuilder.counterparty(proposedCounterparty);
                }
                else if (!currentCounterparty.Equals(proposedCounterparty))
                {
                    throw new FpmlParseException(Messages.format("Two different counterparties found: {} and {}", currentCounterparty, proposedCounterparty));
                }
                return(PayReceive.PAY);
            }
            else if (ourPartyHrefIds.Empty || ourPartyHrefIds.contains(receiverPartyReference))
            {
                StandardId proposedCounterparty = StandardId.of(FPML_PARTY_SCHEME, parties.get(payerPartyReference).get(0));
                if (currentCounterparty == null)
                {
                    tradeInfoBuilder.counterparty(proposedCounterparty);
                }
                else if (!currentCounterparty.Equals(proposedCounterparty))
                {
                    throw new FpmlParseException(Messages.format("Two different counterparties found: {} and {}", currentCounterparty, proposedCounterparty));
                }
                return(PayReceive.RECEIVE);
            }
            else
            {
                throw new FpmlParseException(Messages.format("Neither payerPartyReference nor receiverPartyReference contain our party ID: {}", ourPartyHrefIds));
            }
        }
示例#3
0
        // parse the trade info
        private TradeInfo parseTradeInfo(CsvRow row)
        {
            TradeInfoBuilder infoBuilder = TradeInfo.builder();
            string           scheme      = row.findField(ID_SCHEME_FIELD).orElse(DEFAULT_TRADE_SCHEME);

            row.findValue(ID_FIELD).ifPresent(id => infoBuilder.id(StandardId.of(scheme, id)));
            string schemeCpty = row.findValue(CPTY_SCHEME_FIELD).orElse(DEFAULT_CPTY_SCHEME);

            row.findValue(CPTY_FIELD).ifPresent(cpty => infoBuilder.counterparty(StandardId.of(schemeCpty, cpty)));
            row.findValue(TRADE_DATE_FIELD).ifPresent(dateStr => infoBuilder.tradeDate(LoaderUtils.parseDate(dateStr)));
            row.findValue(TRADE_TIME_FIELD).ifPresent(timeStr => infoBuilder.tradeTime(LoaderUtils.parseTime(timeStr)));
            row.findValue(TRADE_ZONE_FIELD).ifPresent(zoneStr => infoBuilder.zone(ZoneId.of(zoneStr)));
            row.findValue(SETTLEMENT_DATE_FIELD).ifPresent(dateStr => infoBuilder.settlementDate(LoaderUtils.parseDate(dateStr)));
            resolver.parseTradeInfo(row, infoBuilder);
            return(infoBuilder.build());
        }