Make account required for trade information
This commit is contained in:
parent
312ddb4dc1
commit
633894ae75
|
@ -124,7 +124,7 @@ urlpatterns = [
|
||||||
name="trade_update",
|
name="trade_update",
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"trades/<str:type>/view/<str:trade_id>/",
|
"trades/<str:type>/view/<str:account_id>/<str:trade_id>/",
|
||||||
trades.TradeAction.as_view(),
|
trades.TradeAction.as_view(),
|
||||||
name="trade_action",
|
name="trade_action",
|
||||||
),
|
),
|
||||||
|
|
|
@ -103,7 +103,10 @@ class OANDAExchange(BaseExchange):
|
||||||
|
|
||||||
def get_position_info(self, symbol):
|
def get_position_info(self, symbol):
|
||||||
r = positions.PositionDetails(self.account_id, symbol)
|
r = positions.PositionDetails(self.account_id, symbol)
|
||||||
return self.call(r)
|
response = self.call(r)
|
||||||
|
response["account"] = self.account.name
|
||||||
|
response["account_id"] = self.account.id
|
||||||
|
return response
|
||||||
|
|
||||||
def get_all_positions(self):
|
def get_all_positions(self):
|
||||||
items = []
|
items = []
|
||||||
|
|
|
@ -235,12 +235,16 @@ class Trade(models.Model):
|
||||||
return cls.objects.get(id=trade_id, user=user)
|
return cls.objects.get(id=trade_id, user=user)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_by_id_or_order(cls, trade_id, user):
|
def get_by_id_or_order(cls, trade_id, account_id, user):
|
||||||
try:
|
try:
|
||||||
return cls.objects.get(id=trade_id, user=user)
|
account = Account.objects.get(id=account_id, user=user)
|
||||||
|
except Account.DoesNotExist:
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
return cls.objects.get(id=trade_id, account=account, user=user)
|
||||||
except cls.DoesNotExist:
|
except cls.DoesNotExist:
|
||||||
try:
|
try:
|
||||||
return cls.objects.get(order_id=trade_id, user=user)
|
return cls.objects.get(order_id=trade_id, account=account, user=user)
|
||||||
except cls.DoesNotExist:
|
except cls.DoesNotExist:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
{% for trade_id in item %}
|
{% for trade_id in item %}
|
||||||
<button
|
<button
|
||||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
hx-get="{% url 'trade_action' type=type trade_id=trade_id %}"
|
hx-get="{% url 'trade_action' type=type trade_id=trade_id account_id=object.account_id %}"
|
||||||
hx-trigger="click"
|
hx-trigger="click"
|
||||||
hx-target="#modals-here"
|
hx-target="#modals-here"
|
||||||
hx-swap="innerHTML"
|
hx-swap="innerHTML"
|
||||||
|
|
|
@ -29,7 +29,8 @@ class TradeAction(LoginRequiredMixin, OTPRequiredMixin, ObjectRead):
|
||||||
|
|
||||||
def get_object(self, **kwargs):
|
def get_object(self, **kwargs):
|
||||||
trade_id = kwargs.get("trade_id")
|
trade_id = kwargs.get("trade_id")
|
||||||
db_info = Trade.get_by_id_or_order(trade_id, self.request.user)
|
account_id = kwargs.get("account_id")
|
||||||
|
db_info = Trade.get_by_id_or_order(trade_id, account_id, self.request.user)
|
||||||
if db_info is None:
|
if db_info is None:
|
||||||
return HttpResponseBadRequest("Trade not found.")
|
return HttpResponseBadRequest("Trade not found.")
|
||||||
if db_info.order_id is not None:
|
if db_info.order_id is not None:
|
||||||
|
|
Loading…
Reference in New Issue