- .NET 10 SDK
- Docker (Optional, for containerized deployment)
-
Clone the repository:
git clone https://github.com/nikolic-milan/MetaExchange.git cd MetaExchange -
Restore dependencies:
dotnet restore
-
Data File: Ensure
order_books_data.jsonis present in the root directory.
The CLI allows enables calculating an execution plan from the terminal. Note: the terminal handles decimal values based on the OS locale, try 1.5 and 1,5 and see the difference.
# Buying 1.5 BTC with 10s window filtering
dotnet run --project src/MetaExchange.Console/MetaExchange.Console.csproj -- --type Buy --amount 1.5 --use-window
# Selling 1.5 BTC with 10s window filtering
dotnet run --project src/MetaExchange.Console/MetaExchange.Console.csproj -- --type Sell --amount 1.5 --use-windowOptions:
-t, --type: Order type (BuyorSell). Default:Buy.-a, --amount: Amount of BTC.-w, --use-window: Boolean flag to only use snapshots within a 10s window of the current time.
The project includes an ASP.NET Core Web API with Swagger documentation.
# Start the API
dotnet run --project src/MetaExchange.Api/MetaExchange.Api.csproj --urls "http://localhost:5000"Swagger UI: http://localhost:5000/swagger
Endpoint: GET /api/v1/MetaExchange/execution-plan
type:buyorsellamount: decimaluseWindow: boolean (optional)
The solution is fully containerized and configurable via environment variables.
# Build the image
docker build -t metaexchange-api -f src/MetaExchange.Api/Dockerfile .
# Run the container (mounting the local data file)
docker run -p 8080:8080 \
-v "$(pwd)/order_books_data.json:/app/order_books_data.json" \
metaexchange-api- The logic is separated into
Core(entities/services) andInfrastructure(data loading). - The Web API uses standard .NET DI to manage services and configuration.
- Greedy Optimization: For Buys, the algorithm sorts all available asks across all exchanges from lowest to highest price. For Sells, it sorts bids from highest to lowest.
- Constraint Handling: The taks task description states that a balance constraint should be applied. Since the data provided does not include any constraints the file JsonOrderBookRepository.cs has the fallowing:
- Total volume as exchange balance (commented out) For each exchange the SUM of 'asks' and 'bids' is calculated and assigned as the exchange balance.
- Net liquidity (difference between counter-orders) (commented out) For each exchange the difference between counter-orders is calculated and assigned as the exchange balance.
- Random (Within specified ranges) (active) For each exchange the balance is randomly generated within a specified range.
- Time Window Filtering I noticed that the data file provided covers a span of 1 hour. Since it didn't seem realstic to use the whole range (a snapshot from 40 minutes, might not be relevant), I added an optional flag which only uses the snapshopts within a 10 second window.
The project includes Unit Tests, Logical E2E Tests, and Web API Integration Tests.
dotnet test tests/MetaExchange.Tests/MetaExchange.Tests.csproj