Implement strategies and posting trades

This commit is contained in:
2022-10-27 18:08:40 +01:00
parent 7e4f3f52d1
commit 061c6f6ca7
32 changed files with 1060 additions and 178 deletions

View File

@@ -202,29 +202,38 @@
Home
</a>
{% if user.is_authenticated %}
<a class="navbar-item" href="{% url 'positions' type='page' %}">
Positions
</a>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">
Manage
</a>
<div class="navbar-dropdown">
<a class="navbar-item" href="{% url 'positions' type='page' %}">
Positions
</a>
<a class="navbar-item" href="{% url 'trades' type='page' %}">
Bot Trades
</a>
</div>
</div>
{% endif %}
{% if user.is_authenticated %}
<a class="navbar-item" href="{% url 'accounts' type='page' %}">
Accounts
</a>
{% endif %}
{% if user.is_authenticated %}
<a class="navbar-item" href="{% url 'trades' type='page' %}">
Bot Trades
</a>
{% endif %}
{% if user.is_authenticated %}
<a class="navbar-item" href="{% url 'hooks' type='page' %}">
Hooks
</a>
{% endif %}
{% if user.is_authenticated %}
<a class="navbar-item" href="{% url 'callbacks' type='page' %}">
Callbacks
</a>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">
Setup
</a>
<div class="navbar-dropdown">
<a class="navbar-item" href="{% url 'hooks' type='page' %}">
Hooks
</a>
<a class="navbar-item" href="{% url 'accounts' type='page' %}">
Accounts
</a>
<a class="navbar-item" href="{% url 'strategies' type='page' %}">
Strategies
</a>
</div>
</div>
{% endif %}
{% if settings.STRIPE_ENABLED %}
{% if user.is_authenticated %}
@@ -233,22 +242,6 @@
</a>
{% endif %}
{% endif %}
{% if user.is_superuser %}
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">
Admin
</a>
<div class="navbar-dropdown">
<a class="navbar-item" href="#">
Admin1
</a>
<a class="navbar-item" href="#">
Admin2
</a>
</div>
</div>
{% endif %}
<a class="navbar-item add-button">
Install
</a>

View File

@@ -6,6 +6,7 @@
<th>user</th>
<th>name</th>
<th>hook</th>
<th>direction</th>
<th>received hooks</th>
<th>actions</th>
</thead>
@@ -15,6 +16,7 @@
<td>{{ item.user }}</td>
<td>{{ item.name }}</td>
<td><code>{{settings.URL}}/{{settings.HOOK_PATH}}/{{ item.hook }}/</code></td>
<td>{{ item.direction }}</td>
<td>{{ item.received }}</td>
<td>
<div class="buttons">
@@ -43,7 +45,7 @@
</span>
</button>
{% if type == 'page' %}
<a href="{% url 'callbacks' type=type hook_id=item.id %}"><button
<a href="{% url 'callbacks' type='page' hook_id=item.id %}"><button
class="button is-success">
<span class="icon-text">
<span class="icon">

View File

@@ -27,7 +27,7 @@
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="#trade-edit"
hx-get="#"
hx-trigger="click"
hx-target="#{{ type }}s-here"
class="button is-info">
@@ -50,7 +50,7 @@
</span>
</button>
{% if type == 'page' %}
<a href="#trade-info">
<a href="{% url 'position_action' type=type account_id=item.account_id asset_id=item.asset_id %}">
<button
class="button is-success">
<span class="icon-text">
@@ -63,7 +63,7 @@
{% else %}
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="#trade-info"
hx-get="{% url 'position_action' type=type account_id=item.account_id asset_id=item.asset_id %}"
hx-trigger="click"
hx-target="#{{ type }}s-here"
class="button is-success">

View File

@@ -0,0 +1,88 @@
{% include 'partials/notify.html' %}
<table class="table is-fullwidth is-hoverable" id="strategies-table">
<thead>
<th>id</th>
<th>name</th>
<th>description</th>
<th>account</th>
<th>enabled</th>
<th>TP</th>
<th>SL</th>
<th>actions</th>
</thead>
{% for item in items %}
<tr>
<td>{{ item.id }}</td>
<td>{{ item.name }}</td>
<td>{{ item.description }}</td>
<td>{{ item.account }}</td>
<td>
{% if item.enabled %}
<span class="icon">
<i class="fa-solid fa-check"></i>
</span>
{% else %}
<span class="icon">
<i class="fa-solid fa-xmark"></i>
</span>
{% endif %}
</td>
<td>{{ item.take_profit_percent }}</td>
<td>{{ item.stop_loss_percent }}</td>
<td>
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'strategies_action' type=type strategy_id=item.id %}"
hx-trigger="click"
hx-target="#{{ type }}s-here"
class="button is-info">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-pencil"></i>
</span>
</span>
</button>
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-delete="{% url 'strategies_action' type=type strategy_id=item.id %}"
hx-trigger="click"
hx-target="#strategies-table"
class="button is-danger">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-trash"></i>
</span>
</span>
</button>
{% if type == 'page' %}
<a href="{% url 'strategies_action' type=type strategy_id=item.id %}"><button
class="button is-success">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-eye"></i>
</span>
</span>
</button>
</a>
{% else %}
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'strategies_action' type=type strategy_id=item.id %}"
hx-trigger="click"
hx-target="#{{ type }}s-here"
class="button is-success">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-eye"></i>
</span>
</span>
</button>
{% endif %}
</div>
</td>
</tr>
{% endfor %}
</table>

View File

@@ -3,6 +3,7 @@
<table class="table is-fullwidth is-hoverable" id="trades-table">
<thead>
<th>id</th>
<th>status</th>
<th>account id</th>
<th>symbol</th>
<th>type</th>
@@ -15,6 +16,7 @@
{% for item in items %}
<tr>
<td>{{ item.id }}</td>
<td>{{ item.status }}</td>
<td>{{ item.account.id }}</td>
<td>{{ item.symbol }}</td>
<td>{{ item.type }}</td>

View File

@@ -0,0 +1,19 @@
{% extends "base.html" %}
{% load static %}
{% load crispy_forms_tags %}
{% block content %}
<section class="hero is-fullheight">
<div class="hero-body">
<div class="container">
<div class="columns is-centered">
<div class="column is-5-tablet is-4-desktop is-3-widescreen">
<div class="box">
<p class="has-text-danger">Registration closed.</p>
</div>
</div>
</div>
</div>
</div>
</section>
{% endblock %}

View File

@@ -1,3 +1,6 @@
{% include 'partials/notify.html' %}
<h1 class="title is-4">List of accounts</h1>
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
@@ -14,6 +17,5 @@
</button>
</div>
{% include 'partials/notify.html' %}
{% include 'partials/account-list.html' %}

View File

@@ -0,0 +1,31 @@
{% include 'partials/notify.html' %}
{% load crispy_forms_tags %}
{% load crispy_forms_bulma_field %}
<form
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
{% if strategy_id is not None %}
hx-put="{% url 'strategies_action' type=type strategy_id=strategy_id %}"
{% else %}
hx-put="{% url 'strategies_action' type=type %}"
{% endif %}
hx-target="#strategies-table"
hx-swap="outerHTML">
{% csrf_token %}
{{ form|crispy }}
<button
type="button"
class="button is-light modal-close-button">
Cancel
</button>
<button type="submit" class="button is-info modal-close-button">Submit</button>
</form>

View File

@@ -1,3 +1,6 @@
<h1 class="title is-5">Add or edit a trade</h1>
<h1 class="subtitle">Updates will be posted to exchange!</h1>
{% include 'partials/notify.html' %}
{% load crispy_forms_tags %}

View File

@@ -1,4 +1,5 @@
{% include 'partials/notify.html' %}
<h1 class="title is-4">List of received callbacks</h1>
<table class="table is-fullwidth is-hoverable" id="callbacks-table">
<thead>
@@ -11,8 +12,8 @@
<th>sent</th>
<th>trade</th>
<th>exchange</th>
<th>item</th>
<th>currency</th>
<th>symbol</th>
<th>price</th>
<th>contract</th>
<th>actions</th>
</thead>
@@ -31,12 +32,12 @@
<td>{{ item.title }}</td>
<td>{{ item.message }}</td>
<td>{{ item.period }}</td>
<td>{{ item.timestamp_sent }}</td>
<td>{{ item.timestamp_trade }}</td>
<td>{{ item.market_exchange }}</td>
<td>{{ item.market_item }}</td>
<td>{{ item.market_currency }}</td>
<td>{{ item.market_contract }}</td>
<td>{{ item.sent }}</td>
<td>{{ item.trade }}</td>
<td>{{ item.exchange }}</td>
<td>{{ item.symbol }}</td>
<td>{{ item.price }}</td>
<td>{{ item.contract }}</td>
<td>
<div class="buttons">

View File

@@ -1,3 +1,8 @@
{% include 'partials/notify.html' %}
<h1 class="title is-4">List of active URL endpoints for receiving hooks.</h1>
<h1 class="subtitle">Add URLs here to receive Drakdoo callbacks. Make then unique!</h1>
<h1 class="subtitle">Warning: hooks can only trade in one direction.</h1>
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
@@ -14,6 +19,5 @@
</button>
</div>
{% include 'partials/notify.html' %}
{% include 'partials/hook-list.html' %}

View File

@@ -1,19 +1,6 @@
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="#"
hx-trigger="click"
hx-target="#modals-here"
class="button is-info">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-plus"></i>
</span>
<span>Trade</span>
</span>
</button>
</div>
<h1 class="title is-4">Live positions from all exchanges</h1>
<h1 class="subtitle">Manual trades are editable under "Bot Trades" tab.</h1>
{% include 'partials/notify.html' %}
{% include 'partials/position-list.html' %}
{% include 'partials/position-list.html' %}

View File

@@ -0,0 +1,21 @@
{% include 'partials/notify.html' %}
<h1 class="title is-4">List of strategies</h1>
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-get="{% url 'strategies_action' type=type %}"
hx-trigger="click"
hx-target="#modals-here"
class="button is-info">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-plus"></i>
</span>
<span>Strategy</span>
</span>
</button>
</div>
{% include 'partials/strategy-list.html' %}

View File

@@ -15,5 +15,9 @@
</div>
{% include 'partials/notify.html' %}
<h1 class="title is-4">List of bot and manual trades. This may not reflect actual live trades.</h1>
<h1 class="subtitle">Trades deleted here will not be closed on the exchange.</h1>
{% include 'partials/trade-list.html' %}

View File

@@ -0,0 +1,20 @@
{% include 'partials/notify.html' %}
<h1 class="title">Live information</h1>
<table class="table is-fullwidth is-hoverable">
<thead>
<th>attribute</th>
<th>value</th>
</thead>
<tbody>
{% for key, item in items.items %}
<tr>
<th>{{ key }}</th>
<td>
{% if item is not None %}
{{ item }}
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>