Begin implementing pydantic validation for OANDA

This commit is contained in:
2022-10-31 08:58:08 +00:00
parent c15ae379f5
commit 8ee56b0e37
4 changed files with 106 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
from pydantic import BaseModel, Field
class Asset(BaseModel):
id: str
class_: str = Field(..., alias="class")
@@ -17,10 +18,12 @@ class Asset(BaseModel):
min_trade_increment: str
price_increment: str
# get_all_assets
class GetAllAssets(BaseModel):
itemlist: list[Asset]
# get_open_position
class GetOpenPosition(BaseModel):
asset_id: str
@@ -63,10 +66,12 @@ class Position(BaseModel):
change_today: str
qty_available: str
# get_all_positions
class GetAllPositions(BaseModel):
itemlist: list[Position]
# get_account
class GetAccount(BaseModel):
id: str

View File

@@ -1 +1,79 @@
from pydantic import BaseModel
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