2022-10-30 19:11:07 +00:00
|
|
|
from pydantic import BaseModel
|
2022-10-31 08:58:08 +00:00
|
|
|
|
|
|
|
a = {
|
|
|
|
"positions": [
|
|
|
|
{
|
|
|
|
"instrument": "EUR_USD",
|
|
|
|
"long": {
|
|
|
|
"units": "1",
|
|
|
|
"averagePrice": "0.99361",
|
|
|
|
"pl": "-0.1014",
|
|
|
|
"resettablePL": "-0.1014",
|
|
|
|
"financing": "0.0000",
|
|
|
|
"dividendAdjustment": "0.0000",
|
|
|
|
"guaranteedExecutionFees": "0.0000",
|
|
|
|
"tradeIDs": ["71"],
|
|
|
|
"unrealizedPL": "-0.0002",
|
|
|
|
},
|
|
|
|
"short": {
|
|
|
|
"units": "0",
|
|
|
|
"pl": "0.0932",
|
|
|
|
"resettablePL": "0.0932",
|
|
|
|
"financing": "0.0000",
|
|
|
|
"dividendAdjustment": "0.0000",
|
|
|
|
"guaranteedExecutionFees": "0.0000",
|
|
|
|
"unrealizedPL": "0.0000",
|
|
|
|
},
|
|
|
|
"pl": "-0.0082",
|
|
|
|
"resettablePL": "-0.0082",
|
|
|
|
"financing": "0.0000",
|
|
|
|
"commission": "0.0000",
|
|
|
|
"dividendAdjustment": "0.0000",
|
|
|
|
"guaranteedExecutionFees": "0.0000",
|
|
|
|
"unrealizedPL": "-0.0002",
|
|
|
|
"marginUsed": "0.0286",
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"lastTransactionID": "71",
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class PositionLong(BaseModel):
|
|
|
|
units: str
|
|
|
|
averagePrice: str
|
|
|
|
pl: str
|
|
|
|
resettablePL: str
|
|
|
|
financing: str
|
|
|
|
dividendAdjustment: str
|
|
|
|
guaranteedExecutionFees: str
|
|
|
|
tradeIDs: list[str]
|
|
|
|
unrealizedPL: str
|
|
|
|
|
|
|
|
|
|
|
|
class PositionShort(BaseModel):
|
|
|
|
units: str
|
|
|
|
pl: str
|
|
|
|
resettablePL: str
|
|
|
|
financing: str
|
|
|
|
dividendAdjustment: str
|
|
|
|
guaranteedExecutionFees: str
|
|
|
|
unrealizedPL: str
|
|
|
|
|
|
|
|
|
|
|
|
class Position(BaseModel):
|
|
|
|
instrument: str
|
|
|
|
long: PositionLong
|
|
|
|
short: PositionShort
|
|
|
|
pl: str
|
|
|
|
resettablePL: str
|
|
|
|
financing: str
|
|
|
|
commission: str
|
|
|
|
dividendAdjustment: str
|
|
|
|
guaranteedExecutionFees: str
|
|
|
|
unrealizedPL: str
|
|
|
|
marginUsed: str
|
|
|
|
|
|
|
|
|
|
|
|
class OpenPositions(BaseModel):
|
|
|
|
positions: list[Position]
|
|
|
|
lastTransactionID: str
|
2022-11-02 18:25:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
"positions": [
|
|
|
|
{
|
|
|
|
"instrument": "EUR_USD",
|
|
|
|
"long": {
|
|
|
|
"units": "1",
|
|
|
|
"averagePrice": "0.99361",
|
|
|
|
"pl": "-0.1014",
|
|
|
|
"resettablePL": "-0.1014",
|
|
|
|
"financing": "-0.0002",
|
|
|
|
"dividendAdjustment": "0.0000",
|
|
|
|
"guaranteedExecutionFees": "0.0000",
|
|
|
|
"tradeIDs": ["71"],
|
|
|
|
"unrealizedPL": "-0.0044",
|
|
|
|
},
|
|
|
|
"short": {
|
|
|
|
"units": "0",
|
|
|
|
"pl": "0.0932",
|
|
|
|
"resettablePL": "0.0932",
|
|
|
|
"financing": "0.0000",
|
|
|
|
"dividendAdjustment": "0.0000",
|
|
|
|
"guaranteedExecutionFees": "0.0000",
|
|
|
|
"unrealizedPL": "0.0000",
|
|
|
|
},
|
|
|
|
"pl": "-0.0082",
|
|
|
|
"resettablePL": "-0.0082",
|
|
|
|
"financing": "-0.0002",
|
|
|
|
"commission": "0.0000",
|
|
|
|
"dividendAdjustment": "0.0000",
|
|
|
|
"guaranteedExecutionFees": "0.0000",
|
|
|
|
"unrealizedPL": "-0.0044",
|
|
|
|
"marginUsed": "0.0287",
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"lastTransactionID": "73",
|
|
|
|
}
|
2022-11-02 19:04:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
def parse_prices(x):
|
2022-11-02 19:09:50 +00:00
|
|
|
if float(x["long"]["units"]) > 0:
|
2022-11-02 19:04:05 +00:00
|
|
|
return x["long"]["averagePrice"]
|
2022-11-02 19:09:50 +00:00
|
|
|
elif float(x["short"]["units"]) > 0:
|
2022-11-02 19:04:05 +00:00
|
|
|
return x["short"]["averagePrice"]
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
2022-11-02 19:09:50 +00:00
|
|
|
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"
|
|
|
|
|
|
|
|
|
2022-11-04 07:20:55 +00:00
|
|
|
OpenPositionsSchema = {
|
2022-11-02 18:25:34 +00:00
|
|
|
"itemlist": (
|
|
|
|
"positions",
|
2022-11-02 19:04:05 +00:00
|
|
|
[
|
|
|
|
{
|
|
|
|
"symbol": "instrument",
|
|
|
|
"unrealized_pl": "unrealizedPL",
|
|
|
|
"price": parse_prices,
|
2022-11-02 19:09:50 +00:00
|
|
|
"units": parse_units,
|
|
|
|
"side": parse_side,
|
|
|
|
"value": parse_value,
|
2022-11-02 19:04:05 +00:00
|
|
|
}
|
|
|
|
],
|
2022-11-02 18:25:34 +00:00
|
|
|
)
|
|
|
|
}
|