package quantisan.qte_lmax;

import com.lmax.api.FixedPointNumber;
import com.lmax.api.TimeInForce;
import com.lmax.api.order.AmendStopsRequest;
import com.lmax.api.order.MarketOrderSpecification;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class OrderTest {
    @Ignore @Test
    public void testToMarketOrder() throws Exception {
        long instrument = 4001;
        String orderId = "my order 1";
        FixedPointNumber quantity = FixedPointNumber.valueOf("1.0");
        FixedPointNumber stopLossOffset = FixedPointNumber.valueOf("10.0");
        MarketOrderSpecification mos = new MarketOrderSpecification(instrument, orderId, quantity, TimeInForce.IMMEDIATE_OR_CANCEL,stopLossOffset, null);
        // {:instrument "EURUSD", :order-id "my_order_1", :quantity "0.1", :stop-loss-offset "10", :order-type :market}
//        assertEquals(mos.toString(),
//                Order.toMarketOrder("{:instrument \"EURUSD\", :order-id \"my_order_1\", :quantity 1, :stop-loss-offset 10}").toString());
    }

    @Ignore @Test
    public void testToAmendStopOrder() throws Exception {
        long instrument = 4001;
        String orderId = "my order 1";
        FixedPointNumber stopLossOffset = FixedPointNumber.valueOf(10);
        AmendStopsRequest request = new AmendStopsRequest(instrument, orderId, orderId, stopLossOffset, null);
//        assertEquals(request,  // BUG equals useless and no toString
//                Order.toAmendStopOrder("{:order-type :amend-stop, :instrument \"EURUSD\", :order-id \"my order 1\", :stop-loss-offset 10}"));
    }

    @Ignore @Test
    public void testParseOrderType() throws Exception {
        assertEquals(Order.OrderType.MARKET, Order.parseOrderType("{:order-type :market}"));
        assertEquals(Order.OrderType.AMEND_STOP, Order.parseOrderType("{:order-type :amend-stop}"));
        assertEquals(Order.OrderType.UNKNOWN, Order.parseOrderType("{}"));
    }
}
package quantisan.qte_lmax;

import com.lmax.api.FixedPointNumber;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class OrderTest {
    @Test
    public void testMarketOrderConstructor() throws Exception {
        String message = "{:instrument \"EURUSD\", :order-id \"my_order_1\", :quantity \"0.1\", :stop-loss-offset \"10\", :order-type :market}";
        Order order = new Order(null, message);
        assertEquals(4001, order.getInstrumentId());
        assertEquals("my_order_1", order.getOrderId());
        assertEquals("0.1", order.getQuantity().toString());
        assertEquals("10", order.getStopLossOffset().toString());
    }

    @Test
    public void testAmendOrderConstructor() throws Exception {
        String message = "{:instrument \"EURUSD\", :order-id \"my_order_1\", :stop-loss-offset \"20\", :order-type :amend-stop}";
        Order order = new Order(null, message);
        assertEquals(4001, order.getInstrumentId());
        assertEquals("my_order_1", order.getOrderId());
        assertEquals(FixedPointNumber.ZERO, order.getQuantity());
        assertEquals("20", order.getStopLossOffset().toString());
    }

    @Test
    public void testParseOrderType() throws Exception {
        assertEquals(Order.OrderType.MARKET, Order.parseOrderType("{:order-type :market}"));
        assertEquals(Order.OrderType.AMEND_STOP, Order.parseOrderType("{:order-type :amend-stop}"));
        assertEquals(Order.OrderType.UNKNOWN, Order.parseOrderType("{}"));
    }
}
update order test check constructor and order types