Package com.opengamma.master.position

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


   *
   * @param position  the position to add, not null
   * @return the added document, not null
   */
  protected PositionDocument addPosition(final ManageablePosition position) {
    return getToolContext().getPositionMaster().add(new PositionDocument(position));
  }
View Full Code Here


    trade2.setPremiumCurrency(Currency.GBP);
    trade2.setPremiumDate(tradeDate.plusDays(10));
    trade2.setPremiumTime(tradeTime.plusHours(1));
    position.getTrades().add(trade2);

    final PositionDocument doc = new PositionDocument();
    doc.setPosition(position);
    _posMaster.add(doc);
    assertNotNull(trade1.getUniqueId());
    assertNotNull(trade2.getUniqueId());

    assertEquals(trade1, _posMaster.getTrade(trade1.getUniqueId()));
    assertEquals(trade2, _posMaster.getTrade(trade2.getUniqueId()));

    final PositionDocument storedDoc = _posMaster.get(position.getUniqueId());
    assertNotNull(storedDoc);
    assertNotNull(storedDoc.getPosition());
    assertNotNull(storedDoc.getPosition().getTrades());
    assertEquals(2, storedDoc.getPosition().getTrades().size());
    assertTrue(storedDoc.getPosition().getTrades().contains(trade1));
    assertTrue(storedDoc.getPosition().getTrades().contains(trade2));
  }
View Full Code Here

    final ManageableTrade trade2 = new ManageableTrade(BigDecimal.TEN, ExternalId.of("C", "D"), tradeDate, tradeTime, ExternalId.of("CPS2", "CPV2"));
    trade2.addAttribute("key21", "Value21");
    trade2.addAttribute("key22", "Value22");
    position.getTrades().add(trade2);

    final PositionDocument doc = new PositionDocument();
    doc.setPosition(position);
    _posMaster.add(doc);
    assertNotNull(trade1.getUniqueId());
    assertNotNull(trade2.getUniqueId());

    assertEquals(trade1, _posMaster.getTrade(trade1.getUniqueId()));
    assertEquals(trade2, _posMaster.getTrade(trade2.getUniqueId()));

    final PositionDocument storedDoc = _posMaster.get(position.getUniqueId());
    assertNotNull(storedDoc);
    assertNotNull(storedDoc.getPosition());
    assertNotNull(storedDoc.getPosition().getTrades());
    assertEquals(2, storedDoc.getPosition().getTrades().size());
    assertTrue(storedDoc.getPosition().getTrades().contains(trade1));
    assertTrue(storedDoc.getPosition().getTrades().contains(trade2));
  }
View Full Code Here

    String positionId = matcher.group(2);
    assertTradeWithAttributes(UniqueId.parse(positionId));
  }

  private void assertTradeWithAttributes(UniqueId positionId) {
    PositionDocument positionDocument = _positionMaster.get(positionId);
    ManageableTrade trade = assertTrade(positionDocument);
    Map<String, String> attributes = trade.getAttributes();
    assertNotNull(attributes);
    assertEquals(4, attributes.size());
    assertDealAttributes(attributes);
View Full Code Here

    String positionId = matcher.group(2);
    assertTradeWithEmptyDealAttributes(UniqueId.parse(positionId));
  }
 
  private void assertTradeWithEmptyDealAttributes(UniqueId positionId) {
    PositionDocument positionDocument = _positionMaster.get(positionId);
    ManageableTrade trade = assertTrade(positionDocument);
    Map<String, String> attributes = trade.getAttributes();
    assertNotNull(attributes);
    assertEquals(2, attributes.size());
    assertUserAttributes(attributes);
View Full Code Here

    String positionId = matcher.group(2);
    assertTradeWithEmptyUserAttributes(UniqueId.parse(positionId));
  }
 
  private void assertTradeWithEmptyUserAttributes(UniqueId positionId) {
    PositionDocument positionDocument = _positionMaster.get(positionId);
    ManageableTrade trade = assertTrade(positionDocument);
    Map<String, String> attributes = trade.getAttributes();
    assertNotNull(attributes);
    assertEquals(2, attributes.size());
    assertDealAttributes(attributes);
View Full Code Here

  public void test_removePosition_removed() {
    Instant now = Instant.now(_posMaster.getClock());
   
    UniqueId uniqueId = UniqueId.of("DbPos", "122", "0");
    _posMaster.remove(uniqueId);
    PositionDocument test = _posMaster.get(uniqueId);
   
    assertEquals(uniqueId, test.getUniqueId());
    assertEquals(_version1Instant, test.getVersionFromInstant());
    assertEquals(now, test.getVersionToInstant());
    assertEquals(_version1Instant, test.getCorrectionFromInstant());
    assertEquals(null, test.getCorrectionToInstant());
    ManageablePosition position = test.getPosition();
    assertNotNull(position);
    assertEquals(uniqueId, position.getUniqueId());
    assertEquals(BigDecimal.valueOf(122.987), position.getQuantity());
    ExternalIdBundle secKey = position.getSecurityLink().getExternalId();
    assertEquals(1, secKey.size());
View Full Code Here

 
  private ManageablePortfolioNode createNode(final String nodeName, final Collection<? extends ManageableSecurity> securities) {
    final ManageablePortfolioNode node = new ManageablePortfolioNode(nodeName);
    for (ManageableSecurity security : securities) {
      final ManageablePosition position = createPosition(security);
      node.addPosition(_positions.add(new PositionDocument(position)).getObjectId());
    }
    return node;
  }
View Full Code Here

        existingPosition.addTrade(trade);
      }

      if (!_multithread) {
        // Save the updated existing position to the position master
        PositionDocument addedDoc = _positionMaster.update(new PositionDocument(existingPosition));
        s_logger.debug("Updated position {}, delta position {}", addedDoc.getPosition(), position);

        // update position map (huh?)
        _securityIdToPosition.put(writtenSecurities.get(0).getUniqueId().getObjectId(), addedDoc.getPosition());

        // Return the updated position
        return new ObjectsPair<>(addedDoc.getPosition(),
            securities);
      } else {
        // update position map
        _securityIdToPosition.put(writtenSecurities.get(0).getUniqueId().getObjectId(), existingPosition);

         // Return the updated position
        return new ObjectsPair<>(existingPosition, securities);
      }
    }
    // Attempt to reuse an existing position from the previous version of the portfolio, and return if an exact match is found
    if (!(_originalNode == null) && !_originalNode.getPositionIds().isEmpty()) {
      ManageablePosition existingPosition = matchExistingPosition(position, writtenSecurities);
      if (existingPosition != null) {
        return new ObjectsPair<>(existingPosition,
            writtenSecurities.toArray(new ManageableSecurity[writtenSecurities.size()]));
      }
    }

    // If security has no ExternalId, link position to security ObjectId now
    if (position.getSecurityLink().getExternalId().isEmpty() && position.getSecurityLink().getObjectId() == null) {
      position.setSecurityLink(ManageableSecurityLink.of(writtenSecurities.get(0)));
    }
    // also check trades within position for a valid securityLink
    for (ManageableTrade trade : position.getTrades()) {
      if (trade.getSecurityLink().getExternalId().isEmpty() && trade.getSecurityLink().getObjectId() == null) {
        trade.setSecurityLink(ManageableSecurityLink.of(writtenSecurities.get(0))); // or reuse link from position?
      }
    }

    // No existing position could be reused/updated: just Add the new position to the position master as a new document
    // (can't launch a thread since we need the position id immediately, to be stored with the pos document in the map)
    PositionDocument addedDoc;
    try {
      addedDoc = _positionMaster.add(new PositionDocument(position));
      s_logger.debug("Added position {}", position);
    } catch (Exception e) {
      s_logger.error("Unable to add position " + position.getUniqueId() + ": " + e.getMessage());
      return null;
    }
    // Add the new position to the portfolio
    _currentNode.addPosition(addedDoc.getUniqueId());

    // Update position map
    _securityIdToPosition.put(writtenSecurities.get(0).getUniqueId().getObjectId(), addedDoc.getPosition());

    // Return the new position
    return new ObjectsPair<>(addedDoc.getPosition(),
        writtenSecurities.toArray(new ManageableSecurity[writtenSecurities.size()]));
  }
View Full Code Here

          tasks.add(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
              try {
                // Update the position in the position master
                PositionDocument addedDoc = _positionMaster.update(new PositionDocument(position));
                s_logger.debug("Updated position {}", position);
                 // Add the new position to the portfolio node
                _currentNode.addPosition(addedDoc.getUniqueId());
              } catch (Exception e) {
                s_logger.error("Unable to update position " + position.getUniqueId() + ": " + e.getMessage());
              }
              return 0;
            }
View Full Code Here

TOP

Related Classes of com.opengamma.master.position.PositionDocument$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.