Package org.archfirst.common.money

Examples of org.archfirst.common.money.Money


        this.createBrokerageAccount1();
        this.createExternalAccount1();
       
        // Add cash to brokerage account so we can buy securities
        this.baseAccountService.transferCash(
                USERNAME1, new Money("10000"),
                externalAccount1Id, brokerageAccount1Id);
    }
View Full Code Here


   
    public List<Lot> buy(String symbol, BigDecimal quantity, BigDecimal pricePaidPerShare) {
       
        // Make sure placeOrder() can get a market price for the symbol
        marketDataService.updateMarketPrice(
                new MarketPrice(symbol, new Money("10"), new DateTime()));

        // Place the order
        OrderParams orderParams = new OrderParams(
                OrderSide.Buy,
                symbol,
                quantity,
                OrderType.Market,
                null,
                OrderTerm.GoodTilCanceled,
                false);
        Long orderId = this.brokerageAccountService.placeOrder(
                USERNAME1, brokerageAccount1Id, orderParams);
        Order order = this.brokerageAccountService.findOrder(orderId);
       
        // Acknowledge the order
        ExecutionReport executionReport = ExecutionReport.createNewType(order);
        this.brokerageAccountService.processExecutionReport(executionReport);
       
        // Execute the trade
        executionReport = ExecutionReport.createTradeType(
                order,
                OrderStatus.Filled,
                new DecimalQuantity(quantity),
                new Money(pricePaidPerShare));
        this.brokerageAccountService.processExecutionReport(executionReport);
       
        List<Lot> lots =
            this.brokerageAccountService.findActiveLots(brokerageAccount1Id);
        Collections.sort(lots, new Lot.CreationTimeComparator());
View Full Code Here

        this.createExternalAccount1();
    }
   
    public void transferCash(BigDecimal amount) {
        this.baseAccountService.transferCash(
                USERNAME1, new Money(amount),
                externalAccount1Id, brokerageAccount1Id);
    }
View Full Code Here

    }

    public void transferSecurities(String symbol, BigDecimal quantity, BigDecimal price) {
        this.baseAccountService.transferSecurities(
                USERNAME1, symbol,
                new DecimalQuantity(quantity), new Money(price),
                externalAccount1Id, brokerageAccount1Id);
    }
View Full Code Here

                externalAccount1Id, brokerageAccount1Id);
    }
   
    public void setMarketPrice(String symbol, BigDecimal price) {
        marketDataService.updateMarketPrice(
                new MarketPrice(symbol, new Money(price), new DateTime()));
    }
View Full Code Here

    private static final MarketPrice toDomainMarketPrice(
            org.archfirst.bfoms.interfaceout.exchange.marketdataadapter.client.MarketPrice wsMarketPrice) {

        return new MarketPrice(
                wsMarketPrice.getSymbol(),
                new Money(
                        wsMarketPrice.getPrice().getAmount(),
                        Currency.getInstance(wsMarketPrice.getPrice().getCurrency())),
                new DateTime(wsMarketPrice.getEffective().toGregorianCalendar()));
    }
View Full Code Here

        return new AvgPx(money.getAmount().doubleValue());
    }

    public static Money toDomain(AvgPx avgPx)
            throws FieldNotFound {
        return new Money(new BigDecimal(Double.toString(avgPx.getValue())));
    }
View Full Code Here

        if (quantityLeftToWithdraw.isPlus()) {
            Lot lot = new Lot(
                    new DateTime(),
                    symbol,
                    quantityLeftToWithdraw.negate(),
                    new Money("0.00"));
                brokerageAccountRepository.persistAndFlush(lot);
                this.addLot(lot);
                lot.addAllocation(factory.createAllocation(quantityLeftToWithdraw));
        }
    }
View Full Code Here

            ReferenceDataService referenceDataService,
            MarketDataService marketDataService) {
       
        List<Position> positions =
            this.getPositions(referenceDataService, marketDataService);
        Money marketValue = new Money();
        for (Position position : positions) {
            marketValue = marketValue.plus(position.getMarketValue());
        }
       
        List<BrokerageAccountPermission> permissions =
            brokerageAccountRepository.findPermissionsForAccount(user, this);
       
View Full Code Here

        return amount.lteq(calculateCashAvailable(marketDataService));
    }
   
    public Money calculateCashAvailable(MarketDataService marketDataService) {

        Money cashAvailable = cashPosition;
       
        // Reduce cash available by estimated cost of buy orders
        List<Order> orders = brokerageAccountRepository.findActiveBuyOrders(this);
        for (Order order : orders) {
            OrderEstimate orderEstimate =
                order.calculateOrderEstimate(marketDataService);
            cashAvailable =
                cashAvailable.minus(orderEstimate.getEstimatedValueInclFees());
        }
       
        return cashAvailable;
    }
View Full Code Here

TOP

Related Classes of org.archfirst.common.money.Money

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.