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.
EasyTrade is a simulated trading application with the following use cases:
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.
You need to determine:
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}
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:
Request - Path
starts with
/broker/api/trade/BuyAssets
Define the Event provider:
Fixed value
www.easytrade.com
Define the Event type:
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
and com.easytrade.deposit-money
.
Define the Event category:
Fixed value
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.
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")
com.easytrade.buy-assets
), the matcher would be:
matchesValue(event.type, "com.easytrade.buy-assets")
matchesValue(event.type, "com.easytrade.buy-assets") or matchesValue(event.type, "com.easytrade.sell-assets")
matchesValue(event.provider, "www.easytrade.com")
In the Transformation fields section, add price
and amount
.
price
amount
Set Processor definition to FIELDS_ADD(trading_volume:price*amount)
Select Save changes.
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:
To create an alert with your metric
bizevents.EasyTrade.TradingVolume
.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.
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:
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:
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
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.