Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

account_positions table can have duplicate entries #111

Open
chipkent opened this issue Sep 22, 2023 · 1 comment
Open

account_positions table can have duplicate entries #111

chipkent opened this issue Sep 22, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@chipkent
Copy link
Collaborator

chipkent commented Sep 22, 2023

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")
@chipkent chipkent added the bug Something isn't working label Sep 22, 2023
@chipkent chipkent self-assigned this Sep 22, 2023
@chipkent
Copy link
Collaborator Author

To work around this problem in the short term:

  1. Check out the dh-ib plugin from github
  2. Edit line 590 of ./src/deephaven_ib/init.py to be .last_by(["Account", "ModelCode", "ContractId"])
  3. You also may need to remove the RequestId from other "accounts_*" tables in that section of code.
  4. Rebuild and use the modified code. An easy way to do this is: cd docker/dev , ./build.sh , docker compose up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant