Skip to content

Commit

Permalink
touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
Da5hes committed Sep 10, 2024
1 parent a7229c7 commit 3779514
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
31 changes: 29 additions & 2 deletions src/deephaven_ib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ class IbSessionTws:
* **accounts_summary**: account summary. Automatically populated.
* **accounts_positions**: account positions. Automatically populated.
* **accounts_pnl**: account PNL. Automatically populated.
* **accounts_pnl_single**: single PNL. populated by calling request_single_pnl() on a specific contract.
####
# News
####
Expand Down Expand Up @@ -608,6 +608,15 @@ def deephaven_ib_parse_note(note:str, key:str) -> Optional[str]:
.move_columns_up(["RequestId", "ReceiveTime", "Account", "ModelCode"]) \
.drop_columns("Note") \
.last_by("RequestId"),
"accounts_pnl_single": tables_raw["raw_accounts_pnl_single"] \
.natural_join(tables_raw["raw_requests"], on="RequestId", joins="Note") \
.update([
"Account=(String)deephaven_ib_parse_note(Note,`account`)",
"ModelCode=(String)deephaven_ib_parse_note(Note,`model_code`)",
"ConId=(String)deephaven_ib_parse_note(Note,`conid`)"]) \
.move_columns_up(["RequestId", "ReceiveTime", "Account", "ModelCode"]) \
.drop_columns("Note") \
.last_by("RequestId"),
"contracts_matching": tables_raw["raw_contracts_matching"] \
.natural_join(tables_raw["raw_requests"], on="RequestId", joins="Pattern=Note") \
.move_columns_up(["RequestId", "ReceiveTime", "Pattern"]) \
Expand Down Expand Up @@ -776,6 +785,24 @@ def request_account_positions(self, account: str, model_code: str = "") -> Reque
req_id = self._client.request_account_positions(account, model_code)
return Request(request_id=req_id)

def request_single_pnl(self, account: str, model_code: str = "", conid: int = 0) -> Request:
"""Request PNL updates for a single position. Results are returned in the ``accounts_pnl_single`` table.
Args:
account (str): Account to request PNL for.
model_code (str): Model portfolio code to request PNL for.
conid (int): Contract ID to request PNL for.
Returns:
A Request.
Raises:
Exception: problem executing action.
"""
self._assert_connected()
req_id = self._client.request_single_pnl(account, model_code, conid)
return Request(request_id=req_id)


####################################################################################################################
####################################################################################################################
Expand Down Expand Up @@ -1161,7 +1188,7 @@ def order_place(self, contract: RegisteredContract, order: Order) -> Request:
order.orderId = req_id
else:
req_id = order.orderId

cd = contract.contract_details[0]
self._client.log_request(req_id, "PlaceOrder", cd.contract, {"order": f"Order({order})"})
self._client.placeOrder(req_id, cd.contract, order)
Expand Down
4 changes: 1 addition & 3 deletions src/deephaven_ib/_tws/tws_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,7 @@ def managedAccounts(self, accountsList: str):
self.request_account_pnl(account)
self.request_account_overview(account)
self.request_account_positions(account)

# TODO: Implement PnL requests for individual positions



####
# reqFamilyCodes
Expand Down

0 comments on commit 3779514

Please sign in to comment.