TradeSignalBuilder { public SubmitSignalRequest buildSignalRequest( String systemId, TradeOrder order ) { Ticker ticker = order.getTicker(); String symbol; if( ticker instanceof FuturesTicker ) { symbol = C2Util.getFuturesSymbol((FuturesTicker)ticker); } else { symbol = ticker.getSymbol(); } SignalInfo signalInfo = new SignalInfo(); signalInfo.setTicker(symbol); signalInfo.setAction(C2Util.getTradeAction(order)); signalInfo.setIsMarketOrder( (order.getType() == TradeOrder.Type.MARKET || order.getType() == TradeOrder.Type.MARKET_ON_OPEN )); signalInfo.setSymbolType(C2Util.getSymbolType(order)); signalInfo.setOrderType(C2Util.getOrderType(order)); signalInfo.setQuantity(order.getSize()); signalInfo.setDuration( getDuration(order.getDuration() )); if( order.getGoodAfterTime() != null ) { signalInfo.setParkUntil(C2Util.getTime(order.getGoodAfterTime())); } if( order.getType() == TradeOrder.Type.STOP ) { signalInfo.setStopPrice(order.getStopPrice()); } else if( order.getType() == TradeOrder.Type.LIMIT ) { signalInfo.setLimitPrice(order.getLimitPrice() ); } SubmitSignalRequest request = new SubmitSignalRequest(systemId, signalInfo); return request; }  SubmitSignalRequest buildSignalRequest( String systemId, TradeOrder order );  }
@Test public void testBuildSignalRequest() { String systemId = "123"; StockTicker ticker = new StockTicker("QQQ"); TradeOrder order = new TradeOrder("", ticker, 100, TradeDirection.BUY); order.setDuration(TradeOrder.Duration.GOOD_UNTIL_CANCELED); SignalInfo expectedSignalInfo = new SignalInfo(); SubmitSignalRequest expectedRequest = new SubmitSignalRequest(systemId, expectedSignalInfo); expectedSignalInfo.setTicker("QQQ"); expectedSignalInfo.setAction(SignalInfo.Action.BTO); expectedSignalInfo.setIsMarketOrder(true); expectedSignalInfo.setSymbolType(SignalInfo.SymbolType.stock); expectedSignalInfo.setOrderType(SignalInfo.OrderType.MARKET); expectedSignalInfo.setQuantity(100); expectedSignalInfo.setDuration(SignalInfo.Duration.GTC); SubmitSignalRequest submitSignalRequest = testBuilder.buildSignalRequest(systemId, order); assertEquals( expectedSignalInfo, submitSignalRequest.getSignal() ); assertEquals(expectedRequest,submitSignalRequest ); }
@Test public void testBuildSignalRequest_MarketOnOpen() { String systemId = "123"; StockTicker ticker = new StockTicker("QQQ"); TradeOrder order = new TradeOrder("", ticker, 100, TradeDirection.BUY); order.setType(TradeOrder.Type.MARKET_ON_OPEN); order.setDuration(TradeOrder.Duration.GOOD_UNTIL_CANCELED); SignalInfo expectedSignalInfo = new SignalInfo(); SubmitSignalRequest expectedRequest = new SubmitSignalRequest(systemId, expectedSignalInfo); expectedSignalInfo.setTicker("QQQ"); expectedSignalInfo.setAction(SignalInfo.Action.BTO); expectedSignalInfo.setIsMarketOrder(true); expectedSignalInfo.setSymbolType(SignalInfo.SymbolType.stock); expectedSignalInfo.setOrderType(SignalInfo.OrderType.MARKET); expectedSignalInfo.setQuantity(100); expectedSignalInfo.setDuration(SignalInfo.Duration.GTC); SubmitSignalRequest submitSignalRequest = testBuilder.buildSignalRequest(systemId, order); assertEquals( expectedSignalInfo, submitSignalRequest.getSignal() ); assertEquals(expectedRequest,submitSignalRequest ); }
@Test public void testBuildSignalRequest_GoodAfterTime() { String systemId = "123"; StockTicker ticker = new StockTicker("QQQ"); ZonedDateTime zoneTime = ZonedDateTime.of(2018, 4, 11, 6, 30, 0, 0, ZoneId.of("America/Los_Angeles")); TradeOrder order = new TradeOrder("", ticker, 100, TradeDirection.BUY); order.setDuration(TradeOrder.Duration.GOOD_UNTIL_CANCELED); order.setGoodAfterTime(zoneTime); SignalInfo expectedSignalInfo = new SignalInfo(); SubmitSignalRequest expectedRequest = new SubmitSignalRequest(systemId, expectedSignalInfo); expectedSignalInfo.setTicker("QQQ"); expectedSignalInfo.setAction(SignalInfo.Action.BTO); expectedSignalInfo.setIsMarketOrder(true); expectedSignalInfo.setSymbolType(SignalInfo.SymbolType.stock); expectedSignalInfo.setOrderType(SignalInfo.OrderType.MARKET); expectedSignalInfo.setQuantity(100); expectedSignalInfo.setDuration(SignalInfo.Duration.GTC); expectedSignalInfo.setParkUntil("201804110930"); SubmitSignalRequest submitSignalRequest = testBuilder.buildSignalRequest(systemId, order); assertEquals( expectedSignalInfo, submitSignalRequest.getSignal() ); assertEquals(expectedRequest,submitSignalRequest ); }
@Test public void testBuildSignalRequest_Futures() { String systemId = "123"; FuturesTicker ticker = FuturesTicker.getInstance(Commodity.CORN_ECBOT, 6, 2017); TradeOrder order = new TradeOrder("", ticker, 1, TradeDirection.BUY); SignalInfo expectedSignalInfo = new SignalInfo(); SubmitSignalRequest expectedRequest = new SubmitSignalRequest(systemId, expectedSignalInfo); expectedSignalInfo.setTicker("@CM7"); expectedSignalInfo.setAction(SignalInfo.Action.BTO); expectedSignalInfo.setIsMarketOrder(true); expectedSignalInfo.setSymbolType(SignalInfo.SymbolType.future); expectedSignalInfo.setOrderType(SignalInfo.OrderType.MARKET); expectedSignalInfo.setQuantity(1); expectedSignalInfo.setDuration(SignalInfo.Duration.DAY); SubmitSignalRequest submitSignalRequest = testBuilder.buildSignalRequest(systemId, order); assertEquals( expectedSignalInfo, submitSignalRequest.getSignal() ); assertEquals(expectedRequest,submitSignalRequest ); }
@Test public void testBuildSignalRequest_StopOrder() { String systemId = "123"; StockTicker ticker = new StockTicker("QQQ"); TradeOrder order = new TradeOrder("", ticker, 100, TradeDirection.BUY); order.setType(TradeOrder.Type.STOP); order.setDuration(TradeOrder.Duration.GOOD_UNTIL_CANCELED); order.setStopPrice(10.00); SignalInfo expectedSignalInfo = new SignalInfo(); SubmitSignalRequest expectedRequest = new SubmitSignalRequest(systemId, expectedSignalInfo); expectedSignalInfo.setTicker("QQQ"); expectedSignalInfo.setAction(SignalInfo.Action.BTO); expectedSignalInfo.setIsMarketOrder(false); expectedSignalInfo.setSymbolType(SignalInfo.SymbolType.stock); expectedSignalInfo.setOrderType(SignalInfo.OrderType.MARKET); expectedSignalInfo.setQuantity(100); expectedSignalInfo.setDuration(SignalInfo.Duration.GTC); expectedSignalInfo.setOrderType(SignalInfo.OrderType.STOP); expectedSignalInfo.setStopPrice(10.00); SubmitSignalRequest submitSignalRequest = testBuilder.buildSignalRequest(systemId, order); assertEquals( expectedSignalInfo, submitSignalRequest.getSignal() ); assertEquals(expectedRequest, submitSignalRequest); }
@Test public void testBuildSignalRequest_LimitOrder() { String systemId = "123"; StockTicker ticker = new StockTicker("QQQ"); TradeOrder order = new TradeOrder("", ticker, 100, TradeDirection.BUY); order.setType(TradeOrder.Type.LIMIT); order.setDuration(TradeOrder.Duration.GOOD_UNTIL_CANCELED); order.setLimitPrice(10.00); SignalInfo expectedSignalInfo = new SignalInfo(); SubmitSignalRequest expectedRequest = new SubmitSignalRequest(systemId, expectedSignalInfo); expectedSignalInfo.setTicker("QQQ"); expectedSignalInfo.setAction(SignalInfo.Action.BTO); expectedSignalInfo.setIsMarketOrder(false); expectedSignalInfo.setSymbolType(SignalInfo.SymbolType.stock); expectedSignalInfo.setOrderType(SignalInfo.OrderType.MARKET); expectedSignalInfo.setQuantity(100); expectedSignalInfo.setDuration(SignalInfo.Duration.GTC); expectedSignalInfo.setOrderType(SignalInfo.OrderType.LIMIT); expectedSignalInfo.setLimitPrice(10.00); SubmitSignalRequest submitSignalRequest = testBuilder.buildSignalRequest(systemId, order); assertEquals( expectedSignalInfo, submitSignalRequest.getSignal() ); assertEquals(expectedRequest, submitSignalRequest); }