Skip to content

fergusdixon/django-coin-monitor

Repository files navigation

Coin Monitor API

Test and Flake8 DeepSource

Setup

Poetry

Poetry is used for virtual environments / dependency management. Install it here: https://python-poetry.org/docs/

Install dependencies
poetry install
Activate virtual env
poetry shell
Set environment details
cp .env.example .env

Modify any variables you may need there

Start the server
python manage.py runserver <port_number>
Install pre-commit checks
pre-commit install

Routes

  • GET /coinList/: Gets a list of coins

curl --location --request GET 'http://127.0.0.1:8000/coinList'

[
    {
        "id": "01coin",
        "name": "01coin",
        "symbol": "zoc"
    }
]
  • GET /marketCap/: Params: coin_id, date (YYYY/MM/DD), currency

curl --location --request GET 'http://127.0.0.1:8000/marketCap?coin_id=ripple&date=2020/08/05&currency=gbp'

{
    "gbp": 10294177055.519627
}

Scaling

Caching

JSON responses are cached per view for one hour, to minimize load on CoinGecko.

/marketCap views are cached according to combination of query parameters to ensure maximum accuracy and cache hit rate.

Sessions

The CoinGecko client uses Sessions to reuse TCP connections, reducing load on CoinGecko

Security

  • HTTPS (including forced redirect if not in debug mode)
  • Input validation of GET parameters
  • Validation of upstream data (CoinGecko) using pydantic models

Redundancy

  • 3 retries to CoinGecko with a backoff of 0.2
  • Cached in memory so no need for an external cache (Redis)
  • No database requirements