Refactor OANDA schemas and refactor existing ones to make use of more objects

This commit is contained in:
Mark Veidemanis 2023-01-02 18:42:33 +00:00
parent 9835219e51
commit 72671aa87f
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 110 additions and 80 deletions

View File

@ -386,41 +386,6 @@ AccountInstrumentsSchema = {
} }
class OrderTransaction(BaseModel):
id: str
accountID: str
userID: int
batchID: str
requestID: str
time: str
type: str
instrument: str
units: str
timeInForce: str
positionFill: str
reason: str
class OrderCreate(BaseModel):
orderCreateTransaction: OrderTransaction
OrderCreateSchema = {
"id": "orderCreateTransaction.id",
"accountID": "orderCreateTransaction.accountID",
"userID": "orderCreateTransaction.userID",
"batchID": "orderCreateTransaction.batchID",
"requestID": "orderCreateTransaction.requestID",
"time": "orderCreateTransaction.time",
"type": "orderCreateTransaction.type",
"symbol": "orderCreateTransaction.instrument",
"units": "orderCreateTransaction.units",
"timeInForce": "orderCreateTransaction.timeInForce",
"positionFill": "orderCreateTransaction.positionFill",
"reason": "orderCreateTransaction.reason",
}
class PriceBid(BaseModel): class PriceBid(BaseModel):
price: str price: str
liquidity: int liquidity: int
@ -476,11 +441,6 @@ PricingInfoSchema = {
} }
class LongPositionCloseout(BaseModel):
instrument: str
units: str
class Trade(BaseModel): class Trade(BaseModel):
tradeID: str tradeID: str
clientTradeID: str clientTradeID: str
@ -498,30 +458,52 @@ class Trade(BaseModel):
trailingStopLossOrder: dict | None trailingStopLossOrder: dict | None
{ class SideCarOrder(BaseModel):
"trades": [ id: str
{ createTime: str
"id": "14480", state: str
"instrument": "EUR_USD", price: str | None
"price": "1.06345", timeInForce: str
"openTime": "2022-12-22T08:57:10.459593310Z", gtdTime: str | None
"initialUnits": "100", clientExtensions: dict | None
"initialMarginRequired": "2.9226", tradeID: str
"state": "OPEN", clientTradeID: str | None
"currentUnits": "100", type: str
"realizedPL": "0.0000", time: str | None
"financing": "0.0000", priceBound: str | None
"dividendAdjustment": "0.0000", positionFill: str | None
"unrealizedPL": "-0.0158", reason: str | None
"marginUsed": "2.9228", orderFillTransactionID: str | None
} tradeOpenedID: str | None
], tradeReducedID: str | None
"lastTransactionID": "14480", tradeClosedIDs: list[str] | None
} cancellingTransactionID: str | None
replacesOrderID: str | None
replacedByOrderID: str | None
class OpenTradesTrade(BaseModel):
id: str
instrument: str
price: str
openTime: str
initialUnits: str
initialMarginRequired: str
state: str
currentUnits: str
realizedPL: str
financing: str
dividendAdjustment: str
unrealizedPL: str
marginUsed: str
takeProfitOrder: SideCarOrder | None
stopLossOrder: SideCarOrder | None
trailingStopLossOrder: SideCarOrder | None
trailingStopValue: dict | None
class OpenTrades(BaseModel): class OpenTrades(BaseModel):
trades: list[Trade] trades: list[OpenTradesTrade]
lastTransactionID: str lastTransactionID: str
@ -530,8 +512,8 @@ OpenTradesSchema = {
"trades", "trades",
[ [
{ {
"id": "tradeID", "id": "id",
"instrument": "instrument", "symbol": "instrument",
"price": "price", "price": "price",
"openTime": "openTime", "openTime": "openTime",
"initialUnits": "initialUnits", "initialUnits": "initialUnits",
@ -546,6 +528,7 @@ OpenTradesSchema = {
"takeProfitOrder": "takeProfitOrder", "takeProfitOrder": "takeProfitOrder",
"stopLossOrder": "stopLossOrder", "stopLossOrder": "stopLossOrder",
"trailingStopLossOrder": "trailingStopLossOrder", "trailingStopLossOrder": "trailingStopLossOrder",
"trailingStopValue": "trailingStopValue",
} }
], ],
), ),
@ -560,6 +543,48 @@ class HomeConversionFactors(BaseModel):
lossBaseHome: str lossBaseHome: str
class LongPositionCloseout(BaseModel):
instrument: str
units: str
class OrderTransaction(BaseModel):
id: str
accountID: str
userID: int
batchID: str
requestID: str
time: str
type: str
instrument: str | None
units: str | None
timeInForce: str | None
positionFill: str | None
reason: str
longPositionCloseout: LongPositionCloseout | None
longOrderFillTransaction: dict | None
class OrderCreate(BaseModel):
orderCreateTransaction: OrderTransaction
OrderCreateSchema = {
"id": "orderCreateTransaction.id",
"accountID": "orderCreateTransaction.accountID",
"userID": "orderCreateTransaction.userID",
"batchID": "orderCreateTransaction.batchID",
"requestID": "orderCreateTransaction.requestID",
"time": "orderCreateTransaction.time",
"type": "orderCreateTransaction.type",
"symbol": "orderCreateTransaction.instrument",
"units": "orderCreateTransaction.units",
"timeInForce": "orderCreateTransaction.timeInForce",
"positionFill": "orderCreateTransaction.positionFill",
"reason": "orderCreateTransaction.reason",
}
class LongOrderFillTransaction(BaseModel): class LongOrderFillTransaction(BaseModel):
id: str id: str
accountID: str accountID: str
@ -592,23 +617,6 @@ class LongOrderFillTransaction(BaseModel):
longPositionCloseout: LongPositionCloseout longPositionCloseout: LongPositionCloseout
class OrderTransaction(BaseModel):
id: str
accountID: str
userID: int
batchID: str
requestID: str
time: str
type: str
instrument: str | None
units: str | None
timeInForce: str | None
positionFill: str | None
reason: str
longPositionCloseout: LongPositionCloseout | None
longOrderFillTransaction: dict | None
class PositionClose(BaseModel): class PositionClose(BaseModel):
longOrderCreateTransaction: OrderTransaction | None longOrderCreateTransaction: OrderTransaction | None
longOrderFillTransaction: OrderTransaction | None longOrderFillTransaction: OrderTransaction | None
@ -678,3 +686,25 @@ TradeDetailsSchema = {
"clientExtensions": "trade.clientExtensions", "clientExtensions": "trade.clientExtensions",
"lastTransactionID": "lastTransactionID", "lastTransactionID": "lastTransactionID",
} }
class TradeClose(BaseModel):
orderCreateTransaction: OrderTransaction
TradeCloseSchema = {
"id": "orderCreateTransaction.id",
"accountID": "orderCreateTransaction.accountID",
"userID": "orderCreateTransaction.userID",
"batchID": "orderCreateTransaction.batchID",
"requestID": "orderCreateTransaction.requestID",
"time": "orderCreateTransaction.time",
"type": "orderCreateTransaction.type",
"symbol": "orderCreateTransaction.instrument",
"units": "orderCreateTransaction.units",
"timeInForce": "orderCreateTransaction.timeInForce",
"positionFill": "orderCreateTransaction.positionFill",
"reason": "orderCreateTransaction.reason",
"longPositionCloseout": "orderCreateTransaction.longPositionCloseout",
"longOrderFillTransaction": "orderCreateTransaction.longOrderFillTransaction",
}