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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
Empty file added InvestorPlayground/__init__.py
Empty file.
Binary file added InvestorPlayground/__init__.pyc
Binary file not shown.
133 changes: 133 additions & 0 deletions InvestorPlayground/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
"""
Django settings for InvestorPlayground project.

Generated by 'django-admin startproject' using Django 1.9.5.

For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ')d!2xd310y)hwj=2oepcqroaqo1%t9t9=7f6rez4bvj#_dq7k%'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'PlaygroundMgmt.apps.PlaygroundmgmtConfig',
'rest_framework'
]

MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'InvestorPlayground.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

# static files will come from here
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
os.path.join(BASE_DIR, "bower_components"),
os.path.join(BASE_DIR, "node_modules")
)

WSGI_APPLICATION = 'InvestorPlayground.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'investor_playground',
'USER': 'investor_playground_user',
'PASSWORD': 'investor_playground_pass',
'HOST': '127.0.0.1'
}
}


# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'
Binary file added InvestorPlayground/settings.pyc
Binary file not shown.
23 changes: 23 additions & 0 deletions InvestorPlayground/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""InvestorPlayground URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.9/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
url(r'^', include('PlaygroundMgmt.urls')),
url(r'^PlaygroundMgmt/', include('PlaygroundMgmt.urls')),
url(r'^admin/', admin.site.urls),
]
Binary file added InvestorPlayground/urls.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions InvestorPlayground/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for InvestorPlayground project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "InvestorPlayground.settings")

application = get_wsgi_application()
Binary file added InvestorPlayground/wsgi.pyc
Binary file not shown.
Empty file added PlaygroundMgmt/__init__.py
Empty file.
Binary file added PlaygroundMgmt/__init__.pyc
Binary file not shown.
9 changes: 9 additions & 0 deletions PlaygroundMgmt/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.contrib import admin

from .models import *

admin.site.register(Instrument)
admin.site.register(Market)
admin.site.register(AssetType)
admin.site.register(Portfolio)
admin.site.register(Investment)
Binary file added PlaygroundMgmt/admin.pyc
Binary file not shown.
7 changes: 7 additions & 0 deletions PlaygroundMgmt/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import unicode_literals

from django.apps import AppConfig


class PlaygroundmgmtConfig(AppConfig):
name = 'PlaygroundMgmt'
Binary file added PlaygroundMgmt/apps.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions PlaygroundMgmt/fixtures/playground_init_data.json

Large diffs are not rendered by default.

Empty file.
Binary file added PlaygroundMgmt/management/__init__.pyc
Binary file not shown.
Empty file.
Binary file added PlaygroundMgmt/management/commands/__init__.pyc
Binary file not shown.
48 changes: 48 additions & 0 deletions PlaygroundMgmt/management/commands/import_instruments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from django.core.management.base import BaseCommand, CommandError
from PlaygroundMgmt.models import *
import csv

class Command(BaseCommand):
help = 'Import CSV from instruments. E.g: Coding challenge provided Stock List'

def add_arguments(self, parser):
parser.add_argument('file', nargs='+', type=str)

def renderInstrument(self, row):
market_name = row[2] # find the market name
try:
_market = Market.objects.get(name = market_name)
except Market.DoesNotExist: # this market will be created
_market = Market(name = market_name)
_market.save()

asset_type = row[3] # find the asset_type in csv
try:
_asset = AssetType.objects.get(name = asset_type)
except AssetType.DoesNotExist: # this asset type will be created
_asset = AssetType(name = asset_type)
_asset.save()

_ticker = row[0] # ticker
_name = row[1] # stock name

ins = Instrument(ticker = _ticker, name = _name, market = _market, asset_type = _asset)
print('adding: ', ins.name)
ins.save()

def handle(self, *args, **options):
filename = options['file'][0]

self.stdout.write("Looking to import from: " + filename)
with open(filename, 'rb') as csvfile:
rows = csv.reader(csvfile, delimiter=',')
i = 0
for row in rows:
if i > 0:
self.renderInstrument(row)
i += 1

print 'processed ' + str(i) + ' instruments'



Binary file not shown.
69 changes: 69 additions & 0 deletions PlaygroundMgmt/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.5 on 2016-04-27 17:56
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='AssetType',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
],
),
migrations.CreateModel(
name='Instrument',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('ticker', models.CharField(max_length=200)),
('name', models.CharField(max_length=200)),
('asset_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='PlaygroundMgmt.AssetType')),
],
),
migrations.CreateModel(
name='Investment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('size', models.DecimalField(decimal_places=2, max_digits=3)),
('instrument', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='PlaygroundMgmt.Instrument')),
],
),
migrations.CreateModel(
name='Market',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
],
),
migrations.CreateModel(
name='Portfolio',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
('instruments', models.ManyToManyField(through='PlaygroundMgmt.Investment', to='PlaygroundMgmt.Instrument')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.AddField(
model_name='investment',
name='portfolio',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='PlaygroundMgmt.Portfolio'),
),
migrations.AddField(
model_name='instrument',
name='market',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='PlaygroundMgmt.Market'),
),
]
Binary file added PlaygroundMgmt/migrations/0001_initial.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added PlaygroundMgmt/migrations/0009_auto_20160427_1732.pyc
Binary file not shown.
Empty file.
Binary file added PlaygroundMgmt/migrations/__init__.pyc
Binary file not shown.
52 changes: 52 additions & 0 deletions PlaygroundMgmt/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from __future__ import unicode_literals

from django.db import models
from django.contrib.auth.models import User

# Types of assets
class AssetType(models.Model):
name = models.CharField(max_length = 200)

def __str__(self):
return self.name

# Types of Markets
class Market(models.Model):
name = models.CharField(max_length = 200)

def __str__(self):
return self.name

# Basic instrument model
class Instrument(models.Model):
ticker = models.CharField(max_length = 200)
name = models.CharField(max_length = 200)
market = models.ForeignKey(Market)
asset_type = models.ForeignKey(AssetType)

def __str__(self):
return self.name

# Portfolio, linked to a User
class Portfolio(models.Model):
user = models.ForeignKey(User)
name = models.CharField(max_length = 200)
instruments = models.ManyToManyField(Instrument, through = 'Investment')

def __str__(self):
return self.name

class Meta:
ordering = ['id']

# Investments are the set of instruments an investor
# places in his portfolio
class Investment(models.Model):
portfolio = models.ForeignKey(Portfolio, on_delete = models.CASCADE)
instrument = models.ForeignKey(Instrument, on_delete = models.CASCADE)
size = models.DecimalField(max_digits = 3, decimal_places = 2)

def __str__(self):
return self.portfolio.user.username + ' [id:' + str(self.portfolio.user.id) + ']' + \
' > ' + self.portfolio.name + ' [id:' + str(self.portfolio.id) + ']' + ' > ' + \
self.instrument.name + ' [id:' + str(self.instrument.id) + ']'
Binary file added PlaygroundMgmt/models.pyc
Binary file not shown.
7 changes: 7 additions & 0 deletions PlaygroundMgmt/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from rest_framework import serializers
from .models import AssetType

class AssetTypeSerializer(serializers.ModelSerializer):
class Meta:
model = AssetType
fields = ('id', 'name')
Binary file added PlaygroundMgmt/serializers.pyc
Binary file not shown.
Loading