Change positions fields

This commit is contained in:
Mark Veidemanis 2022-11-02 18:24:56 +00:00
parent 8ee56b0e37
commit 396d838416
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 10 additions and 6 deletions

View File

@ -16,9 +16,9 @@
{% if item.unrealized_pl > 0 %}has-background-success-light
{% elif item.unrealized_pl < 0 %}has-background-danger-light
{% endif %}">
<td>{{ item.account_id }}</td>
<td>{{ item.account }}</td>
<td>{{ item.symbol }}</td>
<td>{{ item.current_price }}</td>
<td>{{ item.price }}</td>
<td>{{ item.qty }}</td>
<td>{{ item.market_value }}</td>
<td>{{ item.unrealized_pl }}</td>
@ -51,7 +51,7 @@
</span>
</button>
{% if type == 'page' %}
<a href="{% url 'position_action' type=type account_id=item.account_id asset_id=item.asset_id %}">
<a href="{% url 'position_action' type=type account_id=item.account_id symbol=item.symbol %}">
<button
class="button is-success">
<span class="icon-text">
@ -64,7 +64,7 @@
{% else %}
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'position_action' type=type account_id=item.account_id asset_id=item.asset_id %}"
hx-get="{% url 'position_action' type=type account_id=item.account_id symbol=item.symbol %}"
hx-trigger="click"
hx-target="#{{ type }}s-here"
hx-swap="innerHTML"

View File

@ -21,6 +21,8 @@ def get_positions(user, account_id=None):
if not success:
items.append({"name": account.name, "status": "error"})
continue
for position in positions:
position["account"] = account.name
for item in positions:
items.append(item)
@ -40,6 +42,7 @@ class Positions(LoginRequiredMixin, View):
template_name = f"wm/{type}.html"
unique = str(uuid.uuid4())[:8]
items = get_positions(request.user, account_id)
print("ITEMS", items)
if type == "page":
type = "modal"
context = {
@ -60,7 +63,7 @@ class PositionAction(LoginRequiredMixin, View):
window_content = "window-content/view-position.html"
parser_classes = [FormParser]
async def get(self, request, type, account_id, asset_id):
async def get(self, request, type, account_id, symbol):
"""
Get live information for a trade.
"""
@ -70,7 +73,8 @@ class PositionAction(LoginRequiredMixin, View):
unique = str(uuid.uuid4())[:8]
account = Account.get_by_id(account_id, request.user)
success, info = account.client.get_position_info(asset_id)
success, info = account.client.get_position_info(symbol)
print("ACCT INFO", info)
if not success:
message = "Position does not exist"
message_class = "danger"