Examples of MarketPrice


Examples of org.archfirst.bfexch.domain.marketdata.MarketPrice

        this.performMatching(order.getSymbol());
    }
   
    private void performMatching(String symbol) {
        logger.debug("Pricing engine triggered for symbol {}", symbol);
        MarketPrice marketPrice =
            marketDataRepository.findMarketPrice(symbol);
        Money preMatchingPrice = marketPrice.getPrice();
        OrderBook orderBook = getOrderBook(symbol);

        // Iterate through buy orders
        for (Order buyOrder : orderBook.getBuyStack()) {
            logger.debug("Trying to match buy order:\n{}", buyOrder);
            MatchResult matchResult =
                new MatchResult(false, NoMatchReason.priceMismatch);
           
            // Iterate through sell orders to match the current buy order
            for (Order sellOrder : orderBook.getSellStack()) {

                // Skip sell order if it has been filled in a previous iteration
                if (!sellOrder.isActive()) {
                    continue;
                }

                matchResult = matchOrder(buyOrder, sellOrder, marketPrice);

                // Analyze match result and break out of inner loop if appropriate
                if (matchResult.isMatch()) {
                    if (buyOrder.getStatus() == OrderStatus.Filled) {
                        logger.debug("Buy order filled, stop matching with sell orders");
                        break;
                    }
                }
                else { // no match
                    if (matchResult.noMatchReason == NoMatchReason.priceMismatch) {
                        logger.debug("Buy order did not match due to price mismatch, stop matching with sell orders");
                        break;
                    }
                }
            }

            // If buy order did not match due to price mismatch, then break.
            // (No other buy orders will match.)
            if (matchResult.isMatch()==false &&
                matchResult.getNoMatchReason()==NoMatchReason.priceMismatch) {
                logger.debug("Buy order did not match due to price mismatch, stop matching other buy orders");
                break;
            }
        }
       
        // If market price has changed are a result of this run, publish the new price
        if (!marketPrice.getPrice().eq(preMatchingPrice)) {
            marketDataEventPublisher.publish(new MarketPriceChanged(marketPrice));
        }
    }
View Full Code Here

Examples of org.archfirst.bfexch.domain.marketdata.MarketPrice

        }
        return numberOfFills;
    }
   
    public BigDecimal getMarketPrice(String symbol) {
        MarketPrice marketPrice = marketDataService.getMarketPrice(symbol);
        return marketPrice.getPrice().getAmount();
    }
View Full Code Here

Examples of org.archfirst.bfexch.domain.marketdata.MarketPrice

    @Resource(mappedName="jms/ExchangeMarketPriceTopic")
    private Destination destination;

    public void onMarketPriceChanged(@Observes MarketPriceChanged event) {

        MarketPrice marketPrice = event.getMarketPrice();
        logger.debug("Publishing market price:\n{}", marketPrice);

        Connection connection = null;
        try {
            connection = connectionFactory.createConnection();
            Session session = connection.createSession(
                    false, Session.AUTO_ACKNOWLEDGE);
            MessageProducer producer = session.createProducer(destination);
            producer.send(session.createTextMessage(marketPrice.toProperties()));
        }
        catch (JMSException e) {
            throw new RuntimeException("Failed to publish market price", e);
        }
        finally {
View Full Code Here

Examples of org.archfirst.bfoms.domain.marketdata.MarketPrice

    public void onMessage(Message message) {

        if (message instanceof TextMessage) {
            try {
                String messageText = ((TextMessage)message).getText();
                MarketPrice marketPrice = toMarketPrice(messageText);
                logger.debug("Received market price:\n{}", marketPrice);
                marketDataService.updateMarketPrice(marketPrice);
            }
            catch (JMSException e) {
                throw new RuntimeException(e);
View Full Code Here

Examples of org.archfirst.bfoms.domain.marketdata.MarketPrice

        BigDecimal price = new BigDecimal(
                properties.getProperty("price"));
        Currency currency = Currency.getInstance(
                properties.getProperty("currency"));

        return new MarketPrice(
                symbol, new Money(price, currency), effective);
    }
View Full Code Here

Examples of org.archfirst.bfoms.domain.marketdata.MarketPrice

   
    private List<MarketPrice> marketPrices =
        new ArrayList<MarketPrice>();

    public void addMarketPrice(String symbol, Money price) {
        marketPrices.add(new MarketPrice(symbol, price, new DateTime()));
    }
View Full Code Here

Examples of org.archfirst.bfoms.domain.marketdata.MarketPrice

                USERNAME1, symbol, new DecimalQuantity(quantity), pricePerShare,
                externalAccount1Id, brokerageAccount1Id);

        // getOrderEstimate() requires a market price to calculate sale amount
        marketDataService.updateMarketPrice(
                new MarketPrice(symbol, pricePerShare, new DateTime()));
    }
View Full Code Here

Examples of org.archfirst.bfoms.domain.marketdata.MarketPrice

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

Examples of org.archfirst.bfoms.domain.marketdata.MarketPrice

   
    public void initOrders(String symbol, int numOrders) {

        // Set a low market price so we have enough funds for buying shares
        marketDataService.updateMarketPrice(
                new MarketPrice(symbol, new Money("1.00"), new DateTime()));

        // Place orders
        for (int orderNumber=0; orderNumber < numOrders; orderNumber++) {
            OrderParams orderParams = new OrderParams(
                    OrderSide.Buy,
View Full Code Here

Examples of org.archfirst.bfoms.domain.marketdata.MarketPrice

    public List<Lot> sell(String symbol, BigDecimal quantity) {
       
        // 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.Sell,
                symbol,
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.