summaryrefslogtreecommitdiff
path: root/app/trading/views.py
blob: 9922bd5eb0bb51d90ba7be301a0cbd265907e1da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from datetime import datetime
from django.views.generic.edit import CreateView, UpdateView
from utils.views import PaginatedListView

from .models import LuxTrade, LuxOptionsTrade


class LuxTradeListView(PaginatedListView):
    model = LuxTrade
    template_name = 'trading/list.html'

    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(LuxTradeListView, self).get_context_data(**kwargs)
        context['open_trades'] = LuxTrade.objects.filter(status=0)
        context['watch_trades'] = LuxTrade.objects.filter(status=2)
        context['options_trades'] = LuxOptionsTrade.objects.filter(status__in=[0,2])
        context['options_trades_closed'] = LuxOptionsTrade.objects.filter(status=1)
        context['monthly_pl'] = LuxTrade.stats.get_month_pl()
        context['month'] = datetime.now().strftime('%h')
        return context

    def get_queryset(self):
        queryset = super(LuxTradeListView, self).get_queryset()
        return queryset.filter(status=1)


class LuxTradeDetailView(UpdateView):
    model = LuxTrade
    fields = ['symbol', 'status', 'entry_price', 'stop_price', 'target_price', 'shares', 'close_price', 'notes', 'is_wanderer']
    template_name = 'trading/update_form.html'
    success_url = '/trading/'


class TradeModelFormView(CreateView):
    model = LuxTrade
    fields = ['symbol', 'status', 'entry_price', 'stop_price', 'target_price', 'shares', 'is_wanderer']
    success_url = '/trading/'
    template_name = 'trading/create_form.html'


class LuxOptionsTradeDetailView(UpdateView):
    model = LuxOptionsTrade
    fields = [
        'symbol', 
        'status',
        'entry_price',
        'stop_price',
        'target_price',
        'call_put',
        'expiration_date',
        'strike_price',
        'contract_price',
        'number_contracts',
        'delta',
        'notes'
    ]
    template_name = 'trading/update_options_form.html'
    success_url = '/trading/'


class OptionsModelFormView(CreateView):
    model = LuxOptionsTrade
    fields = [
        'symbol', 
        'status',
        'entry_price',
        'stop_price',
        'target_price',
        'call_put',
        'expiration_date',
        'strike_price',
        'contract_price',
        'number_contracts',
        'delta'
    ]
    success_url = '/trading/'
    template_name = 'trading/create_options_form.html'