summaryrefslogtreecommitdiff
path: root/app/trading/templates
diff options
context:
space:
mode:
authorlxf <sng@luxagraf.net>2022-01-03 17:02:50 -0500
committerlxf <sng@luxagraf.net>2022-01-03 17:02:50 -0500
commit617b485a0147266d93ec7db22afd2cd9055b0c09 (patch)
tree93462a0cf8c93c211c3db7223df48f94f94f3b96 /app/trading/templates
parent1123d655bd6708fba056d9800af61e9f2e8bd6eb (diff)
trad: new options tracker that works better for WON system
Diffstat (limited to 'app/trading/templates')
-rw-r--r--app/trading/templates/trading/create_luxoptions_form.html68
-rw-r--r--app/trading/templates/trading/list.html77
2 files changed, 143 insertions, 2 deletions
diff --git a/app/trading/templates/trading/create_luxoptions_form.html b/app/trading/templates/trading/create_luxoptions_form.html
new file mode 100644
index 0000000..5fff0ae
--- /dev/null
+++ b/app/trading/templates/trading/create_luxoptions_form.html
@@ -0,0 +1,68 @@
+{% extends 'trading/base.html' %}
+{% load typogrify_tags %}
+ {% block content %}
+ <form id="id_form" action="{% url 'luxtrade:testoptions' %}" method="post" class="big">{% csrf_token %}
+ {% for field in form %}
+ <fieldset>
+ {{ field.errors }}
+ {% if field.name == 'status' or field.name == 'call_put' %}
+ <label class="hide" for="id_status">Status:</label>{{ field }}
+ {% else %}
+ {{ field.label_tag }} {{ field }}
+ {% endif %}
+ {% if field.help_text %}
+ <p class="help">{{ field.help_text|safe }}</p>
+ {% endif %}
+ </fieldset>
+{% endfor %}
+ <dl>
+ <dt>R/R: </dt><dd id="id_rr"></dd>
+ <dt>% Portfolio: </dt><dd id="id_p_portfolio"></dd>
+ <dt>Risk per contract: </dt><dd id="id_risk_contract"></dd>
+ <dt>Total Risk: </dt><dd id="id_risk_total"></dd>
+ <dt>Total Invested: </dt><dd id="id_total"></dd>
+ </dl>
+ <div class="flex">
+ <input type="submit" name="post" class="btn" value="record purchase"/>
+ </div>
+ </form>
+ {% endblock %}
+
+ {% block js %}
+<script>
+function calcPercentPortfolio() {
+ var entry_price = document.getElementById("id_entry_price").value;
+ var stop_price = document.getElementById("id_stop_price").value;
+ var target_price = document.getElementById("id_target_price").value;
+ var contract_price = document.getElementById("id_contract_price").value;
+ var number_contracts = document.getElementById("id_number_contracts").value;
+ var delta = document.getElementById("id_delta").value;
+ var pp = (contract_price*number_contracts)*100/10000;
+ var total = (contract_price*number_contracts)*100;
+ var rr = (target_price-entry_price)/(entry_price-stop_price);
+ var risk_per = ((entry_price-stop_price)*delta/contract_price)*contract_price*100
+ var total_risk = (risk_per*number_contracts);
+ document.getElementById("id_p_portfolio").innerText = (pp*100).toFixed(2);
+ document.getElementById("id_risk_contract").innerText = "$"+risk_per.toFixed(2);
+ document.getElementById("id_risk_total").innerText = "$"+total_risk.toFixed(2);
+ document.getElementById("id_rr").innerText = rr.toFixed(2);
+ document.getElementById("id_total").innerText = "$"+total.toFixed(2);
+}
+id_form.addEventListener("input", function (e) {
+ calcPercentPortfolio();
+});
+var form = document.getElementById('id_form');
+function processForm(e) {
+ if (e.preventDefault) e.preventDefault();
+ if(!confirm("Do you really want to do this?")) {
+ return false;
+ }
+ form.submit();
+}
+if (form.attachEvent) {
+ form.attachEvent("submit", processForm);
+} else {
+ form.addEventListener("submit", processForm);
+}
+</script>
+ {% endblock %}
diff --git a/app/trading/templates/trading/list.html b/app/trading/templates/trading/list.html
index 390b64e..bf8104b 100644
--- a/app/trading/templates/trading/list.html
+++ b/app/trading/templates/trading/list.html
@@ -1,6 +1,55 @@
{% extends 'trading/base.html' %}
{% block content %}
+ <h3>WON Options Trades</h3>
+ <table class="options">
+ <thead>
+ <tr>
+ <th>Symbol</th>
+ <th>Open Date</th>
+ <th>Contract</th>
+ <th>Total Invested</th>
+ <th>$ Trade Risk</th>
+ <th>% Portfolio Risk</th>
+ <th>25% profit at</th>
+ <th>Stop</th>
+ <th>Notes</th>
+ </tr>
+ </thead>
+ {% for object in luxoptions_purchases %}
+ <tr>
+ <td><a href="https://www.tradingview.com/chart/?symbol={{object.symbol}}" target="_blank">{{object.symbol}}</a></td>
+ <td><a href="{{object.get_absolute_url}}">{{object.open_date|date:"Y-m-d"}}</a></td>
+ <td>
+ <div class="data_calc">
+ {% for contract in object.luxoptioncontact_set.all %}{% if forloop.first%}
+ <span id="contract" data-num-contracts="{{object.get_contract_count}}">{{object.get_contract_count}}</span>
+ <span>{{contract.expiration_date|date:"Mj"}}</span>
+ <span>${{contract.strike_price|floatformat:0}} {{contract.get_call_put_display|title}}</span>
+ <span>@ ${{object.contract_price|floatformat:2}}</span>
+{%endif%}
+{%endfor%}
+ </div>
+
+ <td>${{object.total_invested}}</td>
+ <td>${{object.trade_risk}}</td>
+ <td>{{object.portfolio_risk}}%</td>
+ <td>${{object.sell_half_at|floatformat:2}}</td>
+ <td>${{object.stop_price|floatformat:2}}</td>
+ <td class="notes">
+ {% if object.notes %}
+ <div class="wrapper">
+ {{object.notes_html|safe}}
+ </div>
+ {% endif %}
+ </td>
+ {%if object.status == 2%}<td>
+ <a href="https://live.luxagraf.net/admin/trading/luxoptionstrade/{{object.pk}}/delete/">&#8709;</a>
+ </td>{% endif %}
+ </tr>
+ {% endfor %}
+ </table>
+ {% comment %}
<h3>Options Trades</h3>
<table class="options">
<thead>
@@ -66,11 +115,12 @@
</table>
+ {% endcomment %}
- <h3>Stock Trades</h3>
+ <h3>Open Stock Trades</h3>
<table>
<thead>
<tr>
@@ -146,7 +196,7 @@
- <h3>Trade History</h3>
+ <h3>Stock History</h3>
<table>
<thead>
<tr>
@@ -336,6 +386,29 @@
for (var i = 0; i < elements.length; i++) {
elements[i].addEventListener('input', getCurrentProfit, false);
}
+ var els = document.getElementsByClassName("data_calc");
+ var getData = function() {
+ var options = this.getAttribute("data-options");
+ var eprice = this.getAttribute("data-eprice");
+ var sprice = this.getAttribute("data-sprice");
+ var shares = this.getAttribute("data-shares");
+ var contract_price = this.getAttribute("data-cprice");
+ var number_contracts = this.getAttribute("data-ncontracts");
+ var total = this.getAttribute("data-total");
+ var delta = this.getAttribute("data-delta");
+ var cprice = this.value;
+ if (options) {
+ var profit = ((cprice*number_contracts)*100)-((contract_price*number_contracts)*100);
+ this.nextSibling.innerHTML = "$"+profit.toFixed(2);
+ } else {
+ var profit = (cprice*shares)-(shares*eprice)
+ this.nextSibling.innerHTML = "$"+profit.toFixed(2);
+ }
+ };
+
+ for (var i = 0; i < elements.length; i++) {
+ els[i].addEventListener('input', getData, false);
+ }
</script>
{% endblock %}