/** * Processes deferred market transactions for the current timeslot * by updating the broker's cash position. */ public void handleMarketTransactionsForTimeslot(Timeslot ts) { ArrayList<MarketTransaction> pending = pendingMarketTransactions.get(ts); if (null == pending) return; for (MarketTransaction tx : pending) { Broker broker = tx.getBroker(); updateCash(broker, tx.getPrice() * Math.abs(tx.getMWh())); } }
/** * 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 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()); } }
/** * Receives a new MarketTransaction. In bootstrapMode, we need to record * these as they arrive in order to be able to compute delivered price of * power purchased in the wholesale market. Note that this computation will * ignore balancing cost. This is intentional. */ public void handleMessage (MarketTransaction tx) { // Save all transactions in bootstrapMode if (bootstrapMode) { ArrayList<MarketTransaction> txs = marketTxMap.get(tx.getTimeslot()); if (txs == null) { txs = new ArrayList<MarketTransaction>(); marketTxMap.put(tx.getTimeslot(), txs); } txs.add(tx); } // reset price escalation when a trade fully clears. Order lastTry = lastOrder.get(tx.getTimeslot()); if (lastTry == null) // should not happen log.error("order corresponding to market tx " + tx + " is null"); else if (tx.getMWh() == lastTry.getMWh()) // fully cleared lastOrder.put(tx.getTimeslot(), null); }
public MarketTransaction makeMarketTransaction (Broker broker, Timeslot timeslot, double mWh, double price) { return new MarketTransaction(broker, getTimeslotIndex(), timeslot, mWh, price); }