package quantisan.qte_lmax;

import us.bpsm.edn.parser.Parseable;
import us.bpsm.edn.parser.Parser;
import us.bpsm.edn.parser.Parsers;

import java.util.Map;

import static us.bpsm.edn.Keyword.newKeyword;
import static us.bpsm.edn.parser.Parsers.defaultConfiguration;

public class Order {
    private final long instrument;

    public Order(String message) {
        Parseable pbr = Parsers.newParseable(message);
        Parser p = Parsers.newParser(defaultConfiguration());
        Map<?, ?> m = (Map<?, ?>) p.nextValue(pbr);
        instrument = Instrument.toId(m.get(newKeyword("instrument")).toString());

    }

    public void execute() {
    }
}

@@ -33,309 +33,1021 @@
 ort 
-us.bpsm.edn.parser.Parseable;%0Aimport us.bpsm.edn.parser.Parser;%0Aimport us.bpsm.edn.parser.Parsers;%0A%0Aimport java.util.Map;%0A%0Aimport static us.bpsm.edn.Keyword.newKeyword;%0Aimport static us.bpsm.edn.parser.Parsers.defaultConfiguration;%0A%0Apublic class Order %7B%0A    private final long instrument;%0A%0A    public 
+com.lmax.api.FailureResponse;%0Aimport com.lmax.api.FixedPointNumber;%0Aimport com.lmax.api.Session;%0Aimport com.lmax.api.TimeInForce;%0Aimport com.lmax.api.order.MarketOrderSpecification;%0Aimport com.lmax.api.order.OrderCallback;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0Aimport us.bpsm.edn.parser.Parseable;%0Aimport us.bpsm.edn.parser.Parser;%0Aimport us.bpsm.edn.parser.Parsers;%0A%0Aimport java.util.Map;%0A%0Aimport static us.bpsm.edn.Keyword.newKeyword;%0Aimport static us.bpsm.edn.parser.Parsers.defaultConfiguration;%0A%0Apublic class Order %7B%0A    final static Logger logger = LoggerFactory.getLogger(Order.class);%0A%0A    private final Session session;%0A    private final MarketOrderSpecification marketOrderSpecification;%0A%0A    public enum OrderState %7B NONE, FAIL, PENDING %7D;%0A    private OrderState orderState = OrderState.NONE;%0A%0A    /**%0A     * Parse a EDN message to a market order.%0A     *%0A     * @param ednMessage a EDN message%0A     * @return a market order%0A     */%0A    public static MarketOrderSpecification toMarket
 Orde
@@ -1055,17 +1055,20 @@
 (String 
-m
+ednM
 essage) 
@@ -1114,17 +1114,20 @@
 rseable(
-m
+ednM
 essage);
@@ -1249,16 +1249,88 @@
         
+String orderId = m.get(newKeyword(%22order-id%22)).toString();%0A        Long 
 instrume
@@ -1399,43 +1399,1766 @@
 ));%0A
-%0A    %7D%0A%0A    public void execute() %7B
+        FixedPointNumber quantity = FixedPointNumber.valueOf((Long)m.get(newKeyword(%22quantity%22)));%0A%0A        FixedPointNumber stopLossOffset = FixedPointNumber.valueOf((Long)m.get(newKeyword(%22stop-loss-offset%22)));%0A%0A        return new MarketOrderSpecification(instrument, orderId, quantity, TimeInForce.IMMEDIATE_OR_CANCEL,stopLossOffset, null);%0A    %7D%0A%0A    public Order(Session session, String message) %7B%0A        this.session = session;%0A        this.marketOrderSpecification = toMarketOrder(message);%0A    %7D%0A%0A    public void execute() %7B%0A        if (getOrderState() == OrderState.NONE) %7B%0A            session.placeMarketOrder(this.marketOrderSpecification, new OrderCallback()%0A            %7B%0A                public void onSuccess(String placeOrderInstructionId)%0A                %7B%0A                    // note - this will be the same instructionId from above,%0A                    // it confirms this success is related to that specific place order request%0A%0A                    //move from %22new%22 to %22pending%22 to show the order was successfully placed%0A                    logger.info(%22Order sent and pending: %7B%7D%22, placeOrderInstructionId);%0A                    setOrderState(OrderState.PENDING);%0A                %7D%0A%0A                public void onFailure(FailureResponse failureResponse)%0A                %7B%0A                    setOrderState(OrderState.FAIL);%0A                    logger.error(%22Failed to place order: %7B%7D%22, failureResponse);%0A                %7D%0A            %7D);%0A        %7D%0A    %7D%0A%0A    public MarketOrderSpecification getMarketOrderSpecification() %7B%0A        return marketOrderSpecification;%0A    %7D%0A%0A    public OrderState getOrderState() %7B%0A        return orderState;%0A    %7D%0A%0A    public void setOrderState(OrderState orderState) %7B%0A        this.orderState = orderState;
 %0A   

Order class generate market order spec and execute()