From 48858bf20b71836f1039eca67d1f676618b95696 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Wed, 2 Nov 2022 19:04:05 +0000 Subject: [PATCH] Fix price parsing --- core/exchanges/oanda.py | 2 +- core/lib/schemas/alpaca_s.py | 2 +- core/lib/schemas/oanda_s.py | 19 ++++++++++++++++++- core/templates/partials/position-list.html | 1 - 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/core/exchanges/oanda.py b/core/exchanges/oanda.py index 5fae4fa..d42b2c8 100644 --- a/core/exchanges/oanda.py +++ b/core/exchanges/oanda.py @@ -86,7 +86,7 @@ class OANDAExchange(BaseExchange): print("Positions", response) for item in response["itemlist"]: item["account"] = self.account.name - item["account_id"] = self.account_id + item["account_id"] = self.account.id item["unrealized_pl"] = float(item["unrealized_pl"]) items.append(item) return (True, items) diff --git a/core/lib/schemas/alpaca_s.py b/core/lib/schemas/alpaca_s.py index 44ab6fb..6f10c64 100644 --- a/core/lib/schemas/alpaca_s.py +++ b/core/lib/schemas/alpaca_s.py @@ -104,7 +104,7 @@ get_all_positions_schema = { { "symbol": "symbol", "unrealized_pl": "unrealized_pl", - "price:": "current_price", + "price": "current_price", } ], ) diff --git a/core/lib/schemas/oanda_s.py b/core/lib/schemas/oanda_s.py index 033a44a..f571c16 100644 --- a/core/lib/schemas/oanda_s.py +++ b/core/lib/schemas/oanda_s.py @@ -115,9 +115,26 @@ class OpenPositions(BaseModel): ], "lastTransactionID": "73", } + + +def parse_prices(x): + if int(x["long"]["units"]) > 0: + return x["long"]["averagePrice"] + elif int(x["short"]["units"]) > 0: + return x["short"]["averagePrice"] + else: + return 0 + + OpenPositions_schema = { "itemlist": ( "positions", - [{"symbol": "instrument", "unrealized_pl": "unrealizedPL"}], + [ + { + "symbol": "instrument", + "unrealized_pl": "unrealizedPL", + "price": parse_prices, + } + ], ) } diff --git a/core/templates/partials/position-list.html b/core/templates/partials/position-list.html index 0ef8a35..63d1248 100644 --- a/core/templates/partials/position-list.html +++ b/core/templates/partials/position-list.html @@ -1,5 +1,4 @@ {% include 'partials/notify.html' %} -
account