2022-11-22 07:20:37 +00:00
|
|
|
from decimal import Decimal as D
|
|
|
|
|
2022-10-30 19:11:07 +00:00
|
|
|
from pydantic import BaseModel
|
2022-10-31 08:58:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PositionLong(BaseModel):
|
|
|
|
units: str
|
2022-11-29 07:20:39 +00:00
|
|
|
averagePrice: str | None
|
2022-10-31 08:58:08 +00:00
|
|
|
pl: str
|
|
|
|
resettablePL: str
|
|
|
|
financing: str
|
|
|
|
dividendAdjustment: str
|
|
|
|
guaranteedExecutionFees: str
|
2022-11-29 07:20:39 +00:00
|
|
|
tradeIDs: list[str] | None
|
2022-10-31 08:58:08 +00:00
|
|
|
unrealizedPL: str
|
|
|
|
|
|
|
|
|
|
|
|
class PositionShort(BaseModel):
|
|
|
|
units: str
|
2022-11-29 07:20:39 +00:00
|
|
|
averagePrice: str | None
|
2022-10-31 08:58:08 +00:00
|
|
|
pl: str
|
|
|
|
resettablePL: str
|
|
|
|
financing: str
|
|
|
|
dividendAdjustment: str
|
|
|
|
guaranteedExecutionFees: str
|
2022-11-29 07:20:39 +00:00
|
|
|
tradeIDs: list[str] | None
|
2022-10-31 08:58:08 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2022-12-02 07:20:37 +00:00
|
|
|
def prevent_hedging(x):
|
|
|
|
"""
|
|
|
|
Our implementation breaks if a position has both.
|
|
|
|
We implemented it this way in order to more easily support other exchanges.
|
|
|
|
The actual direction is put into the root object with Grom.
|
|
|
|
"""
|
|
|
|
if float(x["long"]["units"]) > 0 and float(x["short"]["units"]) < 0:
|
|
|
|
raise ValueError("Hedging not allowed")
|
|
|
|
|
|
|
|
|
2022-11-02 19:04:05 +00:00
|
|
|
def parse_prices(x):
|
2022-12-02 07:20:37 +00:00
|
|
|
prevent_hedging(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-29 07:20:39 +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):
|
2022-12-02 07:20:37 +00:00
|
|
|
prevent_hedging(x)
|
2022-11-02 19:09:50 +00:00
|
|
|
if float(x["long"]["units"]) > 0:
|
|
|
|
return x["long"]["units"]
|
2022-11-29 07:20:39 +00:00
|
|
|
elif float(x["short"]["units"]) < 0:
|
2022-11-02 19:09:50 +00:00
|
|
|
return x["short"]["units"]
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
def parse_value(x):
|
2022-12-02 07:20:37 +00:00
|
|
|
prevent_hedging(x)
|
2022-11-02 19:09:50 +00:00
|
|
|
if float(x["long"]["units"]) > 0:
|
2022-11-22 07:20:37 +00:00
|
|
|
return D(x["long"]["units"]) * D(x["long"]["averagePrice"])
|
2022-11-29 07:20:39 +00:00
|
|
|
elif float(x["short"]["units"]) < 0:
|
2022-11-22 07:20:37 +00:00
|
|
|
return D(x["short"]["units"]) * D(x["short"]["averagePrice"])
|
2022-11-02 19:09:50 +00:00
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
def parse_side(x):
|
2022-12-02 07:20:37 +00:00
|
|
|
prevent_hedging(x)
|
2022-11-02 19:09:50 +00:00
|
|
|
if float(x["long"]["units"]) > 0:
|
|
|
|
return "long"
|
2022-11-29 07:20:39 +00:00
|
|
|
elif float(x["short"]["units"]) < 0:
|
2022-11-02 19:09:50 +00:00
|
|
|
return "short"
|
|
|
|
else:
|
|
|
|
return "unknown"
|
|
|
|
|
|
|
|
|
2022-11-29 07:20:39 +00:00
|
|
|
def parse_trade_ids(x, sum=0):
|
2022-12-02 07:20:37 +00:00
|
|
|
prevent_hedging(x)
|
2022-11-29 07:20:39 +00:00
|
|
|
if float(x["long"]["units"]) > 0:
|
|
|
|
return [str(int(y) + sum) for y in x["long"]["tradeIDs"]]
|
|
|
|
elif float(x["short"]["units"]) < 0:
|
|
|
|
return [str(int(y) + sum) for y in x["short"]["tradeIDs"]]
|
|
|
|
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",
|
2022-11-29 07:20:39 +00:00
|
|
|
"trade_ids": parse_trade_ids, # actual value is lower by 1
|
2022-11-02 19:04:05 +00:00
|
|
|
"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
|
|
|
)
|
|
|
|
}
|
2022-11-04 07:20:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AccountDetailsNested(BaseModel):
|
|
|
|
guaranteedStopLossOrderMode: str
|
|
|
|
hedgingEnabled: bool
|
|
|
|
id: str
|
|
|
|
createdTime: str
|
|
|
|
currency: str
|
|
|
|
createdByUserID: int
|
|
|
|
alias: str
|
|
|
|
marginRate: str
|
|
|
|
lastTransactionID: str
|
|
|
|
balance: str
|
|
|
|
openTradeCount: int
|
|
|
|
openPositionCount: int
|
|
|
|
pendingOrderCount: int
|
|
|
|
pl: str
|
|
|
|
resettablePL: str
|
|
|
|
resettablePLTime: str
|
|
|
|
financing: str
|
|
|
|
commission: str
|
|
|
|
dividendAdjustment: str
|
|
|
|
guaranteedExecutionFees: str
|
|
|
|
orders: list # Order
|
|
|
|
positions: list # Position
|
|
|
|
trades: list # Trade
|
|
|
|
unrealizedPL: str
|
|
|
|
NAV: str
|
|
|
|
marginUsed: str
|
|
|
|
marginAvailable: str
|
|
|
|
positionValue: str
|
|
|
|
marginCloseoutUnrealizedPL: str
|
|
|
|
marginCloseoutNAV: str
|
|
|
|
marginCloseoutMarginUsed: str
|
|
|
|
marginCloseoutPositionValue: str
|
|
|
|
marginCloseoutPercent: str
|
|
|
|
withdrawalLimit: str
|
|
|
|
marginCallMarginUsed: str
|
|
|
|
marginCallPercent: str
|
|
|
|
|
|
|
|
|
|
|
|
class AccountDetails(BaseModel):
|
|
|
|
account: AccountDetailsNested
|
|
|
|
lastTransactionID: str
|
|
|
|
|
|
|
|
|
|
|
|
AccountDetailsSchema = {
|
|
|
|
"guaranteedSLOM": "account.guaranteedStopLossOrderMode",
|
|
|
|
"hedgingEnabled": "account.hedgingEnabled",
|
|
|
|
"id": "account.id",
|
|
|
|
"created_at": "account.createdTime",
|
|
|
|
"currency": "account.currency",
|
|
|
|
"createdByUserID": "account.createdByUserID",
|
|
|
|
"alias": "account.alias",
|
|
|
|
"marginRate": "account.marginRate",
|
|
|
|
"lastTransactionID": "account.lastTransactionID",
|
|
|
|
"balance": "account.balance",
|
|
|
|
"openTradeCount": "account.openTradeCount",
|
|
|
|
"openPositionCount": "account.openPositionCount",
|
|
|
|
"pendingOrderCount": "account.pendingOrderCount",
|
|
|
|
"pl": "account.pl",
|
|
|
|
"resettablePL": "account.resettablePL",
|
|
|
|
"resettablePLTime": "account.resettablePLTime",
|
|
|
|
"financing": "account.financing",
|
|
|
|
"commission": "account.commission",
|
|
|
|
"dividendAdjustment": "account.dividendAdjustment",
|
|
|
|
"guaranteedExecutionFees": "account.guaranteedExecutionFees",
|
|
|
|
# "orders": "account.orders",
|
|
|
|
# "positions": "account.positions",
|
|
|
|
# "trades": "account.trades",
|
|
|
|
"unrealizedPL": "account.unrealizedPL",
|
|
|
|
"NAV": "account.NAV",
|
|
|
|
"marginUsed": "account.marginUsed",
|
|
|
|
"marginAvailable": "account.marginAvailable",
|
|
|
|
"positionValue": "account.positionValue",
|
|
|
|
"marginCloseoutUnrealizedPL": "account.marginCloseoutUnrealizedPL",
|
|
|
|
"marginCloseoutNAV": "account.marginCloseoutNAV",
|
|
|
|
"marginCloseoutMarginUsed": "account.marginCloseoutMarginUsed",
|
|
|
|
"marginCloseoutPositionValue": "account.marginCloseoutPositionValue",
|
|
|
|
"marginCloseoutPercent": "account.marginCloseoutPercent",
|
|
|
|
"withdrawalLimit": "account.withdrawalLimit",
|
|
|
|
"marginCallMarginUsed": "account.marginCallMarginUsed",
|
|
|
|
"marginCallPercent": "account.marginCallPercent",
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-10 07:20:14 +00:00
|
|
|
class AccountSummaryNested(BaseModel):
|
|
|
|
marginCloseoutNAV: str
|
|
|
|
marginUsed: str
|
|
|
|
currency: str
|
|
|
|
resettablePL: str
|
|
|
|
NAV: str
|
|
|
|
marginCloseoutMarginUsed: str
|
|
|
|
marginCloseoutPositionValue: str
|
|
|
|
openTradeCount: int
|
|
|
|
id: str
|
|
|
|
hedgingEnabled: bool
|
|
|
|
marginCloseoutPercent: str
|
|
|
|
marginCallMarginUsed: str
|
|
|
|
openPositionCount: int
|
|
|
|
positionValue: str
|
|
|
|
pl: str
|
|
|
|
lastTransactionID: str
|
|
|
|
marginAvailable: str
|
|
|
|
marginRate: str
|
|
|
|
marginCallPercent: str
|
|
|
|
pendingOrderCount: int
|
|
|
|
withdrawalLimit: str
|
|
|
|
unrealizedPL: str
|
|
|
|
alias: str
|
|
|
|
createdByUserID: int
|
|
|
|
marginCloseoutUnrealizedPL: str
|
|
|
|
createdTime: str
|
|
|
|
balance: str
|
|
|
|
|
|
|
|
|
|
|
|
class AccountSummary(BaseModel):
|
|
|
|
account: AccountSummaryNested
|
|
|
|
lastTransactionID: str
|
|
|
|
|
|
|
|
|
|
|
|
AccountSummarySchema = {
|
|
|
|
"marginCloseoutNAV": "account.marginCloseoutNAV",
|
|
|
|
"marginUsed": "account.marginUsed",
|
|
|
|
"currency": "account.currency",
|
|
|
|
"resettablePL": "account.resettablePL",
|
|
|
|
"NAV": "account.NAV",
|
|
|
|
"marginCloseoutMarginUsed": "account.marginCloseoutMarginUsed",
|
|
|
|
"marginCloseoutPositionValue": "account.marginCloseoutPositionValue",
|
|
|
|
"openTradeCount": "account.openTradeCount",
|
|
|
|
"id": "account.id",
|
|
|
|
"hedgingEnabled": "account.hedgingEnabled",
|
|
|
|
"marginCloseoutPercent": "account.marginCloseoutPercent",
|
|
|
|
"marginCallMarginUsed": "account.marginCallMarginUsed",
|
|
|
|
"openPositionCount": "account.openPositionCount",
|
|
|
|
"positionValue": "account.positionValue",
|
|
|
|
"pl": "account.pl",
|
|
|
|
"lastTransactionID": "account.lastTransactionID",
|
|
|
|
"marginAvailable": "account.marginAvailable",
|
|
|
|
"marginRate": "account.marginRate",
|
|
|
|
"marginCallPercent": "account.marginCallPercent",
|
|
|
|
"pendingOrderCount": "account.pendingOrderCount",
|
|
|
|
"withdrawalLimit": "account.withdrawalLimit",
|
|
|
|
"unrealizedPL": "account.unrealizedPL",
|
|
|
|
"alias": "account.alias",
|
|
|
|
"createdByUserID": "account.createdByUserID",
|
|
|
|
"marginCloseoutUnrealizedPL": "account.marginCloseoutUnrealizedPL",
|
|
|
|
"createdTime": "account.createdTime",
|
|
|
|
"balance": "account.balance",
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-04 07:20:14 +00:00
|
|
|
class PositionDetailsNested(BaseModel):
|
|
|
|
instrument: str
|
|
|
|
long: PositionLong
|
|
|
|
short: PositionShort
|
|
|
|
pl: str
|
|
|
|
resettablePL: str
|
|
|
|
financing: str
|
|
|
|
commission: str
|
|
|
|
dividendAdjustment: str
|
|
|
|
guaranteedExecutionFees: str
|
|
|
|
unrealizedPL: str
|
2022-12-01 20:36:09 +00:00
|
|
|
marginUsed: str | None
|
2022-11-04 07:20:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PositionDetails(BaseModel):
|
|
|
|
position: PositionDetailsNested
|
|
|
|
lastTransactionID: str
|
|
|
|
|
|
|
|
|
|
|
|
PositionDetailsSchema = {
|
|
|
|
"symbol": "position.instrument",
|
|
|
|
"long": "position.long",
|
|
|
|
"short": "position.short",
|
|
|
|
"pl": "position.pl",
|
|
|
|
"resettablePL": "position.resettablePL",
|
|
|
|
"financing": "position.financing",
|
|
|
|
"commission": "position.commission",
|
|
|
|
"dividendAdjustment": "position.dividendAdjustment",
|
|
|
|
"guaranteedExecutionFees": "position.guaranteedExecutionFees",
|
|
|
|
"unrealizedPL": "position.unrealizedPL",
|
|
|
|
"marginUsed": "position.marginUsed",
|
|
|
|
"price": lambda x: parse_prices(x["position"]),
|
|
|
|
"units": lambda x: parse_units(x["position"]),
|
|
|
|
"side": lambda x: parse_side(x["position"]),
|
|
|
|
"value": lambda x: parse_value(x["position"]),
|
2022-11-29 07:20:39 +00:00
|
|
|
"trade_ids": lambda x: parse_trade_ids(
|
|
|
|
x["position"], sum=0
|
|
|
|
), # this value is correct
|
2022-11-04 07:20:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class InstrumentTag(BaseModel):
|
|
|
|
type: str
|
|
|
|
name: str
|
|
|
|
|
|
|
|
|
|
|
|
class InstrumentFinancingDaysOfWeek(BaseModel):
|
|
|
|
dayOfWeek: str
|
|
|
|
daysCharged: int
|
|
|
|
|
|
|
|
|
|
|
|
class InstrumentFinancing(BaseModel):
|
|
|
|
longRate: str
|
|
|
|
shortRate: str
|
|
|
|
financingDaysOfWeek: list[InstrumentFinancingDaysOfWeek]
|
|
|
|
|
|
|
|
|
|
|
|
class InstrumentGuaranteedRestriction(BaseModel):
|
|
|
|
volume: str
|
|
|
|
priceRange: str
|
|
|
|
|
|
|
|
|
|
|
|
class Instrument(BaseModel):
|
|
|
|
name: str
|
|
|
|
type: str
|
|
|
|
displayName: str
|
|
|
|
pipLocation: int
|
|
|
|
displayPrecision: int
|
|
|
|
tradeUnitsPrecision: int
|
|
|
|
minimumTradeSize: str
|
|
|
|
maximumTrailingStopDistance: str
|
|
|
|
minimumTrailingStopDistance: str
|
|
|
|
maximumPositionSize: str
|
|
|
|
maximumOrderUnits: str
|
|
|
|
marginRate: str
|
|
|
|
guaranteedStopLossOrderMode: str
|
|
|
|
tags: list[InstrumentTag]
|
|
|
|
financing: InstrumentFinancing
|
|
|
|
guaranteedStopLossOrderLevelRestriction: InstrumentGuaranteedRestriction | None
|
|
|
|
|
|
|
|
|
|
|
|
class AccountInstruments(BaseModel):
|
|
|
|
instruments: list[Instrument]
|
|
|
|
|
|
|
|
|
|
|
|
AccountInstrumentsSchema = {
|
|
|
|
"itemlist": (
|
|
|
|
"instruments",
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "name",
|
|
|
|
"type": "type",
|
|
|
|
"displayName": "displayName",
|
|
|
|
"pipLocation": "pipLocation",
|
|
|
|
"displayPrecision": "displayPrecision",
|
|
|
|
"tradeUnitsPrecision": "tradeUnitsPrecision",
|
|
|
|
"minimumTradeSize": "minimumTradeSize",
|
|
|
|
"maximumTrailingStopDistance": "maximumTrailingStopDistance",
|
|
|
|
"minimumTrailingStopDistance": "minimumTrailingStopDistance",
|
|
|
|
"maximumPositionSize": "maximumPositionSize",
|
|
|
|
"maximumOrderUnits": "maximumOrderUnits",
|
|
|
|
"marginRate": "marginRate",
|
|
|
|
"guaranteedSLOM": "guaranteedStopLossOrderMode",
|
|
|
|
"tags": "tags",
|
|
|
|
"financing": "financing",
|
|
|
|
"guaranteedSLOLR": "guaranteedStopLossOrderLevelRestriction",
|
|
|
|
}
|
|
|
|
],
|
|
|
|
)
|
|
|
|
}
|
2022-11-10 19:27:46 +00:00
|
|
|
|
2022-11-10 07:20:20 +00:00
|
|
|
|
2022-11-10 19:27:46 +00:00
|
|
|
class PriceBid(BaseModel):
|
|
|
|
price: str
|
|
|
|
liquidity: int
|
|
|
|
|
2022-11-10 07:20:20 +00:00
|
|
|
|
2022-11-10 19:27:46 +00:00
|
|
|
class PriceAsk(BaseModel):
|
|
|
|
price: str
|
|
|
|
liquidity: int
|
|
|
|
|
2022-11-10 07:20:20 +00:00
|
|
|
|
2022-11-10 19:27:46 +00:00
|
|
|
class PriceQuoteHomeConversionFactors(BaseModel):
|
|
|
|
positiveUnits: str
|
|
|
|
negativeUnits: str
|
|
|
|
|
2022-11-10 07:20:20 +00:00
|
|
|
|
2022-11-10 19:27:46 +00:00
|
|
|
class Price(BaseModel):
|
|
|
|
type: str
|
|
|
|
time: str
|
|
|
|
bids: list[PriceBid]
|
|
|
|
asks: list[PriceAsk]
|
|
|
|
closeoutBid: str
|
|
|
|
closeoutAsk: str
|
|
|
|
status: str
|
|
|
|
tradeable: bool
|
|
|
|
quoteHomeConversionFactors: PriceQuoteHomeConversionFactors
|
|
|
|
instrument: str
|
|
|
|
|
2022-11-10 07:20:20 +00:00
|
|
|
|
2022-11-10 19:27:46 +00:00
|
|
|
class PricingInfo(BaseModel):
|
|
|
|
time: str
|
|
|
|
prices: list[Price]
|
|
|
|
|
2022-11-10 07:20:20 +00:00
|
|
|
|
2022-11-10 19:27:46 +00:00
|
|
|
PricingInfoSchema = {
|
|
|
|
"time": "time",
|
|
|
|
"prices": (
|
|
|
|
"prices",
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"type": "type",
|
|
|
|
"time": "time",
|
|
|
|
"bids": "bids",
|
|
|
|
"asks": "asks",
|
|
|
|
"closeoutBid": "closeoutBid",
|
|
|
|
"closeoutAsk": "closeoutAsk",
|
|
|
|
"status": "status",
|
|
|
|
"tradeable": "tradeable",
|
|
|
|
"quoteHomeConversionFactors": "quoteHomeConversionFactors",
|
|
|
|
"symbol": "instrument",
|
|
|
|
}
|
|
|
|
],
|
|
|
|
),
|
|
|
|
}
|
2022-12-01 20:36:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Trade(BaseModel):
|
|
|
|
tradeID: str
|
|
|
|
clientTradeID: str
|
|
|
|
units: str
|
|
|
|
realizedPL: str
|
|
|
|
financing: str
|
|
|
|
baseFinancing: str
|
|
|
|
price: str
|
|
|
|
guaranteedExecutionFee: str
|
|
|
|
quoteGuaranteedExecutionFee: str
|
|
|
|
halfSpreadCost: str
|
2022-12-22 07:20:49 +00:00
|
|
|
# takeProfitOrder: TakeProfitOrder | None
|
|
|
|
takeProfitOrder: dict | None
|
|
|
|
stopLossOrder: dict | None
|
|
|
|
trailingStopLossOrder: dict | None
|
|
|
|
|
|
|
|
|
2023-01-02 18:42:33 +00:00
|
|
|
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
|
2022-12-22 07:20:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OpenTrades(BaseModel):
|
2023-01-02 18:42:33 +00:00
|
|
|
trades: list[OpenTradesTrade]
|
2022-12-22 07:20:49 +00:00
|
|
|
lastTransactionID: str
|
|
|
|
|
|
|
|
|
|
|
|
OpenTradesSchema = {
|
|
|
|
"itemlist": (
|
|
|
|
"trades",
|
|
|
|
[
|
|
|
|
{
|
2023-01-02 18:42:33 +00:00
|
|
|
"id": "id",
|
|
|
|
"symbol": "instrument",
|
2022-12-22 07:20:49 +00:00
|
|
|
"price": "price",
|
|
|
|
"openTime": "openTime",
|
|
|
|
"initialUnits": "initialUnits",
|
|
|
|
"initialMarginRequired": "initialMarginRequired",
|
|
|
|
"state": "state",
|
|
|
|
"currentUnits": "currentUnits",
|
|
|
|
"realizedPL": "realizedPL",
|
|
|
|
"financing": "financing",
|
|
|
|
"dividendAdjustment": "dividendAdjustment",
|
|
|
|
"unrealizedPL": "unrealizedPL",
|
|
|
|
"marginUsed": "marginUsed",
|
|
|
|
"takeProfitOrder": "takeProfitOrder",
|
|
|
|
"stopLossOrder": "stopLossOrder",
|
|
|
|
"trailingStopLossOrder": "trailingStopLossOrder",
|
2023-01-02 18:42:33 +00:00
|
|
|
"trailingStopValue": "trailingStopValue",
|
2022-12-22 07:20:49 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
),
|
|
|
|
"lastTransactionID": "lastTransactionID",
|
|
|
|
}
|
2022-12-01 20:36:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
class HomeConversionFactors(BaseModel):
|
|
|
|
gainQuoteHome: str
|
|
|
|
lossQuoteHome: str
|
|
|
|
gainBaseHome: str
|
|
|
|
lossBaseHome: str
|
|
|
|
|
|
|
|
|
2023-01-02 18:42:33 +00:00
|
|
|
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",
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-01 20:36:09 +00:00
|
|
|
class LongOrderFillTransaction(BaseModel):
|
|
|
|
id: str
|
|
|
|
accountID: str
|
|
|
|
userID: int
|
|
|
|
batchID: str
|
|
|
|
requestID: str
|
|
|
|
time: str
|
|
|
|
type: str
|
|
|
|
orderID: str
|
|
|
|
instrument: str
|
|
|
|
units: str
|
|
|
|
requestedUnits: str
|
|
|
|
price: str
|
|
|
|
pl: str
|
|
|
|
quotePL: str
|
|
|
|
financing: str
|
|
|
|
baseFinancing: str
|
|
|
|
commission: str
|
|
|
|
accountBalance: str
|
|
|
|
gainQuoteHomeConversionFactor: str
|
|
|
|
lossQuoteHomeConversionFactor: str
|
|
|
|
guaranteedExecutionFee: str
|
|
|
|
quoteGuaranteedExecutionFee: str
|
|
|
|
halfSpreadCost: str
|
|
|
|
fullVWAP: str
|
|
|
|
reason: str
|
|
|
|
tradesClosed: list[Trade]
|
|
|
|
fullPrice: Price
|
|
|
|
homeConversionFactors: HomeConversionFactors
|
|
|
|
longPositionCloseout: LongPositionCloseout
|
|
|
|
|
|
|
|
|
|
|
|
class PositionClose(BaseModel):
|
2022-12-02 07:20:37 +00:00
|
|
|
longOrderCreateTransaction: OrderTransaction | None
|
|
|
|
longOrderFillTransaction: OrderTransaction | None
|
|
|
|
longOrderCancelTransaction: OrderTransaction | None
|
|
|
|
shortOrderCreateTransaction: OrderTransaction | None
|
|
|
|
shortOrderFillTransaction: OrderTransaction | None
|
|
|
|
shortOrderCancelTransaction: OrderTransaction | None
|
2022-12-01 20:36:09 +00:00
|
|
|
relatedTransactionIDs: list[str]
|
|
|
|
lastTransactionID: str
|
|
|
|
|
|
|
|
|
|
|
|
PositionCloseSchema = {
|
|
|
|
"longOrderCreateTransaction": "longOrderCreateTransaction",
|
|
|
|
"longOrderFillTransaction": "longOrderFillTransaction",
|
|
|
|
"longOrderCancelTransaction": "longOrderCancelTransaction",
|
|
|
|
"shortOrderCreateTransaction": "shortOrderCreateTransaction",
|
|
|
|
"shortOrderFillTransaction": "shortOrderFillTransaction",
|
|
|
|
"shortOrderCancelTransaction": "shortOrderCancelTransaction",
|
|
|
|
"relatedTransactionIDs": "relatedTransactionIDs",
|
|
|
|
"lastTransactionID": "lastTransactionID",
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class ClientExtensions(BaseModel):
|
|
|
|
id: str
|
|
|
|
tag: str
|
|
|
|
|
|
|
|
|
|
|
|
class TradeDetailsTrade(BaseModel):
|
|
|
|
id: str
|
|
|
|
instrument: str
|
|
|
|
price: str
|
|
|
|
openTime: str
|
|
|
|
initialUnits: str
|
|
|
|
initialMarginRequired: str
|
|
|
|
state: str
|
|
|
|
currentUnits: str
|
|
|
|
realizedPL: str
|
2022-11-29 07:20:39 +00:00
|
|
|
closingTransactionIDs: list[str] | None
|
2022-12-01 20:36:09 +00:00
|
|
|
financing: str
|
|
|
|
dividendAdjustment: str
|
2022-11-29 07:20:39 +00:00
|
|
|
closeTime: str | None
|
|
|
|
averageClosePrice: str | None
|
2022-12-02 07:20:37 +00:00
|
|
|
clientExtensions: ClientExtensions | None
|
2022-12-01 20:36:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TradeDetails(BaseModel):
|
|
|
|
trade: TradeDetailsTrade
|
|
|
|
lastTransactionID: str
|
|
|
|
|
|
|
|
|
|
|
|
TradeDetailsSchema = {
|
2022-12-02 07:20:37 +00:00
|
|
|
"id": "trade.id",
|
|
|
|
"symbol": "trade.instrument",
|
|
|
|
"price": "trade.price",
|
|
|
|
"openTime": "trade.openTime",
|
|
|
|
"initialUnits": "trade.initialUnits",
|
|
|
|
"initialMarginRequired": "trade.initialMarginRequired",
|
|
|
|
"state": "trade.state",
|
|
|
|
"currentUnits": "trade.currentUnits",
|
|
|
|
"realizedPL": "trade.realizedPL",
|
|
|
|
"closingTransactionIDs": "trade.closingTransactionIDs",
|
|
|
|
"financing": "trade.financing",
|
|
|
|
"dividendAdjustment": "trade.dividendAdjustment",
|
|
|
|
"closeTime": "trade.closeTime",
|
|
|
|
"averageClosePrice": "trade.averageClosePrice",
|
|
|
|
"clientExtensions": "trade.clientExtensions",
|
2022-12-01 20:36:09 +00:00
|
|
|
"lastTransactionID": "lastTransactionID",
|
|
|
|
}
|
2023-01-02 18:42:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
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",
|
|
|
|
}
|