/** * Processes a market transaction by ensuring that the market position * will be sent to the broker. * Actual transaction posting is deferred to delivery time */ public void processTransaction(MarketTransaction tx, ArrayList<Object> messages) { MarketPosition mkt = tx.getBroker().findMarketPositionByTimeslot(tx.getTimeslotIndex()); if (!messages.contains(mkt)) messages.add(mkt); }
private double getRemaining (Broker broker, HashMap<Broker, Double> posns, int ts) { Double result = posns.get(broker); if (null == result) { MarketPosition posn = broker.findMarketPositionByTimeslot(ts); // offset is zero for final ts int offset = ts - timeslotRepo.currentSerialNumber(); double limit = mktPosnLimitFinal; if (enabledTimeslots.size() > 1) { limit -= (offset * (mktPosnLimitFinal - mktPosnLimitInitial) / (enabledTimeslots.size() - 1)); } result = Math.max(0.0, limit - posn.getOverallBalance()); posns.put(broker, result); } return result; }
/** * Gets the net market position for the current timeslot. This only works on * processed transactions, but it can be used before activation in case there * can be no new market transactions for the current timeslot. This is the * normal case. The value will be positive if the broker is importing power * during the current timeslot. */ @Override public synchronized double getCurrentMarketPosition(Broker broker) { Timeslot current = timeslotRepo.currentTimeslot(); log.debug("current timeslot: " + current.getSerialNumber()); MarketPosition position = broker.findMarketPositionByTimeslot(current.getSerialNumber()); if (position == null) { log.debug("null position for ts " + current.getSerialNumber()); return 0.0; } log.info("market position for " + broker.getUsername() + ": " + position.getOverallBalance()); return position.getOverallBalance(); }
private void updateBrokerMarketPosition(MarketTransaction tx) { Broker broker = tx.getBroker(); MarketPosition mkt = broker.findMarketPositionByTimeslot(tx.getTimeslotIndex()); if (mkt == null) { mkt = new MarketPosition(broker, tx.getTimeslot(), tx.getMWh()); log.debug("New MarketPosition(" + broker.getUsername() + ", " + tx.getTimeslot().getSerialNumber() + "): " + mkt.getId()); broker.addMarketPosition(mkt, tx.getTimeslotIndex()); } else { mkt.updateBalance(tx.getMWh()); } }