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; }
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()); } }
/** * 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 submitOrder (double neededKWh, Timeslot timeslot) { double neededMWh = neededKWh / 1000.0; if (Math.abs(neededMWh) < competition.getMinimumOrderQuantity()) { // don't bother return; } Double limitPrice; MarketPosition posn = face.findMarketPositionByTimeslot(timeslot.getSerialNumber()); if (posn != null) neededMWh -= posn.getOverallBalance(); log.debug("needed mWh=" + neededMWh); if (Math.abs(neededMWh) < minMWh) { log.info("no power required in timeslot " + timeslot.getSerialNumber()); return; } else { limitPrice = computeLimitPrice(timeslot, neededMWh); } log.info("new order for " + neededMWh + " at " + limitPrice + " in timeslot " + timeslot.getSerialNumber()); Order result = new Order(face, timeslot.getSerialNumber(), neededMWh, limitPrice); lastOrder.put(timeslot, result); brokerProxyService.routeMessage(result); }
if (skip-- > 0 && (posn == null || posn.getOverallBalance() == 0.0)) continue; if (posn != null) { availableCapacity += posn.getOverallBalance();
/** * Generates Orders in the market to sell remaining available capacity. */ public void generateOrders (Instant now, List<Timeslot> openSlots) { log.info("Generate orders for " + getUsername()); double[] tempCorrections = computeWeatherCorrections(); int i = 0; for (Timeslot slot: openSlots) { int index = slot.getSerialNumber(); MarketPosition posn = findMarketPositionByTimeslot(index); double start = 0.0; double demand = computeScaledValue(index, tempCorrections[i++]); if (posn != null) { // posn.overallBalance is negative if we have sold power in this slot start = posn.getOverallBalance(); } double needed = demand - start; Order offer = new Order(this, index, needed, null); log.info(getUsername() + " orders " + needed + " ts " + index); brokerProxyService.routeMessage(offer); } }
if (posn != null) { start = -posn.getOverallBalance();