Package com.opengamma.master.position

Examples of com.opengamma.master.position.ManageableTrade$Meta


  }

  @Override
  public Trade getTrade(final UniqueId uniqueId) {
    ArgumentChecker.notNull(uniqueId, "uniqueId");
    final ManageableTrade manTrade = getPositionMaster().getTrade(uniqueId);
    if (manTrade == null) {
      throw new DataNotFoundException("Unable to find trade: " + uniqueId);
    }
    return manTrade;
  }
View Full Code Here


  //-------------------------------------------------------------------------
  @GET
  public Response get() {
    UniqueId tradeId = getUrlTradeId().atLatestVersion();
    ManageableTrade result = getPositionMaster().getTrade(tradeId);
    return responseOkFudge(result);
  }
View Full Code Here

  @GET
  @Path("versions/{versionId}")
  public Response getVersioned(@PathParam("versionId") String versionId) {
    UniqueId tradeId = getUrlTradeId().atVersion(versionId);
    ManageableTrade result = getPositionMaster().getTrade(tradeId);
    return responseOkFudge(result);
  }
View Full Code Here

   * @param securityPersister the supplied security persister
   * @param counterPartyGenerator the supplied counter party generator
   * @return the new trade, or null if no trade can be generated
   */
  public ManageableTrade createSecurityTrade(final QuantityGenerator quantityGenerator, final SecurityPersister securityPersister, final NameGenerator counterPartyGenerator) {
    ManageableTrade trade = null;
    final T security = createSecurity();
    if (security != null) {
      final ZonedDateTime tradeDate = previousWorkingDay(ZonedDateTime.now().minusDays(getRandom(30)), getRandomCurrency());
      trade = new ManageableTrade(quantityGenerator.createQuantity(), securityPersister.storeSecurity(security), tradeDate.toLocalDate(), tradeDate.toOffsetDateTime().toOffsetTime(),
          ExternalId.of(Counterparty.DEFAULT_SCHEME, counterPartyGenerator.createName()));
    }
    return trade;
  }
View Full Code Here

    Instant now = Instant.now(_posMaster.getClock());
   
    PositionDocument base = _posMaster.get(UniqueId.of("DbPos", "121", "0"));
    ManageablePosition pos = new ManageablePosition(BigDecimal.TEN, ExternalId.of("A", "B"));
    pos.setUniqueId(UniqueId.of("DbPos", "121", "0"));
    pos.addTrade(new ManageableTrade(BigDecimal.TEN, ExternalId.of("C", "D"), _now.toLocalDate(), _now.toOffsetTime().minusSeconds(500), ExternalId.of("CPS2", "CPV2")));
    PositionDocument input = new PositionDocument(pos);
   
    PositionDocument updated = _posMaster.update(input);
    assertEquals(false, base.getUniqueId().equals(updated.getUniqueId()));
    assertEquals(now, updated.getVersionFromInstant());
View Full Code Here

    ManageablePosition pos1 = new ManageablePosition(BigDecimal.TEN, ExternalId.of("A", "B"));
   
    LocalDate tradeDate = _now.toLocalDate();
    OffsetTime tradeTime = _now.toOffsetTime().minusSeconds(500);
   
    ManageableTrade tradeA = new ManageableTrade(BigDecimal.TEN, ExternalId.of("A", "B"), tradeDate, tradeTime, ExternalId.of("CPS", "CPV"));
    tradeA.addAttribute("key11", "Value11");
    tradeA.addAttribute("key12", "Value12");
    pos1.addTrade(tradeA);
   
    ManageableTrade tradeB = new ManageableTrade(BigDecimal.TEN, ExternalId.of("C", "D"), tradeDate, tradeTime, ExternalId.of("CPS2", "CPV2"));
    tradeB.addAttribute("key21", "Value21");
    tradeB.addAttribute("key22", "Value22");
    pos1.addTrade(tradeB);
   
    PositionDocument doc = new PositionDocument(pos1);
    PositionDocument version1 = _posMaster.add(doc);
    assertNotNull(version1.getUniqueId());
    assertNotNull(tradeA.getUniqueId());
    assertNotNull(tradeB.getUniqueId());
    assertEquals(version1.getPosition(), _posMaster.get(pos1.getUniqueId()).getPosition());
   
    ManageablePosition pos2 = new ManageablePosition(BigDecimal.TEN, ExternalId.of("A", "B"));
    pos2.setUniqueId(version1.getUniqueId());
    ManageableTrade tradeC = new ManageableTrade(BigDecimal.TEN, ExternalId.of("A", "B"), tradeDate, tradeTime, ExternalId.of("CPS", "CPV"));
    tradeC.addAttribute("A", "B");
    tradeC.addAttribute("C", "D");
    tradeC.addAttribute("E", "F");
    pos2.addTrade(tradeC);
   
    PositionDocument version2 = _posMaster.update(new PositionDocument(pos2));   
    assertNotNull(version2);
    assertFalse(version1.getUniqueId().equals(version2.getUniqueId()));
    assertNotNull(tradeC.getUniqueId());
    assertEquals(version2.getPosition(), _posMaster.get(version2.getUniqueId()).getPosition());
   
    //reload version1
    version1 = _posMaster.get(version1.getUniqueId());
   
View Full Code Here

    pos1.addAttribute("A12", "V12");

    LocalDate tradeDate = _now.toLocalDate();
    OffsetTime tradeTime = _now.toOffsetTime().minusSeconds(500);

    ManageableTrade tradeA = new ManageableTrade(BigDecimal.TEN, ExternalId.of("A", "B"), tradeDate, tradeTime, ExternalId.of("CPS", "CPV"));
    tradeA.addAttribute("key11", "Value11");
    tradeA.addAttribute("key12", "Value12");
    pos1.addTrade(tradeA);

    ManageableTrade tradeB = new ManageableTrade(BigDecimal.TEN, ExternalId.of("C", "D"), tradeDate, tradeTime, ExternalId.of("CPS2", "CPV2"));
    tradeB.addAttribute("key21", "Value21");
    tradeB.addAttribute("key22", "Value22");
    pos1.addTrade(tradeB);

    PositionDocument doc = new PositionDocument(pos1);
    PositionDocument version1 = _posMaster.add(doc);
    assertNotNull(version1.getUniqueId());
    assertNotNull(tradeA.getUniqueId());
    assertNotNull(tradeB.getUniqueId());
    assertEquals(version1.getPosition(), _posMaster.get(pos1.getUniqueId()).getPosition());

    ManageablePosition pos2 = new ManageablePosition(BigDecimal.TEN, ExternalId.of("A", "B"));
    pos2.setUniqueId(version1.getUniqueId());
    pos1.addAttribute("A11", "V21");
    pos1.addAttribute("A12", "V22");
    ManageableTrade tradeC = new ManageableTrade(BigDecimal.TEN, ExternalId.of("A", "B"), tradeDate, tradeTime, ExternalId.of("CPS", "CPV"));
    tradeC.addAttribute("A", "B");
    tradeC.addAttribute("C", "D");
    tradeC.addAttribute("E", "F");
    pos2.addTrade(tradeC);

    PositionDocument version2 = _posMaster.update(new PositionDocument(pos2));
    assertNotNull(version2);
    assertFalse(version1.getUniqueId().equals(version2.getUniqueId()));
    assertNotNull(tradeC.getUniqueId());
    assertEquals(version2.getPosition(), _posMaster.get(version2.getUniqueId()).getPosition());

    //reload version1
    version1 = _posMaster.get(version1.getUniqueId());
View Full Code Here

  public String getTradeJSON(@PathParam("tradeId") String tradeIdStr) {
    UniqueId tradeId = UniqueId.parse(tradeIdStr);
    if (!tradeId.isLatest()) {
      throw new IllegalArgumentException("The blotter can only be used to update the latest version of a trade");
    }
    ManageableTrade trade = _positionMaster.getTrade(tradeId);
    ManageableSecurityLink securityLink = trade.getSecurityLink();
    return buildTradeJSON(trade, securityLink);
  }
View Full Code Here

  @DELETE
  @Produces(MediaType.APPLICATION_JSON)
  @Path("trades/{tradeId}")
  public Response deleteTrade(@PathParam("tradeId") String tradeIdStr) {
    UniqueId tradeId = UniqueId.parse(tradeIdStr);
    ManageableTrade trade = _positionMaster.getTrade(tradeId);
    PositionDocument positionDoc = _positionMaster.get(trade.getParentPositionId());
    positionDoc.getPosition().removeTrade(trade);
    _positionMaster.update(positionDoc);
    return Response.ok().build();
  }
View Full Code Here

    if (!positionId.isLatest()) {
      throw new IllegalArgumentException("The blotter can only be used to update the latest version of a trade");
    }
    ManageablePosition position = _positionMaster.get(positionId).getPosition();
    ManageableSecurityLink securityLink = position.getSecurityLink();
    ManageableTrade trade = new ManageableTrade();
    trade.setSecurityLink(securityLink);
    if (position.getTrades().size() == 0) {
      trade.setTradeDate(LocalDate.now());
      trade.setCounterpartyExternalId(ExternalId.of(AbstractTradeBuilder.CPTY_SCHEME, AbstractTradeBuilder.DEFAULT_COUNTERPARTY));
      trade.setQuantity(position.getQuantity());
    }
    return buildTradeJSON(trade, securityLink);
  }
View Full Code Here

TOP

Related Classes of com.opengamma.master.position.ManageableTrade$Meta

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.