From 2f710a83fabdf76d6880c807260b17a87725d4b0 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Tue, 5 Dec 2023 05:28:13 -0800 Subject: [PATCH] Randomly assign client id by default in order to prevent errors related to client id reuse --- ibkr/client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ibkr/client.py b/ibkr/client.py index 45a8034..9eb4c59 100644 --- a/ibkr/client.py +++ b/ibkr/client.py @@ -3,6 +3,7 @@ import pandas as pd from datetime import datetime from ib_insync import ComboLeg, Contract, IB, Index, Option, Order, Trade from ib_insync.util import isNan +from random import randint from typing import Callable, List from .currency import USD @@ -13,7 +14,7 @@ from .order_action import BUY, SELL class Client: - def __init__(self, host: str = '127.0.0.1', port: int = 7497, client_id = 1) -> None: + def __init__(self, host: str = '127.0.0.1', port: int = 7497, client_id = randint(1, 10000)) -> None: self.ib = IB() self.ib.connect(host, port, clientId = client_id) self.ib.reqMarketDataType(LIVE)