OTE app: improving the back end
Here, we shall look into the back-end code and make some useful changes to increase the usability and range of the app.
Adding a query
Now add a new query to your Data Server to make this information available to the front end.
-
Go to the folder
OTE\server\OTE-app\src\main\genesis\scripts
. -
Go to the file
OTE\server\OTE-app\src\main\genesis\scripts\OTE-dataserver.kts
and add the following code [Need to specify where] to define the new query.
This can also be found in a TODO block.
query("ALL_USER_NAMES", USER) {
fields {
USER_NAME
}
}
Updating the consolidators
The code changes listed can also be found in TODO blocks.
-
Go to the file
OTE\server\OTE-app\src\main\genesis\scripts\OTE-consolidator.kts
. -
In the
SELL_PARTICIPANT_POSITION_AGG consolidator
, findsum { quantity } into QUANTITY
. Update it as follows:
sum { quantity * -1 } into QUANTITY
Modify the CASH_BALANCE_AGG consolidator so that the new aggregations are included as a result of the primary key changes that were made.
Aggregate buy and sell in the consolidators
To ensure that Buy and Sell data is aggregated and captured for the correct side in the OPEN_POSITION_AGG
consolidator:
- Add the following code to the imports section:
import global.genesis.gen.dao.enums.OTE.passive_order_book.Side
import global.genesis.gen.dao.enums.OTE.passive_order_book.Status
- Find
sum { openQuantity } into BUY_QUANTITY
andsum { openQuantity } into SELL_QUANTITY
. Update as follows:
sum { openQuantity } onlyIf { side == Side.Buy } into BUY_QUANTITY
sum { openQuantity } onlyIf { side == Side.Sell } into SELL_QUANTITY
- Find
groupBy
and add the following clause above this label:
where {
status == Status.Active
}
Create a new passive order book eventHandler
To handle the Passive Order Book correctly, you need to update the -eventhandler.kts
file. The file contains a list of TODO items. Each of these contains extra code.
Checking the file
Some of the TODOs involve large code snippets. You are going to make major changes to this file. So, before you change anything, take some time to look inside it.
There are more than 20 different eventHandlers in the file, and you will see them mostly in groups of three: _INSERT, _MODIFY and _DELETE. The exception is for the Passive Order Book, which only has _INSERT and _DELETE (and you will be changing these).
At the end of the file are are three eventHandlers that need custom logic, which cannot be created using Genesis Create. These eventHandlers serve new buttons on the front end, which enable the user to simulate End of Day processes. You will need to add code to:
- RUN_CLOSING_PRICES
- RUN_VARIATION_MARGIN
- EXPIRE ORDERS
Here is a summary of the changes you need to make:
Item | Task |
---|---|
import statements | Insert these at the beginning of the file. |
PASSIVE_ORDER_BOOK_INSERT | Replace this with the larger contextEventHandler provided. |
PASSIVE_ORDER_BOOK_DELETE | Replace this with the larger contextEventHandler provided. |
RUN_CLOSING_PRICES | Add additional code after the onCommit line. |
RUN_VARIATION_MARGIN | Add additional code before and after the onCommit line. |
EXPIRE_ORDERS | Add additional code after the onCommit line. |
Genesis Create adds TODO items automatically, and you can ignore the generic TODO at the end of the file.
Implementing the TODO items
For each TODO item:
- Cut the code from that item.
- Insert it into the relevant point in the code itself.
- Remove the asterisk character from the beginning of each line. But take care not to remove any asterisks in the code you have inserted!
- Once you have made the changes, remove the TODO comments themselves to keep the code tidy.
Our extensive usability team has found that it is easier to insert the import statements first and then go to the end of the file and work through the remaining TODOs in reverse order. This makes it easier to keep track as you cut and paste.
When you are cutting and pasting the code in the TODO items, watch out for word wrapping, which can split lines of code that need to be on a single line. Take extra care if you have a small window.
The code snippets themselves have comments throughout to indicate the purpose of each codeblock. You should leave these in place.
That's it. Once you have inserted this code, you have successfully set the logic for handling the passive order book.