Fix off by one issue in OANDA

master
Mark Veidemanis 1 year ago
parent f240c4b381
commit f7242f4dd8
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -82,7 +82,7 @@ def parse_side(x):
return "unknown"
def parse_trade_ids(x, sum=-1):
def parse_trade_ids(x, sum=0):
if float(x["long"]["units"]) > 0:
return [str(int(y) + sum) for y in x["long"]["tradeIDs"]]
elif float(x["short"]["units"]) < 0:

@ -8,7 +8,7 @@
<th>quote</th>
<th>P/L</th>
<th>side</th>
<th>stored</th>
<th>trades</th>
<th>actions</th>
</thead>
{% for item in items %}
@ -33,7 +33,7 @@
</span>
{% endif %}
</td>
<td>{{ item.trades|length }}</td>
<td>{{ item.trade_ids|length }}</td>
<td>
<div class="buttons">
<button

@ -1,6 +1,5 @@
{% include 'partials/notify.html' %}
<h1 class="title">Live information</h1>
{{ valid_trade_ids }}
<table class="table is-fullwidth is-hoverable">
<thead>
<th>attribute</th>

@ -39,6 +39,9 @@ class TradeAction(LoginRequiredMixin, OTPRequiredMixin, View):
return HttpResponseBadRequest("Trade not found.")
if db_info.order_id is not None:
try:
if db_info.order_id == db_info.response["id"]:
db_info.order_id = str(int(db_info.order_id) + 1)
db_info.save()
live_info = db_info.account.client.get_trade(db_info.order_id)
except GenericAPIError as e:
live_info = {"error": e}

Loading…
Cancel
Save