|
|
|
@ -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,
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|