nilopmsft / cosmos-trading-demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cosmos DB NoSQL API - Trading Demo

Introduction

This repository provides a code sample in .NET on how to use some Azure Cosmos DB features integrated with Azure Funcions.

Requirements

It's recommended to create all the resources within the same region.

Configuration

  • Create Event Hubs

    • Create marketdata Event Hub
    • Create ems-orderstoexecute Event Hub
    • Create ems-ordersexecuted Event Hub
    • Create ems-executions Event Hub
  • Create a database and containers

    • Create trading database
    • Create orders container: provide /orderId as the Partition key, select Autoscale and provide 1000 as Collection Max RU/s.
    • Create orderExecutions container: provide /orderId as the Partition key, select Autoscale and provide 1000 as Collection Max RU/s.
    • Create marketdata container: provide /symbol as the Partition key, select Autoscale and provide 1000 as Collection Max RU/s.
    • Create customerPortfolio container using the SDK (Create new container with hierarchical partition keys): provide /customerId and /assetClass as the Partition keys, select Autoscale and provide 1000 as Collection Max RU/s.
  • Configure application settings

    • CosmosDBConnection: <your Cosmos DB connection string>
    • ordersHubConnection: <your Event Hub namespace connection string>
  • Deploy Function application to Azure (Deploy using VS Code).

Running the sample

You can call Function APIs from Azure Portal or your favorite tool.

  1. Call CreateOrder function

    curl --request POST 'https://<function app name>.azurewebsites.net/api/orders/create?code=<function code>' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "customerId": 99999999,
        "quantity": 1000,
        "symbol": "MSFT",
        "price": 300,
        "action": "buy"
    }'
    
  2. Call GetOrder function (use orderId from the previous response)

    -- Returns Order by orderId
    curl --request GET 'https://<function app name>.azurewebsites.net/api/orders/{orderId}?code=<function code>'
    
  3. Call GetExecutions function (use the same orderId)

    -- Returns Order Executions by orderId
    curl --request GET 'https://<function app name>.azurewebsites.net/api/orders/execution/{orderId}?code=<function code>'
    
  4. Call GetCustomerPortfolio function (use customerId provided on step 1)

    -- Returns Customer Portfolio by customerId
    curl --request GET 'https://<function app name>.azurewebsites.net/api/customerPortfolio/{customerId}?code=<function code>'
    

How to Contribute

If you find any errors or have suggestions for changes, please be part of this project!

  1. Create your branch: git checkout -b my-new-feature
  2. Add your changes: git add .
  3. Commit your changes: git commit -m '<message>'
  4. Push your branch to Github: git push origin my-new-feature
  5. Create a new Pull Request 😄

About

License:MIT License


Languages

Language:C# 100.0%