Improve navigating trades and positions by cross-linking
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
import uuid
|
||||
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.http import HttpResponseBadRequest
|
||||
from django.shortcuts import render
|
||||
from django.views import View
|
||||
from two_factor.views.mixins import OTPRequiredMixin
|
||||
|
||||
from core.exchanges import GenericAPIError
|
||||
from core.forms import TradeForm
|
||||
from core.models import Trade
|
||||
from core.util import logs
|
||||
@@ -17,6 +21,44 @@ from core.views import (
|
||||
log = logs.get_logger(__name__)
|
||||
|
||||
|
||||
class TradeAction(LoginRequiredMixin, OTPRequiredMixin, View):
|
||||
allowed_types = ["modal", "widget", "window", "page"]
|
||||
window_content = "window-content/trade.html"
|
||||
|
||||
def get(self, request, type, trade_id):
|
||||
"""
|
||||
Get live information for a trade.
|
||||
"""
|
||||
if type not in self.allowed_types:
|
||||
return HttpResponseBadRequest()
|
||||
template_name = f"wm/{type}.html"
|
||||
unique = str(uuid.uuid4())[:8]
|
||||
|
||||
db_info = Trade.get_by_id_or_order(trade_id, request.user)
|
||||
if db_info is None:
|
||||
return HttpResponseBadRequest("Trade not found.")
|
||||
if db_info.order_id is not None:
|
||||
try:
|
||||
live_info = db_info.account.client.get_trade(db_info.order_id)
|
||||
except GenericAPIError as e:
|
||||
live_info = {"error": e}
|
||||
else:
|
||||
live_info = {}
|
||||
|
||||
if type == "page":
|
||||
type = "modal"
|
||||
context = {
|
||||
"title": f"Trade info ({type})",
|
||||
"unique": unique,
|
||||
"window_content": self.window_content,
|
||||
"type": type,
|
||||
"db_info": db_info.__dict__,
|
||||
"live_info": live_info,
|
||||
}
|
||||
|
||||
return render(request, template_name, context)
|
||||
|
||||
|
||||
class TradeList(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
|
||||
list_template = "partials/trade-list.html"
|
||||
model = Trade
|
||||
|
||||
Reference in New Issue
Block a user