Convert API responses with Glom
This commit is contained in:
@@ -72,6 +72,44 @@ class GetAllPositions(BaseModel):
|
||||
itemlist: list[Position]
|
||||
|
||||
|
||||
{
|
||||
"itemlist": [
|
||||
{
|
||||
"asset_id": "64bbff51-59d6-4b3c-9351-13ad85e3c752",
|
||||
"symbol": "BTCUSD",
|
||||
"exchange": "FTXU",
|
||||
"asset_class": "crypto",
|
||||
"asset_marginable": False,
|
||||
"qty": "0.009975",
|
||||
"avg_entry_price": "20714",
|
||||
"side": "long",
|
||||
"market_value": "204.297975",
|
||||
"cost_basis": "206.62215",
|
||||
"unrealized_pl": "-2.324175",
|
||||
"unrealized_plpc": "-0.0112484310128416",
|
||||
"unrealized_intraday_pl": "-0.269325",
|
||||
"unrealized_intraday_plpc": "-0.001316559391457",
|
||||
"current_price": "20481",
|
||||
"lastday_price": "20508",
|
||||
"change_today": "-0.001316559391457",
|
||||
"qty_available": "0.009975",
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
get_all_positions_schema = {
|
||||
"itemlist": (
|
||||
"itemlist",
|
||||
[
|
||||
{
|
||||
"symbol": "symbol",
|
||||
"unrealized_pl": "unrealized_pl",
|
||||
"price:": "current_price",
|
||||
}
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
# get_account
|
||||
class GetAccount(BaseModel):
|
||||
id: str
|
||||
@@ -108,3 +146,6 @@ class GetAccount(BaseModel):
|
||||
sma: str
|
||||
daytrade_count: int
|
||||
balance_asof: str
|
||||
|
||||
|
||||
get_account_schema = {"": ""}
|
||||
|
||||
@@ -77,3 +77,47 @@ class Position(BaseModel):
|
||||
class OpenPositions(BaseModel):
|
||||
positions: list[Position]
|
||||
lastTransactionID: str
|
||||
|
||||
|
||||
{
|
||||
"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",
|
||||
}
|
||||
OpenPositions_schema = {
|
||||
"itemlist": (
|
||||
"positions",
|
||||
[{"symbol": "instrument", "unrealized_pl": "unrealizedPL"}],
|
||||
)
|
||||
}
|
||||
|
||||
@@ -73,10 +73,10 @@ def close_trade(trade):
|
||||
pass
|
||||
|
||||
|
||||
def get_position_info(account, asset_id):
|
||||
def get_position_info(account, symbol):
|
||||
trading_client = account.get_client()
|
||||
try:
|
||||
position = trading_client.get_open_position(asset_id)
|
||||
position = trading_client.get_open_position(symbol)
|
||||
except APIError as e:
|
||||
return (False, e)
|
||||
return (True, position)
|
||||
|
||||
Reference in New Issue
Block a user