public void addRow() { final Tradestrategy tradestrategy = getData(); String side = tradestrategy.getSide(); if (null == side) side = Side.BOT; String orderType = OrderType.STPLMT; String action = Action.BUY; if (Side.SLD.equals(side)) { action = Action.SELL; } double risk = tradestrategy.getRiskAmount().doubleValue(); double stop = 1.0d; Money price = new Money( tradestrategy.getStrategyData().getBaseCandleSeries().getContract().getLastPrice()); final Entrylimit entrylimit = DAOEntryLimit.newInstance().getValue(price); Money limitPrice = Action.BUY.equals(action) ? price.add(new Money(entrylimit.getLimitAmount().doubleValue())) : price.subtract(new Money(entrylimit.getLimitAmount().doubleValue())); int quantity = (int) ((int) risk / stop); if (tradestrategy.isThereOpenTradePosition()) { for (TradeOrder item : tradestrategy.getTradeOrders()) { if (item.hasTradePosition()) { TradePosition position = item.getTradePosition(); if (position.isOpen()) { quantity = Math.abs(position.getOpenQuantity()); side = position.getSide(); action = Action.BUY; if (Side.BOT.equals(side)) { action = Action.SELL; } orderType = OrderType.LMT; limitPrice = price; } } } } final TradeOrder tradeOrder = new TradeOrder( tradestrategy, action, orderType, quantity, price.getBigDecimalValue(), limitPrice.getBigDecimalValue(), TradingCalendar.getDate()); tradeOrder.setOcaGroupName(""); tradeOrder.setTransmit(true); tradeOrder.setStatus(OrderStatus.UNSUBMIT); tradestrategy.addTradeOrder(tradeOrder); final Vector<Object> newRow = new Vector<Object>(); getNewRow(newRow, tradeOrder); rows.add(newRow); // Tell the listeners a new table has arrived. fireTableChanged(new TableModelEvent(this)); }
/** * Method isSide. * * @param side String * @return boolean */ public boolean isSide(String side) { if (Side.BOT.equals(side)) return getSide(); return (getSide() ? false : true); }