Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Did some work on the price for executed orders that were partially ex…

…ecuted first
  • Loading branch information...
commit 6d5209681540fa5be92fcf445735f6d4147d1a60 1 parent be6482f
@jettro jettro authored
View
4 app/src/main/java/org/axonframework/samples/trader/app/command/trading/Transaction.java
@@ -133,12 +133,12 @@ public void onTransactionCancelled(SellTransactionCancelledEvent event) {
@EventHandler
public void onTransactionExecuted(BuyTransactionExecutedEvent event) {
- this.amountOfExecutedItems = event.getAmountOfItems();
+ this.amountOfExecutedItems = this.amountOfItems;
}
@EventHandler
public void onTransactionExecuted(SellTransactionExecutedEvent event) {
- this.amountOfExecutedItems = event.getAmountOfItems();
+ this.amountOfExecutedItems = this.amountOfItems;
}
@EventHandler
View
2  ...rc/main/java/org/axonframework/samples/trader/app/query/transaction/TransactionEntry.java
@@ -38,7 +38,7 @@ public long getAmountOfExecutedItems() {
return amountOfExecutedItems;
}
- public void setAmountOfExecutedItems(int amountOfExecutedItems) {
+ public void setAmountOfExecutedItems(long amountOfExecutedItems) {
this.amountOfExecutedItems = amountOfExecutedItems;
}
View
18 ...java/org/axonframework/samples/trader/app/query/transaction/TransactionEventListener.java
@@ -88,17 +88,27 @@ public void handleEvent(SellTransactionPartiallyExecutedEvent event) {
private void partiallyExecuteTransaction(AbstractTransactionPartiallyExecutedEvent event) {
TransactionEntry transactionEntry = transactionQueryRepository.findOne(event.getTransactionIdentifier().asString());
+
+ long value = transactionEntry.getAmountOfExecutedItems() * transactionEntry.getPricePerItem();
+ long additionalValue = event.getAmountOfExecutedItems() * event.getItemPrice();
+ long newPrice = (value + additionalValue) / event.getTotalOfExecutedItems();
+
transactionEntry.setState(PARTIALLYEXECUTED);
- transactionEntry.setAmountOfExecutedItems((int) event.getTotalOfExecutedItems());
- transactionEntry.setPricePerItem(event.getItemPrice());
+ transactionEntry.setAmountOfExecutedItems(event.getTotalOfExecutedItems());
+ transactionEntry.setPricePerItem(newPrice);
transactionQueryRepository.save(transactionEntry);
}
private void executeTransaction(AbstractTransactionExecutedEvent event) {
TransactionEntry transactionEntry = transactionQueryRepository.findOne(event.getTransactionIdentifier().asString());
+
+ long value = transactionEntry.getAmountOfExecutedItems() * transactionEntry.getPricePerItem();
+ long additionalValue = event.getAmountOfItems() * event.getItemPrice();
+ long newPrice = (value + additionalValue) / transactionEntry.getAmountOfItems();
+
transactionEntry.setState(EXECUTED);
- transactionEntry.setAmountOfExecutedItems((int) event.getAmountOfItems());
- transactionEntry.setPricePerItem(event.getItemPrice());
+ transactionEntry.setAmountOfExecutedItems(transactionEntry.getAmountOfItems());
+ transactionEntry.setPricePerItem(newPrice);
transactionQueryRepository.save(transactionEntry);
}
Please sign in to comment.
Something went wrong with that request. Please try again.