Skip to content

nikolic-milan/MetaExchange

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Getting Started

Prerequisites

Setup

  1. Clone the repository:

    git clone https://github.com/nikolic-milan/MetaExchange.git
    cd MetaExchange
  2. Restore dependencies:

    dotnet restore
  3. Data File: Ensure order_books_data.json is present in the root directory.


Usage

1. Console Application

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-window

Options:

  • -t, --type: Order type (Buy or Sell). Default: Buy.
  • -a, --amount: Amount of BTC.
  • -w, --use-window: Boolean flag to only use snapshots within a 10s window of the current time.

2. Web API

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: buy or sell
  • amount: decimal
  • useWindow: boolean (optional)

3. Docker Deployment

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

Assumptions & Approach

Architectural Design

  • The logic is separated into Core (entities/services) and Infrastructure (data loading).
  • The Web API uses standard .NET DI to manage services and configuration.

Approach

  • 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:
  1. Total volume as exchange balance (commented out) For each exchange the SUM of 'asks' and 'bids' is calculated and assigned as the exchange balance.
  2. Net liquidity (difference between counter-orders) (commented out) For each exchange the difference between counter-orders is calculated and assigned as the exchange balance.
  3. 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.

Running Tests

The project includes Unit Tests, Logical E2E Tests, and Web API Integration Tests.

dotnet test tests/MetaExchange.Tests/MetaExchange.Tests.csproj

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors