/** * Method deleteRow. * * @param selectedRow int */ public void deleteRow(int selectedRow) { Integer orderKey = ((Quantity) this.getValueAt(selectedRow, 1)).getIntegerValue(); for (final TradeOrder tradeOrder : getData().getTradeOrders()) { if (CoreUtils.nullSafeComparator(tradeOrder.getOrderKey(), orderKey) == 0) { getData().getTradeOrders().remove(tradeOrder); final Vector<Object> currRow = rows.get(selectedRow); rows.remove(currRow); this.fireTableRowsDeleted(selectedRow, selectedRow); break; } } }
/** * Method getNewRow. * * @param newRow Vector<Object> * @param element TradeOrder */ public void getNewRow(Vector<Object> newRow, TradeOrder element) { newRow.addElement(element.getTradestrategy().getContract().getSymbol()); newRow.addElement(new Quantity(element.getOrderKey())); if (null == element.getAction()) { newRow.addElement(new Action()); } else { newRow.addElement(Action.newInstance(element.getAction())); } if (null == element.getOrderType()) { newRow.addElement(new OrderType()); } else { newRow.addElement(OrderType.newInstance(element.getOrderType())); } newRow.addElement(new Quantity(element.getQuantity())); newRow.addElement(new Money(element.getLimitPrice())); newRow.addElement(new Money(element.getAuxPrice())); newRow.addElement(YesNo.newInstance(element.getTransmit())); if (null == element.getStatus()) { newRow.addElement(new OrderStatus()); } else { newRow.addElement(OrderStatus.newInstance(element.getStatus())); } if (null == element.getOcaGroupName()) { newRow.addElement(""); } else { newRow.addElement(element.getOcaGroupName()); } if (null == element.getAverageFilledPrice()) { newRow.addElement(new Decimal(3)); } else { newRow.addElement(new Decimal(element.getAverageFilledPrice(), 3)); } if (null == element.getFilledDate()) { newRow.addElement(new Date()); } else { newRow.addElement(new Date(element.getFilledDate())); } newRow.addElement(new Quantity(element.getFilledQuantity())); newRow.addElement(new Money(element.getStopPrice())); TradeOrder tradeOrder = new TradeOrder(); tradeOrder.setIdTradeOrder(1); if (null == element.getFAProfile()) { newRow.addElement(tradeOrder); } else { tradeOrder.setFAProfile(element.getFAProfile()); tradeOrder.setFAGroup(element.getFAGroup()); tradeOrder.setFAMethod(element.getFAMethod()); tradeOrder.setFAPercent(element.getFAPercent()); newRow.addElement(tradeOrder); } }
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 populateDAO. * * @param value Object * @param row int * @param column int */ public void populateDAO(Object value, int row, int column) { TradeOrder element = null; int i = 0; for (final TradeOrder tradeOrder : getData().getTradeOrders()) { if (i == row) { element = tradeOrder; break; } i++; } switch (column) { case 0: { element.getTradestrategy().getContract().setSymbol((String) value); break; } case 1: { element.setOrderKey(((Quantity) value).getIntegerValue()); break; } case 2: { element.setAction(((Action) value).getCode()); break; } case 3: { element.setOrderType(((OrderType) value).getCode()); break; } case 4: { element.setQuantity(((Quantity) value).getIntegerValue()); break; } case 5: { element.setLimitPrice(((Money) value).getBigDecimalValue()); break; } case 6: { element.setAuxPrice(((Money) value).getBigDecimalValue()); break; } case 7: { element.setTransmit(new Boolean(((YesNo) value).getCode())); break; } case 8: { element.setStatus(((OrderStatus) value).getCode()); break; } case 9: { element.setOcaGroupName((String) value); break; } case 10: { element.setAverageFilledPrice(((Decimal) value).getBigDecimalValue()); break; } case 11: { element.setFilledDate(((Date) value).getDate()); break; } case 12: { element.setFilledQuantity(((Quantity) value).getIntegerValue()); break; } case 13: { element.setStopPrice(((Money) value).getBigDecimalValue()); break; } case 14: { if (value instanceof TradeOrder) { element.setFAProfile(((TradeOrder) value).getFAProfile()); element.setFAGroup(((TradeOrder) value).getFAGroup()); element.setFAMethod(((TradeOrder) value).getFAMethod()); element.setFAPercent(((TradeOrder) value).getFAPercent()); } else { element.setFAProfile(null); element.setFAGroup(null); element.setFAMethod(null); element.setFAPercent(null); } break; } default: { } } }