diff --git a/backend/Dockerfile b/backend/Dockerfile index eeb0555..17fd30d 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -2,6 +2,10 @@ FROM python:3.9.1-alpine3.13 MAINTAINER "Ameya Shenoy " +ENV PYTHONUNBUFFERED=1 + +WORKDIR /code + COPY requirements.txt / RUN set -ex \ @@ -10,7 +14,13 @@ RUN set -ex \ musl-dev \ postgresql-dev \ python3-dev \ + && apk add --no-cache \ + libpq \ && pip install -r /requirements.txt \ && rm -rf requirements.txt \ && apk del .build-deps +COPY . /code + +ENTRYPOINT sh /code/entrypoint.sh + diff --git a/backend/app/migrations/0001_initial.py b/backend/app/migrations/0001_initial.py new file mode 100644 index 0000000..dc21251 --- /dev/null +++ b/backend/app/migrations/0001_initial.py @@ -0,0 +1,35 @@ +# Generated by Django 3.1.6 on 2021-02-08 21:43 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='BhavCopyEquity', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False)), + ('date', models.DateField(auto_now_add=True)), + ('sc_code', models.PositiveIntegerField()), + ('sc_name', models.CharField(max_length=20)), + ('sc_group', models.CharField(max_length=2)), + ('sc_type', models.CharField(max_length=1)), + ('open_price', models.DecimalField(decimal_places=2, max_digits=12)), + ('high_price', models.DecimalField(decimal_places=2, max_digits=12)), + ('low_price', models.DecimalField(decimal_places=2, max_digits=12)), + ('close_price', models.DecimalField(decimal_places=2, max_digits=12)), + ('last_price', models.DecimalField(decimal_places=2, max_digits=12)), + ('prevclose_price', models.DecimalField(decimal_places=2, max_digits=12)), + ('no_trades', models.PositiveIntegerField()), + ('no_of_shrs', models.PositiveIntegerField()), + ('net_turnov', models.PositiveIntegerField()), + ('tdcloindi', models.TextField()), + ], + ), + ] diff --git a/backend/app/models.py b/backend/app/models.py index 71a8362..0fe0c18 100644 --- a/backend/app/models.py +++ b/backend/app/models.py @@ -1,3 +1,28 @@ from django.db import models # Create your models here. + +class BhavCopyEquity(models.Model): + id = models.AutoField(primary_key=True) + date = models.DateField(auto_now_add=True, editable=False) + + # Ref: https://www.bseindia.com/markets/debt/BhavCopyhelp.aspx + sc_code = models.PositiveIntegerField() + sc_name = models.CharField(max_length=20) + sc_group = models.CharField(max_length=2) + sc_type = models.CharField(max_length=1) + open_price = models.DecimalField(max_digits=12, decimal_places=2) + high_price = models.DecimalField(max_digits=12, decimal_places=2) + low_price = models.DecimalField(max_digits=12, decimal_places=2) + close_price = models.DecimalField(max_digits=12, decimal_places=2) + last_price = models.DecimalField(max_digits=12, decimal_places=2) + prevclose_price = models.DecimalField(max_digits=12, decimal_places=2) + no_trades = models.PositiveIntegerField() + no_of_shrs = models.PositiveIntegerField() + net_turnov = models.PositiveIntegerField() + tdcloindi = models.TextField() + + def __str__(self): + return f'{self.DATE}-{self.SC_CODE}' + + diff --git a/backend/backend/settings.py b/backend/backend/settings.py index f91c00f..cf5fe92 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -38,6 +38,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'app', ] MIDDLEWARE = [ @@ -74,14 +75,25 @@ WSGI_APPLICATION = 'backend.wsgi.application' # Database # https://docs.djangoproject.com/en/3.1/ref/settings/#databases +# DATABASES = { +# 'default': { +# 'ENGINE': 'django.db.backends.sqlite3', +# 'NAME': BASE_DIR / 'db.sqlite3', +# } +# } DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'bullish', + 'USER': 'bullish', + 'PASSWORD': 'password', + 'HOST': 'db', + 'PORT': '5432', } } + # Password validation # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators diff --git a/backend/entrypoint.sh b/backend/entrypoint.sh new file mode 100644 index 0000000..be435d4 --- /dev/null +++ b/backend/entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# Apply database migrations +echo "Apply database migrations" +python manage.py migrate + +# Start server +echo "Starting server" +python manage.py runserver 0.0.0.0:8000 + + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e98d626 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,53 @@ +--- + +version: '3.8' + +services: + backend: + image: codingcoffee/bullish-backend + build: + context: ./backend + volumes: + - ./backend:/code + depends_on: + - db + - redis + ports: + - 8000:8000 + + redis: + image: redis:6.0.10-alpine3.13 + # ports: + # - 6379:6379 + + db: + image: postgres:13.1-alpine + restart: unless-stopped + volumes: + - bullish-db-data:/var/lib/postgresql/data/pgdata + # TODO: remove pass + environment: + - PGDATA=/var/lib/postgresql/data/pgdata + - POSTGRES_SERVER=db + - POSTGRES_USER=bullish + - POSTGRES_PASSWORD=password + - POSTGRES_DB=bullish + # ports: + # - 5432:5432 + + pgadmin: + image: dpage/pgadmin4 + restart: unless-stopped + depends_on: + - db + environment: + - PGADMIN_LISTEN_PORT=5050 + - PGADMIN_DEFAULT_EMAIL=admin@bullish.io + - PGADMIN_DEFAULT_PASSWORD=password + ports: + - 5050:5050 + +volumes: + bullish-db-data: + +