Portfolio portfolio = new SimplePortfolioFactory().createPortfolio(new BigDecimal("10000"));
BigDecimal commission = new BigDecimal("10.00");
Integer systemId = simulationAdapter.createSystem("first system",password,portfolio,commission);
simulationAdapter.subscribe(eMail,systemId,password);
C2ServiceFactory factory = new C2ServiceFactory(simulationAdapter);
C2EntryService sentryService = factory.signalEntryService(password, systemId, eMail);
assertEquals(0, portfolio.position("msft").quantity().intValue());
Signal msft = sentryService.stockSignal(ActionForStock.BuyToOpen)
.quantity(10).symbol("msft")
.stopLoss(base, stopSize)
.duration(Duration.GoodTilCancel);
if (isLimit) {
msft = msft.limitOrder(triggerPrice);
} else {
msft = msft.stopOrder(triggerPrice);
}
Response openResponse = msft.send();
Integer signalId = openResponse.getInteger(C2Element.ElementSignalId);
assertEquals(0,signalId.intValue());
simulationAdapter.tick(dataProvider,sentryService);
HashSet<Integer> pending = sentryService.sendAllSignalsRequest()
.collectIntegers(new HashSet<Integer>(),
C2Element.ElementSignalId);
assertEquals(expectedPendingCount, pending.size());
Integer id = pending.iterator().next();
BigDecimal stop = sentryService.sendSignalStatusRequest(id,true).getBigDecimal(C2Element.ElementStop);
assertEquals(expectedStop,stop);
}