Package org.archfirst.bfcommon.jsontrading

Examples of org.archfirst.bfcommon.jsontrading.Order


        // Create 2011-01-01T09:00:00.000-04:00
        DateTime orderDate = new DateTime(
                2011, 1, 1, 9, 0, 0, 0, DateTimeZone.forOffsetHours(-4));
       
        // Create a JsonMessage with NewOrderSingle
        Order order = new Order(
                fmt.print(orderDate),
                "JVEE-1",
                OrderSide.Buy,
                "AAPL",
                100,
                OrderType.Limit,
                new Money("100.00", "USD"),
                OrderTerm.GoodForTheDay,
                false,
                OrderStatus.PendingNew);
        NewOrderSingle newOrderSingle = new NewOrderSingle(order);

        // Write out the JsonMessage as a string
        String jsonMessageString = JsonMessageMapper.toFormattedString(newOrderSingle);
       
        // Read the JsonMessage back
        JsonMessage jsonMessageRead = JsonMessageMapper.fromString(jsonMessageString);
       
        // Make sure that the message type has been retrieved properly
        Assert.assertTrue(
                jsonMessageRead.getClass().equals(NewOrderSingle.class));
       
        // Make sure that the order has been retrieved properly
        Order orderRead =
            ((NewOrderSingle)jsonMessageRead).getOrder();

        // Can't compare the two DateTime objects with equals
        // because deserialization loses the time zone
        Assert.assertTrue(
                (fmt.parseDateTime(orderRead.getCreationTime()))
                .isEqual(orderDate));
       
        Assert.assertEquals(orderRead.getClientOrderId(), order.getClientOrderId());
        Assert.assertEquals(orderRead.getSide(), order.getSide());
        Assert.assertEquals(orderRead.getSymbol(), order.getSymbol());
        Assert.assertEquals(orderRead.getQuantity(), order.getQuantity());
        Assert.assertEquals(orderRead.getType(), order.getType());

        // Can't compare the two BigDecimal objects with equals
        // because precision may be different (e.g. 100.0 and 100.00)
        Assert.assertEquals(orderRead.getLimitPrice().getAmount().compareTo(order.getLimitPrice().getAmount()), 0);

        Assert.assertEquals(orderRead.getLimitPrice().getCurrency(), order.getLimitPrice().getCurrency());
        Assert.assertEquals(orderRead.getTerm(), order.getTerm());
        Assert.assertEquals(orderRead.isAllOrNone(), order.isAllOrNone());
        Assert.assertEquals(orderRead.getStatus(), order.getStatus());
    }
View Full Code Here

TOP

Related Classes of org.archfirst.bfcommon.jsontrading.Order

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.