Finish porting data structures for positions

Mark Veidemanis 2 years ago
parent 48858bf20b
commit d319769fe0
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -105,6 +105,9 @@ get_all_positions_schema = {
"symbol": "symbol",
"unrealized_pl": "unrealized_pl",
"price": "current_price",
"units": "qty",
"side": "side",
"value": "market_value",
}
],
)

@ -118,14 +118,41 @@ class OpenPositions(BaseModel):
def parse_prices(x):
if int(x["long"]["units"]) > 0:
if float(x["long"]["units"]) > 0:
return x["long"]["averagePrice"]
elif int(x["short"]["units"]) > 0:
elif float(x["short"]["units"]) > 0:
return x["short"]["averagePrice"]
else:
return 0
def parse_units(x):
if float(x["long"]["units"]) > 0:
return x["long"]["units"]
elif float(x["short"]["units"]) > 0:
return x["short"]["units"]
else:
return 0
def parse_value(x):
if float(x["long"]["units"]) > 0:
return float(x["long"]["units"]) * float(x["long"]["averagePrice"])
elif float(x["short"]["units"]) > 0:
return float(x["short"]["units"]) * float(x["short"]["averagePrice"])
else:
return 0
def parse_side(x):
if float(x["long"]["units"]) > 0:
return "long"
elif float(x["short"]["units"]) > 0:
return "short"
else:
return "unknown"
OpenPositions_schema = {
"itemlist": (
"positions",
@ -134,6 +161,9 @@ OpenPositions_schema = {
"symbol": "instrument",
"unrealized_pl": "unrealizedPL",
"price": parse_prices,
"units": parse_units,
"side": parse_side,
"value": parse_value,
}
],
)

@ -18,8 +18,8 @@
<td>{{ item.account }}</td>
<td>{{ item.symbol }}</td>
<td>{{ item.price }}</td>
<td>{{ item.qty }}</td>
<td>{{ item.market_value }}</td>
<td>{{ item.units }}</td>
<td>{{ item.value }}</td>
<td>{{ item.unrealized_pl }}</td>
<td>{{ item.side }}</td>
<td>

Loading…
Cancel
Save