Skip to content

account_positions table can have duplicate entries #111

@chipkent

Description

@chipkent

As reported in https://deephavencommunity.slack.com/archives/C036HT73T43/p1694639036590999, it is possible for the account_positions table to have duplicate entries.

This appears to happen because position data is requested for the base account as well as all accounts.
image

At the same time, the raw data is aggregated using .last_by(["RequestId", "Account", "ModelCode", "ContractId"]).

  • Should the data be aggregated using only .last_by(["Account", "ModelCode", "ContractId"])?
  • Should the account for the all case be rewritten to ALL?
  • Which other account_* tables need a similar code change?

Supporting files:
requests.csv
Screenshot 2023-09-22 at 10 17 22
positions.csv
Screenshot 2023-09-22 at 10 12 07

from ibapi.contract import Contract
from ibapi.order import Order
import deephaven_ib as dhib
from deephaven import time_table
from deephaven.plot import Figure
from deephaven.plot.selectable_dataset import one_click
from deephaven.plot import PlotStyle


print("========== Create a client and connect.=========")
# Socket Port: TWS:: live:7496 paper:7497 | IB:: live:4001 paper:4002
client = dhib.IbSessionTws(host="host.docker.internal", port=4002,client_id=0, download_short_rates=False, 
                           read_only=False)
print(f"IsConnected: {client.is_connected()}")
client.connect()
print(f"IsConnected: {client.is_connected()}")

# Setup
account = "XXXXXXXXXXXXXX"
max_position_dollars = 200000.0 #per security
ema_t = "00:02:00"

errors = client.tables["errors"]
requests = client.tables["requests"]
positions = client.tables["accounts_positions"].where("Account = account")
ticks_bid_ask = client.tables["ticks_bid_ask"]
orders_submitted = client.tables["orders_submitted"].where("Account = account")
orders_status = client.tables["orders_status"]
orders_exec_details = client.tables["orders_exec_details"].where( "Account = account")
pnl = client.tables["accounts_pnl"].where("Account = account")
tmp= client.tables["accounts_summary"].where("Account=account")

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions