Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
281 changes: 281 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
# Created by https://www.toptal.com/developers/gitignore/api/python,visualstudiocode,django
# Edit at https://www.toptal.com/developers/gitignore?templates=python,visualstudiocode,django

### Django ###
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
db.sqlite3
db.sqlite3-journal
media

# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
# in your Git repository. Update and uncomment the following line accordingly.
# <django-project-name>/staticfiles/

### Django.Python Stack ###
# Byte-compiled / optimized / DLL files
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo

# Django stuff:

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

### Python ###
# Byte-compiled / optimized / DLL files

# C extensions

# Distribution / packaging

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.

# Installer logs

# Unit test / coverage reports

# Translations

# Django stuff:

# Flask stuff:

# Scrapy stuff:

# Sphinx documentation

# PyBuilder

# Jupyter Notebook

# IPython

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm

# Celery stuff

# SageMath parsed files

# Environments

# Spyder project settings

# Rope project settings

# mkdocs documentation

# mypy

# Pyre type checker

# pytype static type analyzer

# Cython debug symbols

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.

### VisualStudioCode ###
.vscode/*
.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

# Support for Project snippet scope
.vscode/*.code-snippets

# Ignore code-workspaces
*.code-workspace

# End of https://www.toptal.com/developers/gitignore/api/python,visualstudiocode,django
49 changes: 21 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
# In name of Allah
# Documentation

You can check full documentation with postman from [here](https://documenter.getpostman.com/view/17658108/2s83zgu4om)

## Introduction
We want to develop a REST based django application to read signed in user's KuCoin open positions for them. For this to happen, you must be able to read user's positions (if requested from user) every 30 seconds.

The application you develop must have these features:
- Users should be able to **sign up** (provide name, username & kucoin details).
- Users should be able to **sign in**.
- Users should be able to **request position tracking**.
- Users should be able to **see list** of current open positions.
- Application should be able to track user's positions every 30 seconds.
- Application should be able to handle multi users.
- Application must be able to resume its job after restart.

You can use [this api](https://docs.kucoin.com/#list-accounts) from KuCoin to handle this. You should create KuCoin account if you do not have already & get api key & secret to test your implementation. Note we do not need your api key, that is only for your own usage.

### Note
- We do **NOT want any kind of UI** from you
- KuCoin api key & secrets should not be stored in raw format


## Expectations:
We want a clean, readable and maintainable code with meaningful comments and docstrings. Also you need to provide postman API doc for web app.

## Task
1. Fork this repository
2. Develop the challenge with Django 3 or higher
3. Push your code to your repository
4. Send us a pull request, we will review and get back to you
5. Enjoy

This project is a REST based django application to read signed in user's KuCoin open positions for them. For this to happen, application able to read user's positions (if requested from user) every 30 seconds.

Application have these features:

- Users able to **sign up** (provide name, username & kucoin details).
- Users able to **sign in** with jwt authentication.
- Users able to **request position tracking** with send request based on **track** field ("true" or "false").
- Users able to **see list** of current open (active) positions.
- Application able to track user's positions every 30 seconds with celery periodic task.
- Application able to handle multi users with celery task & redis.
- Application able to resume its job after restart with redis backend and database.

Application use [this api](https://docs.kucoin.com/#list-accounts) from KuCoin to handle KuCoin positions.

# Note

**Attention!** All settings such as SECRET_KEY, DEBUG, ENCRYPT_KEY and etc have been exhibited because this is a test project, please keep those in production secret.
Empty file added accounts/__init__.py
Empty file.
23 changes: 23 additions & 0 deletions accounts/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.contrib import admin
from .models import User
from django.contrib.auth.admin import UserAdmin as DefaultUserAdmin


@admin.register(User)
class UserAdmin(DefaultUserAdmin):
'''
Change field of default user admin page
'''

fieldsets = (
(None, {'fields': ('username', 'password')}),
('Personal info',
{
'fields':
('name', 'kucoin_key', 'kucoin_secret', 'kucoin_passphrase')}),
('Permissions', {'fields': ('is_active', 'is_staff', 'is_superuser', 'groups', 'user_permissions'), }),
('Important dates', {'fields': ('last_login', 'date_joined')}),)

list_filter = ('is_staff', 'is_superuser', 'is_active', 'groups')
list_display = ('username', 'name', 'is_staff', 'is_active')
list_editable = ('is_staff', 'is_active')
6 changes: 6 additions & 0 deletions accounts/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AccountsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'accounts'
32 changes: 32 additions & 0 deletions accounts/encryption.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from cryptography.fernet import Fernet
import base64
from django.conf import settings


def encrypt(txt) -> str:
'''
Encrypt data
'''

try:
txt = str(txt)
cipher_suite = Fernet(settings.ENCRYPT_KEY)
encrypted_text = cipher_suite.encrypt(txt.encode('ascii'))
encrypted_text = base64.urlsafe_b64encode(encrypted_text).decode("ascii")
return encrypted_text
except Exception:
return None


def decrypt(txt) -> str:
'''
Decrypt data
'''

try:
txt = base64.urlsafe_b64decode(txt)
cipher_suite = Fernet(settings.ENCRYPT_KEY)
decoded_text = cipher_suite.decrypt(txt).decode("ascii")
return decoded_text
except Exception:
return None
Loading