★ TopTokens is an API that provides analytic screener that sends market recommendations about sell or buy cryptocurrencies that are backed by tier 1 hedge funds based on market situation that is explained by CNN SPX Fear & Greed Index and Crypto Fear & Greed Index. Processing only reliable tokens that are having at least $500,000,000 market cap.
Documentation for TopTokens API Rest protocol
Table of Contents
TopTokens is an API that provides analytic screener that sends market recommendations about sell or buy cryptocurrencies that are backed by tier 1 hedge funds based on market situation that is explained by CNN SPX Fear & Greed Index and Crypto Fear & Greed Index. Processing only reliable tokens that are having at least $500,000,000 market cap. If Fear & Greed Index less than 45, api sends BUY recommendation and if Fear & Greed Index more than 55, api sends SELL recommendation.
System Design Architecture for Buffettsbot
1. Backend (Django Rest Framework) • API docs in Postman: API docs
• Celery Task Queue for mining data about tier 1 hedge funds portfolios and updating market indicators values:
# Configure Celery Beat
```app.conf.beat_schedule = {
"parse_tier_1_portfolios": {
"task": "analytic_screener.tasks.parse_tier_1_portfolios",
"schedule": timedelta(hours=12),
},
"update_fear_and_greed_indices": {
"task": "analytic_screener.tasks.update_fear_and_greed_indices",
"schedule": timedelta(hours=12),
},
"delete_expired_refresh_tokens": {
"task": "users.tasks.delete_expired_refresh_tokens",
"schedule": crontab(
hour=0, minute=0
), # for dev purposes 2 mins, for prod every midnight
},
}
app.autodiscover_tasks()
2. Database (PostgreSQL)
-
CustomUser: Stores data about user
- Fields:
email
: EmailField, Primary Key, unique, used as the username for authentication.is_staff
: Boolean, Flag to indicate if the user has staff privileges or not.is_active
: Boolean, Flag to indicate if the user’s account is active.date_joined
: DateTimeField, Timestamp of when the user joined the system.
- Fields:
-
Cryptocurrency: Represents a cryptocurrency
- Fields:
name
: CharField, Name of the cryptocurrency.ticker
: CharField, Abbreviation or symbol of the cryptocurrency.price
: FloatField, Current price of the cryptocurrency.market_cap
: PositiveBigIntegerField, Market capitalization of the cryptocurrency.hedge_funds
: ManyToManyField
- Fields:
-
HedgeFund: Represents a hedge fund
- Fields:
name
: CharField, Name of the hedge fund.
- Fields:
-
MarketIndicator: Represents a market indicator
- Fields:
name
: CharField, Name of the market indicator.value
: PositiveIntegerField, Value of the market indicator.
- Fields:
-
MarketRecommendation: Represents a market recommendation
- Fields:
type
: CharField, ChoiceField indicating the type of recommendation ("buy" or "sell").indicator_name
: CharField, Name of the index or recommendation source.value
: PositiveIntegerField, Value associated with the recommendation.created_at
: DateTimeField, Timestamp of when the recommendation was created.
- Fields:
4. Deployment & Infrastructure
• Docker Containers: Used for containerizing the Django application, PostgreSQL database, NGINX reverse proxy server, Redis as message broker and Celery workers that are long-running processes that constantly monitor the task queues for new work and Celery Beat that a single process that schedules periodic tasks
• Docker Compose: Manages multi-container Docker applications.
• Microsoft Azure Linux Ubuntu: VM with 2 CPUs and 4gb RAM
• Microsoft Azure Container Registries: Two repositories for toptokens-api and nginx
-
Get a free API Key at https://docs.coingecko.com/reference/setting-up-your-api-key
-
Clone the repo
https://github.com/r3v5/toptokens-api
-
Navigate to the project directory
cd toptokens-api
-
Create a .env.dev file
DEBUG=1 SECRET_KEY=foo DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1] SQL_ENGINE=django.db.backends.postgresql SQL_DATABASE=toptokensdb SQL_USER=toptokensadmin SQL_PASSWORD=toptokensadmin SQL_HOST=toptokens-db SQL_PORT=5432 DATABASE=postgres POSTGRES_USER=toptokensadmin POSTGRES_PASSWORD=toptokensadmin POSTGRES_DB=toptokensdb CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP=True COINGECKO_API_KEY=<YOUR-API-KEY>``
-
In settings.py comment these variables and uncomment CSRF_TRUSTED_ORIGINS for localhost
#SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
#CSRF_TRUSTED_ORIGINS = os.environ.get("CSRF_TRUSTED_ORIGINS").split(" ")
CSRF_TRUSTED_ORIGINS = ["http://localhost:1337"]
- Start building docker containers for API, Nginx, PostgreSQL, Redis, Celery worker, Celery-beat and up them:
docker compose -f docker-compose.yml up --build
- Make migrations, apply them and collect staticfiles:
docker compose -f docker-compose.yml exec toptokens-api python manage.py makemigrations
docker compose -f docker-compose.yml exec toptokens-api python manage.py migrate
docker compose -f docker-compose.yml exec toptokens-api python manage.py collectstatic --no-input --clear
- Create Django superuser to grant access to Django admin panel:
docker compose -f docker-compose.yml exec toptokens-api python manage.py createsuperuser
- Run tests:
docker compose -f docker-compose.yml exec toptokens-api pytest
- Navigate to Django Admin Panel by this url http://localhost:1337/admin/login/?next=/admin/ and access the content of database with cryptocurrency data:
Email address: email address you used to create superuser
Password: password you used to create superuser
Ian Miller - linkedin
Project Link: https://github.com/r3v5/toptokens-api
API docs in Postman: API docs