Business events end-to-end use case
This use case shows how your data can be captured, how a processing rule is set, and how this data can be further analyzed and visualized.
Scenario
EasyTrade is a simulated trading application with the following use cases:
- Money deposits and withdrawals
- Buy-assets and sell-assets transactions
- Basic dashboards for your trading activities
In this scenario, we suppose you need to calculate the total value of deposits placed on each account, the total and maximum dollar trading volume per account on EasyTrade, and the total value of buy-asset transactions per account.
Before you begin
You need to determine:
- The processing logic and rules
- The data fields needed
Because you need to calculate the dollar trading volume, your processing rule should multiply the price by the amount and add the result as a new field to the event:
Dollar Trading Volume = Price * Amount
You also need to define the data items of the buy-asset request. For example:
{"accountId":6,"amount":10,"instrumentId":1,"price":157.025}
Create a capture rule
-
Go to Settings > Business Analytics > Business Event Sources > OneAgent.
-
Select Add new capture rule and set Rule name to:
easyTrade- /broker/api/trade/BuyAssets
-
Select Add trigger and, in the Summary section, set the following:
- Data source: select
Request - Path
- Operator: select
starts with
- Value: enter or paste
/broker/api/trade/BuyAssets
- Data source: select
-
Define the Event provider:
- Data source:
Fixed value
- Fixed value:
www.easytrade.com
- Data source:
-
Define the Event type:
- Data source:
Fixed value
- Fixed value:
com.easytrade.buy-assets
If you need to add more event types, select Event type separately for each event type. In this case, the event types will also be
com.easytrade.sell-assets
andcom.easytrade.deposit-money
.
- Data source:
-
Define the Event category:
- Data source:
Fixed value
- Fixed value: optional; you can leave it blank in this case
- Data source:
-
In the Event data section, you need to add four data fields.
For each data field:
-
Select Add data field.
-
Set the Field name, Source, and Path values according to the following table:
Field name
Source
Path
accountId
Request-Body
accountId
amount
Request-Body
amount
instrumentId
Request-Body
instrumentID
price
Request-Body
price
-
-
Select Save changes.
Create a data processing rule
To create your data processing rule
-
Go to Settings > Business Analytics > Ingest Pipeline > Processing.
-
Select Add rule and name your rule as
EasyTrade add sum
. -
Set your rule's Matcher to the following matcher-specific DQL query:
matchesValue(event.provider, "www.easytrade.com")
- If you needed to add only one event type (for example,
com.easytrade.buy-assets
), the matcher would be:matchesValue(event.type, "com.easytrade.buy-assets") - For two event types within the same event provider, the matcher would be:
matchesValue(event.type, "com.easytrade.buy-assets") or matchesValue(event.type, "com.easytrade.sell-assets")
- In this use case, however, you need to take all event types under the EasyTrade event provider, so it is sufficient to use:
matchesValue(event.provider, "www.easytrade.com")
- If you needed to add only one event type (for example,
-
In the Transformation fields section, add
price
andamount
.- Select Add item, set Type to double, and set Name to
price
- Select Add item again, set Type to double, and set Name to
amount
- Select Add item, set Type to double, and set Name to
-
Set Processor definition to
FIELDS_ADD(trading_volume:price*amount)
-
Select Save changes.
Add business event metric
To add your business event metric
-
Go to Settings > Business Analytics > Metric extraction.
-
Select Add business event metric and name your metric by adding a Key as
bizevents.EasyTrade.TradingVolume
-
Add a Matcher to your rule by pasting your matcher-specific DQL query:
matchesValue(event.type, "com.easyTrade.buy-assets") -
Choose the Measure on which your metric will be based. In the Attribute value field, add
trading_volume
. -
Select Add dimension. For example, you can define a host as
Host-1
. -
Select Save changes.
To display your metrics
-
Go to Data Explorer.
-
Find your metric in the search window, select Run query, and display your results.
You can also:
- Pin the metric to a classic dashboard. For details, see Pin tiles to your dashboard.
- Export your data to a CSV file.
- Share a link.
- Copy the request.
To create an alert with your metric
- Go to Settings > Anomaly detection > Metric events.
- Select Add metric event and create an event based on your Key,
bizevents.EasyTrade.TradingVolume
.
Choose the retention period
If you need to store your data for one year, for example, for tax purposes
-
Go to Settings > Business Analytics > Ingest Pipeline > Bucket assignment.
-
Select Add rule.
-
Set Rule name to
Bucket_rule
. -
Set Bucket to
Business events (1 year)
. -
Set your rule's Matcher to the following matcher-specific DQL query:
matchesValue(event.provider, "www.easytrade.com")
-
If you needed to add only one event type (for example,
com.easytrade.buy-assets
), the matcher would be:matchesValue(event.type, "com.easytrade.buy-assets") -
For two event types within the same event provider, the matcher would be:
matchesValue(event.type, "com.easytrade.buy-assets") or matchesValue(event.type, "com.easytrade.sell-assets") -
In this use case, however, you need to take all event types under the EasyTrade event provider, so it is sufficient just to use:
matchesValue(event.provider, "www.easytrade.com")
-
-
Select Save changes.
Test your results
To see if your data was captured correctly
-
Go to Explore Business Events.
-
Copy and paste the following query into the edit box:
fetch bizevents| filter event.provider == "www.easytrade.com"| filter event.type == "com.easytrade.buy-assets" OR event.type == "com.easytrade.deposit-money" OR event.type == "com.easytrade.sell-assets"| sort timestamp, direction:"descending" -
Select Run query.
You should get results something like the following:
Analyze your data with DQL
At this point, you can start building your DQL queries to analyze the data loaded, define metrics, and create charts and dashboards.
You need to calculate:
- The total value of deposits per account in the last 30 days
- The total value of buy-asset transactions per account in the last 30 days
- The total and maximum dollar trading volume per account in the last 30 days
To analyze your data using DQL
-
Go to Explore Business Events.
-
Build and run your query:
fetch bizevents, from:now()-30d, to:now()| filter event.provider == "www.easytrade.com" and (event.type == "com.easytrade.buy-assets" OR event.type == "com.easytrade.deposit-money" OR event.type == "com.easytrade.sell-assets")| fieldsAdd moneyTransfered = if(event.type == "com.easytrade.deposit-money", toDouble(amount)),buyAssets = if(event.type == "com.easytrade.buy-assets", toDouble(amount)),trading_volume= if(event.type == "com.easytrade.sell-assets",(amount*price))| summarize sum(moneyTransfered), sum(buyAssets), sum(trading_volume), max(trading_volume), by:accountId
Results table:
accountid
max(trading_volume)
sum(buyAssets)
sum(moneyTransfered)
sum(trading_volume)
6
19924.3187495
609491
1340160.809059129
526623.1340707905
7
47827.65870614
593648
1287203.0690401047
922284.0555854205
8
16718.08125
615123
1288892.9309932007
550042.8770441795
Display your results
Bar chart
Line chart
Dashboard tile
To pin your results to a dashboard, select Actions > Pin to dashboard. You can then select an existing dashboard or create a new one, and name the tile you want to display.