Giter Site home page Giter Site logo

coinmena's Introduction

Coinmena Test

Question: Write an API using Django that fetches the price of BTC/USD from the alphavantage API every hour, and stores it on postgres. This API must be secured meaning that you need an API key to use it. There should be two endpoints: GET /api/v1/quotes - returns exchange rate and POST /api/v1/quotes which triggers force requesting of the price from alphavantage. The API & DB should be containerized using Docker as well.- Every part should be as simple as possible.

  • The project should be committed to GitHub.
  • The sensitive data such as alphavantage API key, should be passed from the .env “gitignored” file via environment variables.

Setup

  1. Clone the repo
git clone [email protected]:dineshkrishnareddy/coinmena.git
  1. Run the docker container
cd coinmena
docker-compose up -d

Generating/Getting API token

  1. Generate API token
curl -X POST -d "{\"key_name\": \"dummy\"}" http://localhost:8000/api/v1/api-key/
  1. Get already created API token
curl -X GET http://localhost:8000/api/v1/api-key/?key_name=dummy

Getting exchange rate

  1. Get exchange rate
curl -X POST -H "Authorization: Api-Key <API_KEY>" -d "{\"from_currency\": \"USD\", \"to_currency\": \"JPY\"}" http://localhost:8000/api/v1/quotes/
  1. Get current exchange rate
curl -X GET -H "Authorization: Api-Key <API_KEY>" http://localhost:8000/api/v1/quotes/?from_currency=USD&to_currency=JPY

Generating exchange rate every hour

We created a celery beat periodic task to populate exchange rate every hour. We used redis as the message broker for celery

How to run celery beat and celery worker manually

celery -A coinmena beat -l info
celery -A coinmena worker -l info

NOTE

  1. Without Authorization exchange rate API will return error. Authorization API_KEY can be generated as the above steps
  2. docker-compose command will run celery tasks also along with web.

coinmena's People

Contributors

dineshkrishnareddy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.