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