Keyboard Shortcuts
ctrl + shift + ? :
Show all keyboard shortcuts
ctrl + g :
Navigate to a group
ctrl + shift + f :
Find
ctrl + / :
Quick actions
esc to dismiss
Likes
- Twsapi
- Messages
Search
IBAPI - Contract details for micro contracts MYM
Hello,
I'm new at this, and would like some help with Contract Definitions for the ECBOT exchange contracts. Using the provided Python sample Program.py and am able to obtain snapshot data for GLOBEX and NYMEX, however with ECBOT I am not able to obtain any snapshot information unless I provide a conId, as per the contract definition: contract = Contract() However when the conId is omitted, as I do in all other contracts, I receive the dreaded 200 error message. ERROR 1005 200 No security definition has been found for the request. Is someone able to help me with the correct way of defining these contracts: MYM, YC, YK and YW? Thanks, KH |
||||
Re: ibapi nextValidId not always invoked
thank you @ScottBrian,
toggle quoted message
Show quoted text
this is indeed my first time to deal with threads. my program is not intended to stop receiving data, but to handle as much of it. about your solution: i see the run() method of EReader is abruptly ending when the connection falls, thus i think it may not snatch responses post disconnection. to my satisfaction, data isn't being lost, as client.reader is pushing it's input to client.msg_queue, q that survives disconnection. a friend (also brian) suggested on stackoverflow to join and stop after disconnection the data consumption loop, the EClient.run(). without very specific explanation, this solution actually works. probably, some later handling of the messages in the queue, does need the now closed connection. here is the working code. i'd like to set the syntax highlighting too:
|
||||
Re: ibapi nextValidId not always invoked
Hi Alex,
I have some additional thoughts: IBapi __init__ calls host_connect which will be unsuccessful if TWS is not yet up. This we know. But then, __init__ instantiates a thread for the EClient run method and starts it. If the client in not yet connected, the EClient run method will see self.Isconnected as False and exit. Later, keepAlive might get connected to TWS, but the EClient run thread is no longer active so we won't be seeing NextValidD get control (or anything else). The quick fix is to instantiate a new run thread in keepAlive after the connect is successful. Also, I suggest that both run thread and keepAlive thread be made a part of the IBapi instance data so that they can be joined during shutdown. Also, threads can not be restarted, so if they are made to be instance data, simply instantiate new threads as needed. Cheers, Scott |
||||
Re: OCA Order Examples
My apologies for the spamming of messages - last one.
I figured it out. For anyone else that searches for and finds this, my mistake was believing that I needed to submit the multiple orders through the one placeOrder. Separating them into 3 placeOrders (and fixing the orderId field) has now worked. |
||||
Re: OCA Order Examples
After working on this further, my main issue seems to be with the contract field in the placeOrder for the OCA. When checking via relevant prints, the list doesn't seem to contain the full contract details. Relevant code pasted below.
? ? ? ? ocaContract = [stock1contract, stock2contract, stock3contract]
? ? ? ? ocaOrders = [stock1limitorder, stock2limitorder, stock3limitorder]
? ? ? ? OneCancelsAll("TestOCA_", ocaOrders, 2)? ? ??
? ? ? ? for o in ocaOrders:
? ? ? ? ? ? self.placeOrder(orderId, Contract(), o)? ??
? ? ? ? ? ??print(Contract(), Order())
? ? ? ? ? ? print("printing o: ", o) def OneCancelsAll(ocaGroup, ocaOrders, ocaType):
? ? for o in ocaOrders:
? ? ? ? o.ocaGroup = ocaGroup
? ? ? ? o.ocaType = ocaType
?
? ? return ocaOrders
|
||||
Re: ibapi nextValidId not always invoked
Hi Alex,
I had a similar problem with a connect being done on the heals of a disconnect. I determined that the EClient disconnect code failed to wait for the reader thread to come home. It was orphaned but still active and snatched the handshaking responses during the following connect. Not sure you have the same problem, but just in case, following is my disconnect code that overrides the EClient disconnect. Try that out if you want. You can either comment out the logging code or get scottbrian-utils from PyPI and add "from scottbrian_utils.diag_msg import get_formatted_call_sequence" to your imports. Note also that you will need the add "self.disconnect_lock = Lock()" in your __init__ method for your IBapi class and add "from threading import Lock" to your imports.? Note also in my disconnect_from_ib that I join the run thread to wait for it to come home before exiting the disconnect process. Having both the reader thread and the run thread finished makes for a clean connect. ########################################################################### ? ? ? ? |
||||
OCA Order Examples
Hey everyone,
I'm in the process of setting up the IB Api in Python and I am pulling my hair out trying to get a One Cancels All order setup correctly (i.e. without errors). I was wondering if anyone would be able to please share some example code from Python for me to better understand the layout? I have reviewed the TWS API github resources extensively, but whether I am just not advanced in Python enough to understand it I don't know. I'm looking to setup OCA orders comprising multiple stocks - so not the typical Bracket Order (comprising parent and stoploss & profit target) OCA that seems to be discussed most often.? Place Orders are going through fine (so the connection and setup of the code are ok) and I'm comfortable with the general logic of Python, but I just cannot work out the format needed to code the OCA order. Any help would be greatly appreciated. Thanks |
||||
Re: How Market Data Farm is ON when the API Client is not connected itself?
Nick
The TWS display of market data farm has nothing to do with the api. It is telling you that TWS itself is connected to IB's data farm server.
toggle quoted message
Show quoted text
You broke your code when you changed it so that you are not calling connect before using other api functions. Or you are connecting, then disconnecting, then trying to use another api function. On 5/11/2021 3:20 AM, Tareq Naushad wrote:
Hello, |
||||
Is it possible to open multiple connection through TWS API?
Hello,
In one of our custom web-based applications for strategy making in trading, we are running a TWS API connection to stream data (which is run all-time). Now we want to open another connection to calculate different indicators like ATR, RSI, except closing the previous connection. I mean: one TWS API connection will run for streaming data, and another (or probably more than one) connection will run for calculating different indicator values. Although we have no idea whether it is a best practice or not to run multiple connections, we want to know whether opening a new connection will impact the previously running connection? I mean if a new connection is open for indicator whether the connection of streaming will work or not. Does anyone have any idea? Thanks Tareq |
||||
ibapi nextValidId not always invoked
i built a small ibapi python app to run some strategy, while taking care to stay connected to tws. if tws is inactive, the python app will start and wait, and will connect to tws when tws will start, but here's my problem: nextValidId won't be invoked here is my code. i repeat, nextValidId will be invoked only while connected to a tws session that was active before my app connects. as you can see, in a tws session that wasn't active before this script starts, nextValidId won't get invoked at all, not even manually by reqIds.
i have also posted on? |
||||
Re: Contents of "SecIdList" within a contract object.
I doubt they'd have Ric or Sedol..? Those are also subscription based on the source side, which I haven't seen mentioned in IB..? I believe the SecIdList is populated with what's available regardless, and CUSIP is the only optional one subscription dependent.
As for support, calling is unlikely to be useful. The people who can answer these questions aren't ones you can call unless your account has 9+ digits in the balance.?? -Peter |
||||
Contents of "SecIdList" within a contract object.
Aquiles Páez
According to the TWS API guide, we have the following definition for this sub-field of the Contract object:
I have the CUSIP sub, so I can view the ISIN code for American Stocks. What if I wanted to see other ID's? Like RIC, CUSIP, SEDOL? I remember seeing them listed in the field of SecIdType when one specifies the contract.? Which subscriptions would allow me to get that? Does anyone know? Lately it has been extremely difficult to get attended through the TOLL FREE number's Customer Support line of IB, I'd ask them directly but I think I prefer coming through here first.? |
||||
to navigate to use esc to dismiss