Example #1
0
 @Test
 public void testGetBulkSecuritiesByUniqueId() {
   final FudgeMsgEnvelope fme =
       getSecuritySourceResource()
           .getSecurities(Lists.newArrayList(_uid1.toString(), _uid2.toString()));
   assertNotNull(fme);
   final FudgeMsg msg = fme.getMessage();
   assertNotNull(msg);
   FudgeMsgFormatter.outputToSystemOut(msg);
   final Collection<FudgeField> securities = msg.getAllByName(SECURITYSOURCE_SECURITY);
   assertNotNull(securities);
   assertEquals(2, securities.size());
   FudgeDeserializer deserializer =
       new FudgeDeserializer(getSecuritySourceResource().getFudgeContext());
   for (FudgeField fudgeField : securities) {
     assertNotNull(fudgeField);
     ObjectsPair<UniqueId, Security> objectsPair =
         ObjectsPairFudgeBuilder.buildObject(
             deserializer, (FudgeMsg) fudgeField.getValue(), UniqueId.class, Security.class);
     assertNotNull(objectsPair);
     UniqueId uniqueId = objectsPair.getKey();
     assertNotNull(uniqueId);
     Security security = objectsPair.getValue();
     assertNotNull(security);
   }
 }
 public static SecurityEntryData decodeSecurityEntryData(RawSecurity rawSecurity) {
   FudgeMsgEnvelope msg =
       OpenGammaFudgeContext.getInstance().deserialize(rawSecurity.getRawData());
   SecurityEntryData securityEntryData =
       OpenGammaFudgeContext.getInstance().fromFudgeMsg(SecurityEntryData.class, msg.getMessage());
   return securityEntryData;
 }
  /**
   * Inserts a new document.
   *
   * @param document the document, not null
   * @return the new document, not null
   */
  @Override
  protected MarketDataSnapshotDocument insert(final MarketDataSnapshotDocument document) {
    ArgumentChecker.notNull(document.getSnapshot(), "document.snapshot");
    ArgumentChecker.notNull(document.getName(), "document.name");

    final ManageableMarketDataSnapshot marketDataSnaphshot = document.getSnapshot();
    final long docId = nextId("snp_snapshot_seq");
    final long docOid =
        (document.getUniqueId() != null ? extractOid(document.getUniqueId()) : docId);
    // set the uniqueId (needs to go in Fudge message)
    final UniqueId uniqueId = createUniqueId(docOid, docId);
    marketDataSnaphshot.setUniqueId(uniqueId);
    document.setUniqueId(uniqueId);

    // the arguments for inserting into the marketDataSnaphshot table
    FudgeMsgEnvelope env = FUDGE_CONTEXT.toFudgeMsg(marketDataSnaphshot);
    byte[] bytes = FUDGE_CONTEXT.toByteArray(env.getMessage());
    final DbMapSqlParameterSource marketDataSnaphshotArgs =
        new DbMapSqlParameterSource()
            .addValue("doc_id", docId)
            .addValue("doc_oid", docOid)
            .addTimestamp("ver_from_instant", document.getVersionFromInstant())
            .addTimestampNullFuture("ver_to_instant", document.getVersionToInstant())
            .addTimestamp("corr_from_instant", document.getCorrectionFromInstant())
            .addTimestampNullFuture("corr_to_instant", document.getCorrectionToInstant())
            .addValue("name", document.getName())
            .addValue("detail", new SqlLobValue(bytes, getDialect().getLobHandler()), Types.BLOB);

    final String sql = getElSqlBundle().getSql("Insert", marketDataSnaphshotArgs);
    getJdbcTemplate().update(sql, marketDataSnaphshotArgs);
    return document;
  }
Example #4
0
 @Test
 public void testGetAllBondsOfIssuerType() {
   final FudgeMsgEnvelope fme =
       getSecuritySourceResource().getBondsWithIssuerName("US TREASURY N/B");
   assertNotNull(fme);
   final FudgeMsg msg = fme.getMessage();
   assertNotNull(msg);
   FudgeMsgFormatter.outputToSystemOut(msg);
   final Collection<FudgeField> securities = msg.getAllByName(SECURITYSOURCE_SECURITY);
   assertNotNull(securities);
   assertEquals(1, securities.size());
 }
 @Override
 public SecurityHistoryResult history(SecurityHistoryRequest request) {
   // POST is wrong; but is easy to write if we have a "request" document
   final FudgeMsg payload = getFudgeSerializer().objectToFudgeMsg(request);
   s_logger.debug("history-post {} to {}", payload, _targetHistoric);
   final FudgeMsgEnvelope env = getRestClient().post(_targetHistoric, payload);
   if (env == null) {
     s_logger.debug("history-recv NULL");
     return null;
   }
   s_logger.debug("history-recv {}", env.getMessage());
   return getFudgeDeserializer().fudgeMsgToObject(SecurityHistoryResult.class, env.getMessage());
 }
 @Override
 public SecurityDocument correct(SecurityDocument document) {
   final FudgeMsg payload = getFudgeSerializer().objectToFudgeMsg(document);
   final RestTarget target = _targetSecurity.resolve(document.getUniqueId().toString());
   s_logger.debug("correct-put {} to {}", payload, target);
   final FudgeMsgEnvelope env = getRestClient().put(target, payload);
   if (env == null) {
     s_logger.debug("correct-recv NULL");
     return null;
   }
   s_logger.debug("correct-recv {}", env.getMessage());
   return document;
 }
 @Override
 public SecurityDocument update(SecurityDocument document) {
   final FudgeMsg payload = getFudgeSerializer().objectToFudgeMsg(document);
   final RestTarget target = _targetSecurity.resolve(document.getUniqueId().toString());
   s_logger.debug("update-post {} to {}", payload, target);
   final FudgeMsgEnvelope env = getRestClient().post(target, payload);
   if (env == null) {
     s_logger.debug("update-recv NULL");
     return null;
   }
   s_logger.debug("update-recv {}", env.getMessage());
   document.setUniqueId(getFudgeDeserializer().fudgeMsgToObject(UniqueId.class, env.getMessage()));
   return document;
 }
Example #8
0
 private void checkSecuritiesMessage(final FudgeMsgEnvelope fme) {
   assertNotNull(fme);
   final FudgeMsg msg = fme.getMessage();
   assertNotNull(msg);
   FudgeMsgFormatter.outputToSystemOut(msg);
   final Collection<FudgeField> securities = msg.getAllByName(SECURITYSOURCE_SECURITY);
   assertNotNull(securities);
   assertEquals(2, securities.size());
 }
Example #9
0
 private void checkSecurityMessage(final FudgeMsgEnvelope fme) {
   assertNotNull(fme);
   final FudgeMsg msg = fme.getMessage();
   assertNotNull(msg);
   FudgeMsgFormatter.outputToSystemOut(msg);
   final FudgeMsg security =
       msg.getFieldValue(FudgeMsg.class, msg.getByName(SECURITYSOURCE_SECURITY));
   assertNotNull(security);
 }
 @Override
 public SecurityDocument add(final SecurityDocument document) {
   final FudgeMsg payload = getFudgeSerializer().objectToFudgeMsg(document);
   s_logger.debug("add-post {} to {}", payload, _targetSecurity);
   final FudgeMsgEnvelope env = getRestClient().post(_targetSecurity, payload);
   if (env == null) {
     s_logger.debug("add-recv NULL");
     return null;
   }
   s_logger.debug("add-recv {}", env.getMessage());
   final UniqueId uid = getFudgeDeserializer().fudgeMsgToObject(UniqueId.class, env.getMessage());
   if (uid == null) {
     return null;
   }
   document.setUniqueId(uid);
   IdUtils.setInto(document.getSecurity(), uid);
   return document;
 }
 public static List<FactorExposureData> decodeFactorExposureData(
     SecuritySource secSource, RawSecurity rawSecurity) {
   FudgeMsgEnvelope msg =
       OpenGammaFudgeContext.getInstance().deserialize(rawSecurity.getRawData());
   SecurityEntryData securityEntryData =
       OpenGammaFudgeContext.getInstance().fromFudgeMsg(SecurityEntryData.class, msg.getMessage());
   RawSecurity underlyingRawSecurity =
       (RawSecurity) secSource.getSingle(securityEntryData.getFactorSetId().toBundle());
   if (underlyingRawSecurity != null) {
     FudgeMsgEnvelope factorIdMsg =
         OpenGammaFudgeContext.getInstance().deserialize(underlyingRawSecurity.getRawData());
     @SuppressWarnings("unchecked")
     List<FactorExposureData> factorExposureDataList =
         OpenGammaFudgeContext.getInstance().fromFudgeMsg(List.class, factorIdMsg.getMessage());
     return factorExposureDataList;
   } else {
     throw new OpenGammaRuntimeException(
         "Couldn't find factor list security " + securityEntryData.getFactorSetId());
   }
 }
 /**
  * Receives a message from Fudge.
  *
  * @param fudgeContext the Fudge context, not null
  * @param msgEnvelope the message, not null
  */
 @Override
 public void messageReceived(FudgeContext fudgeContext, FudgeMsgEnvelope msgEnvelope) {
   final FudgeMsg reply = msgEnvelope.getMessage();
   final Long correlationId = getCorrelationIdFromReply(reply);
   if (correlationId == null) {
     final FudgeMessageReceiver receiver = getAsynchronousMessageReceiver();
     if (receiver == null) {
       s_logger.info("Unhandled asynchronous message {}", msgEnvelope);
     } else {
       receiver.messageReceived(fudgeContext, msgEnvelope);
     }
     return;
   }
   final ClientRequestHolder requestHolder = _pendingRequests.remove(correlationId);
   if (requestHolder == null) {
     s_logger.warn("Got a response on non-pending correlation Id {}", correlationId);
     return;
   }
   requestHolder.resultValue = reply;
   requestHolder.latch.countDown();
 }
Example #13
0
  protected void addSecuritySpecificMetaData(ManageableSecurity security, FlexiBean out) {
    if (security.getSecurityType().equals(SwapSecurity.SECURITY_TYPE)) {
      SwapSecurity swapSecurity = (SwapSecurity) security;
      out.put("payLegType", swapSecurity.getPayLeg().accept(new SwapLegClassifierVisitor()));
      out.put(
          "receiveLegType", swapSecurity.getReceiveLeg().accept(new SwapLegClassifierVisitor()));
    }
    if (security.getSecurityType().equals(FutureSecurity.SECURITY_TYPE)) {
      FutureSecurity futureSecurity = (FutureSecurity) security;
      out.put("futureSecurityType", futureSecurity.accept(new FutureSecurityTypeVisitor()));
      out.put("basket", getBondFutureBasket(security));
      Security underlyingSecurity = getUnderlyingFutureSecurity(futureSecurity);
      if (underlyingSecurity != null) {
        out.put("underlyingSecurity", underlyingSecurity);
      }
    }
    if (security.getSecurityType().equals(EquityOptionSecurity.SECURITY_TYPE)) {
      EquityOptionSecurity equityOption = (EquityOptionSecurity) security;
      addUnderlyingSecurity(out, equityOption.getUnderlyingId());
    }
    if (security.getSecurityType().equals(IRFutureOptionSecurity.SECURITY_TYPE)) {
      IRFutureOptionSecurity irFutureOption = (IRFutureOptionSecurity) security;
      addUnderlyingSecurity(out, irFutureOption.getUnderlyingId());
    }
    if (security.getSecurityType().equals(SwaptionSecurity.SECURITY_TYPE)) {
      SwaptionSecurity swaptionSecurity = (SwaptionSecurity) security;
      addUnderlyingSecurity(out, swaptionSecurity.getUnderlyingId());
    }
    if (security.getSecurityType().equals(EquityBarrierOptionSecurity.SECURITY_TYPE)) {
      EquityBarrierOptionSecurity equityBarrierOptionSecurity =
          (EquityBarrierOptionSecurity) security;
      addUnderlyingSecurity(out, equityBarrierOptionSecurity.getUnderlyingId());
    }
    if (security.getSecurityType().equals(CapFloorSecurity.SECURITY_TYPE)) {
      CapFloorSecurity capFloorSecurity = (CapFloorSecurity) security;
      addUnderlyingSecurity(out, capFloorSecurity.getUnderlyingId());
    }
    if (security.getSecurityType().equals(CapFloorCMSSpreadSecurity.SECURITY_TYPE)) {
      CapFloorCMSSpreadSecurity capFloorCMSSpreadSecurity = (CapFloorCMSSpreadSecurity) security;
      Security shortUnderlying = getSecurity(capFloorCMSSpreadSecurity.getShortId());
      Security longUnderlying = getSecurity(capFloorCMSSpreadSecurity.getLongId());
      if (shortUnderlying != null) {
        out.put("shortSecurity", shortUnderlying);
      }
      if (longUnderlying != null) {
        out.put("longSecurity", longUnderlying);
      }
    }
    if (security.getSecurityType().equals(EquityIndexOptionSecurity.SECURITY_TYPE)) {
      EquityIndexOptionSecurity equityIndxOption = (EquityIndexOptionSecurity) security;
      addUnderlyingSecurity(out, equityIndxOption.getUnderlyingId());
    }
    if (security.getSecurityType().equals(FRASecurity.SECURITY_TYPE)) {
      FRASecurity fraSecurity = (FRASecurity) security;
      addUnderlyingSecurity(out, fraSecurity.getUnderlyingId());
    }
    if (security.getSecurityType().equals(SecurityEntryData.EXTERNAL_SENSITIVITIES_SECURITY_TYPE)) {
      RawSecurity rawSecurity = (RawSecurity) security;
      FudgeMsgEnvelope msg =
          OpenGammaFudgeContext.getInstance().deserialize(rawSecurity.getRawData());
      SecurityEntryData securityEntryData =
          OpenGammaFudgeContext.getInstance()
              .fromFudgeMsg(SecurityEntryData.class, msg.getMessage());

      out.put("securityEntryData", securityEntryData);
      out.put("securityAttributes", security.getAttributes());
      RawSecurity underlyingRawSecurity =
          (RawSecurity) getSecurity(securityEntryData.getFactorSetId());
      if (underlyingRawSecurity != null) {
        FudgeMsgEnvelope factorIdMsg =
            OpenGammaFudgeContext.getInstance().deserialize(underlyingRawSecurity.getRawData());
        @SuppressWarnings("unchecked")
        List<FactorExposureData> factorExposureDataList =
            OpenGammaFudgeContext.getInstance().fromFudgeMsg(List.class, factorIdMsg.getMessage());
        s_logger.error(factorExposureDataList.toString());
        List<FactorExposure> factorExposuresList = convertToFactorExposure(factorExposureDataList);
        out.put("factorExposuresList", factorExposuresList);
      } else {
        s_logger.error("Couldn't find security");
      }
    }
    if (security
        .getSecurityType()
        .equals(FactorExposureData.EXTERNAL_SENSITIVITIES_RISK_FACTORS_SECURITY_TYPE)) {
      RawSecurity rawSecurity = (RawSecurity) security;
      FudgeMsgEnvelope msg =
          OpenGammaFudgeContext.getInstance().deserialize(rawSecurity.getRawData());
      @SuppressWarnings("unchecked")
      List<FactorExposureData> factorExposureDataList =
          OpenGammaFudgeContext.getInstance().fromFudgeMsg(List.class, msg.getMessage());
      List<FactorExposure> factorExposuresList = convertToFactorExposure(factorExposureDataList);
      out.put("factorExposuresList", factorExposuresList);
    }
  }