This repository provides a code sample in .NET on how to use some Azure Cosmos DB features integrated with Azure Funcions.
Setup shell was tested on WSL2 (Ubuntu 22.04.2 LTS)
The setup will provision and configure all the resources required.
-
Sign in with Azure CLI
az login
-
Clone the repo
git clone https://github.com/fonsecamar/cosmos-trading-demo.git cd cosmos-trading-demo/deploy/
-
Run setup.sh with the appropriete parameters. Keep the API's URIs prompted when completed.
Provide a non-existent resource group name. Setup will provision.
```bash
#SAMPLE
#./setup.sh 00000000-0000-0000-0000-000000000000 rg-my-demo SouthCentralUS myrandomsuffix
./setup.sh <subscription id> <resource group> <location> <resources suffix>
```
Setup has some pause stages. Hit enter to continue when prompted.
It takes around 3min to provision and configure resoures.
Resources created:
- Resource group
- Azure Blob Storage (ADLS Gen2)
- Azure Cosmos DB account (1 database with 1000 RUs autoscale shared with 5 collections) with Analytical Store enabled
- Azure Event Hub standard
- Azure Steam Analytics job
- Azure Functions Consumption Plan
- Azure Application Insights
You can call Function APIs from Azure Portal or your favorite tool.
-
Start Azure Stream Analytics job
-
Run markerdata generator
cd ../src/marketdata-generator dotnet run
-
Check Cosmos DB marketdata container (updated every 15 second by Azure Stream Analytics job).
-
Call GetStockPrice function
#Setting variables SUFFIX=<your suffix> # Returns Stock Price by symbol curl --request GET "https://functiondemo$SUFFIX.azurewebsites.net/api/stock/MSFT"
-
Call CreateOrder function
# Creates an Order curl --request POST "https://functiondemo$SUFFIX.azurewebsites.net/api/orders/create" \ --header 'Content-Type: application/json' \ --data-raw '{ "customerId": 99999999, "quantity": 1000, "symbol": "MSFT", "price": 300, "action": "buy" }'
-
Call GetOrder function (use orderId from the previous response)
# Returns Order by orderId curl --request GET "https://functiondemo$SUFFIX.azurewebsites.net/api/orders/{orderId}"
-
Call GetExecutions function (use the same orderId)
-- Returns Order Executions by orderId curl --request GET "https://functiondemo$SUFFIX.azurewebsites.net/api/orders/execution/{orderId}"
-
Call GetCustomerPortfolio function (use customerId provided on step 1)
-- Returns Customer Portfolio by customerId curl --request GET "https://functiondemo$SUFFIX.azurewebsites.net/api/customerPortfolio/{customerId}"
CTRL + C
to stop marketdata generator- Delete the Resource Group to destroy all resources
If you find any errors or have suggestions for changes, please be part of this project!
- Create your branch:
git checkout -b my-new-feature
- Add your changes:
git add .
- Commit your changes:
git commit -m '<message>'
- Push your branch to Github:
git push origin my-new-feature
- Create a new Pull Request 😄