Finish porting data structures for positions

This commit is contained in:
Mark Veidemanis 2022-11-02 19:09:50 +00:00
parent 48858bf20b
commit d319769fe0
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
3 changed files with 37 additions and 4 deletions

View File

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

View File

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

View File

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