summaryrefslogtreecommitdiff
path: root/app/trading/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/trading/views.py')
-rw-r--r--app/trading/views.py48
1 files changed, 44 insertions, 4 deletions
diff --git a/app/trading/views.py b/app/trading/views.py
index b885d7c..69e1ace 100644
--- a/app/trading/views.py
+++ b/app/trading/views.py
@@ -3,8 +3,8 @@ from django.http import HttpResponseRedirect
from django.views.generic.edit import CreateView, UpdateView
from utils.views import PaginatedListView
-from .models import LuxTrade, LuxOptionsTrade, LuxOptionContact, LuxOptionPurchase
-from .forms import LuxOptionsForm
+from .models import LuxTrade, LuxOptionsTrade, LuxOptionContract, LuxOptionPurchase
+from .forms import LuxOptionsForm, LuxOptionsUpdateForm
class LuxTradeListView(PaginatedListView):
@@ -88,7 +88,7 @@ class OptionsModelFormView(CreateView):
class LuxOptionPurchaseCreateView(CreateView):
- model = LuxOptionContact
+ model = LuxOptionContract
fields = ['symbol']
success_url = '/trading/'
template_name = 'trading/create_luxoptions_form.html'
@@ -108,7 +108,7 @@ class LuxOptionPurchaseCreateView(CreateView):
)
print(form.cleaned_data['contracts'])
while i < int(form.cleaned_data['contracts']):
- c = LuxOptionContact.objects.create(
+ c = LuxOptionContract.objects.create(
symbol = form.cleaned_data['symbol'],
strike_price = form.cleaned_data['strike_price'],
expiration_date = form.cleaned_data['expiration_date'],
@@ -119,3 +119,43 @@ class LuxOptionPurchaseCreateView(CreateView):
i = i+1
return HttpResponseRedirect('/trading/')
return render(request, 'trading/create_luxoptions_form.html', {'form': form})
+
+class LuxOptionsPurchaseEditView(UpdateView):
+ model = LuxOptionPurchase
+ fields = [
+ 'symbol',
+ 'close_date',
+ 'status'
+ ]
+ success_url = '/trading/'
+ template_name = 'trading/luxoptions_update_form.html'
+
+
+ def get_context_data(self, **kwargs):
+ context = super(LuxOptionsPurchaseEditView, self).get_context_data(**kwargs)
+ obj = LuxOptionPurchase.objects.get(pk=self.object.pk)
+ context['form'] = LuxOptionsUpdateForm()
+ context['object'] = self.object
+ return context
+
+ def post(self, request, *args, **kwargs):
+ form = LuxOptionsForm(request.POST)
+ if form.is_valid():
+ i = 0
+ p = LuxOptionPurchase.objects.get(
+ symbol = form.cleaned_data['symbol'],
+ open_date = form.cleaned_data['open_date'],
+ )
+ print(form.cleaned_data['contracts_to_close'])
+ while i < int(form.cleaned_data['contracts_to_close']):
+ c = LuxOptionContract.objects.get(
+ symbol = form.cleaned_data['symbol'],
+ strike_price = form.cleaned_data['strike_price'],
+ expiration_date = form.cleaned_data['expiration_date'],
+ contract_open_price = form.cleaned_data['contract_open_price'],
+ call_put = form.cleaned_data['call_put'],
+ )
+ c.contract_close_price = form.cleaned_data['contract_close_price']
+ c.save()
+ return HttpResponseRedirect('/trading/')
+ return render(request, 'trading/create_luxoptions_form.html', {'form': form})