Randomly assign client id by default in order to prevent errors related to client id reuse

This commit is contained in:
moshferatu 2023-12-05 05:28:13 -08:00
parent 2e26d40884
commit 2f710a83fa

View File

@ -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)